From: Yu Watanabe Date: Fri, 25 Jun 2021 06:55:36 +0000 (+0900) Subject: ether-addr-util: introduce hw_addr_hash_ops X-Git-Tag: v249-rc3~17^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=907d5ce4d4f74abb121eb8979ee4fd0a6d8f501a;p=thirdparty%2Fsystemd.git ether-addr-util: introduce hw_addr_hash_ops --- diff --git a/src/basic/ether-addr-util.c b/src/basic/ether-addr-util.c index 3925810768d..e660ac2c6fd 100644 --- a/src/basic/ether-addr-util.c +++ b/src/basic/ether-addr-util.c @@ -37,6 +37,16 @@ int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b) return memcmp(a->bytes, b->bytes, a->length); } +static void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) { + assert(p); + assert(state); + + siphash24_compress(&p->length, sizeof(p->length), state); + siphash24_compress(p->bytes, p->length, state); +} + +DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare); + char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) { assert(addr); assert(buffer); diff --git a/src/basic/ether-addr-util.h b/src/basic/ether-addr-util.h index cf8afff3561..63447910c09 100644 --- a/src/basic/ether-addr-util.h +++ b/src/basic/ether-addr-util.h @@ -36,6 +36,8 @@ static inline bool hw_addr_is_null(const struct hw_addr_data *addr) { return hw_addr_equal(addr, &HW_ADDR_NULL); } +extern const struct hash_ops hw_addr_hash_ops; + #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X" #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]