summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-12-07 22:34:40 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-13 20:32:44 +0900
commit4596c836582f7edcb4c0c6864582576d40b6053d (patch)
treecae23ae5caaf6e3babf476efa3bb8752744409fd
parent0f17886390af057fdcfcf5519261041f105d5fd0 (diff)
downloadsystemd-4596c836582f7edcb4c0c6864582576d40b6053d.tar.gz
in-addr-util: introduce in_addr_data_hash_ops_free and expose its compare and hash functions
Preparation for later commits.
-rw-r--r--src/basic/in-addr-util.c24
-rw-r--r--src/basic/in-addr-util.h3
2 files changed, 23 insertions, 4 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index 8ee5c0cc20..07ac87c6c4 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -921,7 +921,7 @@ int in_addr_prefix_from_string_auto_internal(
}
-static void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state) {
+void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state) {
assert(a);
assert(state);
@@ -929,7 +929,7 @@ static void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash
siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state);
}
-static int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y) {
+int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y) {
int r;
assert(x);
@@ -942,7 +942,18 @@ static int in_addr_data_compare_func(const struct in_addr_data *x, const struct
return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));
}
-DEFINE_HASH_OPS(in_addr_data_hash_ops, struct in_addr_data, in_addr_data_hash_func, 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);
+
+DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
+ in_addr_data_hash_ops_free,
+ struct in_addr_data,
+ in_addr_data_hash_func,
+ in_addr_data_compare_func,
+ free);
void in6_addr_hash_func(const struct in6_addr *addr, struct siphash *state) {
assert(addr);
@@ -958,7 +969,12 @@ int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b) {
return memcmp(a, b, sizeof(*a));
}
-DEFINE_HASH_OPS(in6_addr_hash_ops, struct in6_addr, in6_addr_hash_func, in6_addr_compare_func);
+DEFINE_HASH_OPS(
+ in6_addr_hash_ops,
+ struct in6_addr,
+ in6_addr_hash_func,
+ in6_addr_compare_func);
+
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
in6_addr_hash_ops_free,
struct in6_addr,
diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h
index 8d6efaa006..19354ad404 100644
--- a/src/basic/in-addr-util.h
+++ b/src/basic/in-addr-util.h
@@ -177,10 +177,13 @@ 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 struct in_addr_data *a, struct siphash *state);
+int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y);
void in6_addr_hash_func(const struct in6_addr *addr, struct siphash *state);
int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b);
extern const struct hash_ops in_addr_data_hash_ops;
+extern const struct hash_ops in_addr_data_hash_ops_free;
extern const struct hash_ops in6_addr_hash_ops;
extern const struct hash_ops in6_addr_hash_ops_free;