tree-wide: make hash_ops typesafe
This commit is contained in:
@@ -28,21 +28,15 @@ char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int ether_addr_compare(const void *a, const void *b) {
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b) {
|
||||
return memcmp(a, b, ETH_ALEN);
|
||||
}
|
||||
|
||||
static void ether_addr_hash_func(const void *p, struct siphash *state) {
|
||||
static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *state) {
|
||||
siphash24_compress(p, sizeof(struct ether_addr), state);
|
||||
}
|
||||
|
||||
const struct hash_ops ether_addr_hash_ops = {
|
||||
.hash = ether_addr_hash_func,
|
||||
.compare = ether_addr_compare
|
||||
};
|
||||
DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare);
|
||||
|
||||
int ether_addr_from_string(const char *s, struct ether_addr *ret) {
|
||||
size_t pos = 0, n, field;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define ETHER_ADDR_TO_STRING_MAX (3*6)
|
||||
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]);
|
||||
|
||||
int ether_addr_compare(const void *a, const void *b);
|
||||
int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b);
|
||||
static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) {
|
||||
return ether_addr_compare(a, b) == 0;
|
||||
}
|
||||
|
||||
@@ -603,15 +603,12 @@ int in_addr_prefix_from_string_auto_internal(
|
||||
|
||||
}
|
||||
|
||||
void in_addr_data_hash_func(const void *p, struct siphash *state) {
|
||||
const struct in_addr_data *a = p;
|
||||
|
||||
static void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state) {
|
||||
siphash24_compress(&a->family, sizeof(a->family), state);
|
||||
siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state);
|
||||
}
|
||||
|
||||
int in_addr_data_compare_func(const void *a, const void *b) {
|
||||
const struct in_addr_data *x = a, *y = b;
|
||||
static int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y) {
|
||||
int r;
|
||||
|
||||
r = CMP(x->family, y->family);
|
||||
@@ -621,7 +618,4 @@ int in_addr_data_compare_func(const void *a, const void *b) {
|
||||
return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));
|
||||
}
|
||||
|
||||
const struct hash_ops in_addr_data_hash_ops = {
|
||||
.hash = in_addr_data_hash_func,
|
||||
.compare = in_addr_data_compare_func,
|
||||
};
|
||||
DEFINE_HASH_OPS(in_addr_data_hash_ops, struct in_addr_data, in_addr_data_hash_func, in_addr_data_compare_func);
|
||||
|
||||
@@ -69,6 +69,4 @@ static inline size_t FAMILY_ADDRESS_SIZE(int family) {
|
||||
* See also oss-fuzz#11344. */
|
||||
#define IN_ADDR_NULL ((union in_addr_union) { .in6 = {} })
|
||||
|
||||
void in_addr_data_hash_func(const void *p, struct siphash *state);
|
||||
int in_addr_data_compare_func(const void *a, const void *b);
|
||||
extern const struct hash_ops in_addr_data_hash_ops;
|
||||
|
||||
Reference in New Issue
Block a user