summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2021-02-21 02:37:38 +0000
committerdlg <dlg@openbsd.org>2021-02-21 02:37:38 +0000
commite6a31789890bbcee59812062190d08b10901dc99 (patch)
tree44880f622172ef534e05cf7502fcfa71d245fad1
parentFail on invalid address family. (diff)
downloadwireguard-openbsd-e6a31789890bbcee59812062190d08b10901dc99.tar.xz
wireguard-openbsd-e6a31789890bbcee59812062190d08b10901dc99.zip
add stoeplitz_eaddr, for getting a hash value from an ethernet address.
-rw-r--r--sys/net/toeplitz.c11
-rw-r--r--sys/net/toeplitz.h7
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 <dlg@openbsd.org>
@@ -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_ */