From e6a31789890bbcee59812062190d08b10901dc99 Mon Sep 17 00:00:00 2001 From: dlg Date: Sun, 21 Feb 2021 02:37:38 +0000 Subject: [PATCH] add stoeplitz_eaddr, for getting a hash value from an ethernet address. --- sys/net/toeplitz.c | 11 ++++++++++- sys/net/toeplitz.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sys/net/toeplitz.c b/sys/net/toeplitz.c index ab4b19f8d2d..665d334f5d8 100644 --- a/sys/net/toeplitz.c +++ b/sys/net/toeplitz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: toeplitz.c,v 1.9 2020/09/01 19:18:26 tb Exp $ */ +/* $OpenBSD: toeplitz.c,v 1.10 2021/02/21 02:37:38 dlg Exp $ */ /* * Copyright (c) 2009 The DragonFly Project. All rights reserved. @@ -187,6 +187,15 @@ stoeplitz_hash_ip6port(const struct stoeplitz_cache *scache, } #endif /* INET6 */ +uint16_t +stoeplitz_hash_eaddr(const struct stoeplitz_cache *scache, + const uint8_t ea[static 6]) +{ + const uint16_t *ea16 = (const uint16_t *)ea; + + return (stoeplitz_hash_n16(scache, ea16[0] ^ ea16[1] ^ ea16[2])); +} + void stoeplitz_to_key(void *key, size_t klen) { diff --git a/sys/net/toeplitz.h b/sys/net/toeplitz.h index ece8bdf1726..a0b469ad482 100644 --- a/sys/net/toeplitz.h +++ b/sys/net/toeplitz.h @@ -1,4 +1,4 @@ -/* $OpenBSD: toeplitz.h,v 1.3 2020/06/19 08:48:15 dlg Exp $ */ +/* $OpenBSD: toeplitz.h,v 1.4 2021/02/21 02:37:38 dlg Exp $ */ /* * Copyright (c) 2019 David Gwynne @@ -53,6 +53,9 @@ uint16_t stoeplitz_hash_ip6port(const struct stoeplitz_cache *, uint16_t, uint16_t); #endif +uint16_t stoeplitz_hash_eaddr(const struct stoeplitz_cache *, + const uint8_t [static 6]); + /* hash a uint16_t in network byte order */ static __unused inline uint16_t stoeplitz_hash_n16(const struct stoeplitz_cache *scache, uint16_t n16) @@ -116,5 +119,7 @@ extern const struct stoeplitz_cache *const stoeplitz_cache; #define stoeplitz_ip6port(_sa6, _da6, _sp, _dp) \ stoeplitz_hash_ip6port(stoeplitz_cache, (_sa6), (_da6), (_sp), (_dp)) #endif +#define stoeplitz_eaddr(_ea) \ + stoeplitz_hash_eaddr(stoeplitz_cache, (_ea)) #endif /* _SYS_NET_TOEPLITZ_H_ */ -- 2.20.1