]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_sockaddr_hash_ex that can be used in incremental hashing
authorOndřej Surý <ondrej@isc.org>
Mon, 18 Sep 2023 07:59:10 +0000 (09:59 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 19 Sep 2023 17:56:33 +0000 (19:56 +0200)
Add a sockaddr hashing function that can be used as part of incremental
hashing.

lib/isc/include/isc/sockaddr.h
lib/isc/sockaddr.c

index b9dda2b0c23b644657faf1f9a5625da8fdfb13f7..e962a7a11cb5121140bd06ef07c15ccf5ec07b05 100644 (file)
@@ -85,6 +85,15 @@ isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
  * If 'b''s scope is zero then 'a''s scope will be ignored.
  */
 
+void
+isc_sockaddr_hash_ex(isc_hash32_t *hash, const isc_sockaddr_t *sockaddr,
+                    bool address_only);
+/*%<
+ * Add the hash of the sockaddr into the hash for incremental hashing
+ *
+ * See isc_sockaddr_hash() for details.
+ */
+
 uint32_t
 isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only);
 /*%<
index 020cc58ae998488409a412b8680e492277aa8467..263d652b3815396362708506275b25899129016b 100644 (file)
@@ -187,17 +187,15 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) {
        }
 }
 
-uint32_t
-isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only) {
+void
+isc_sockaddr_hash_ex(isc_hash32_t *hash, const isc_sockaddr_t *sockaddr,
+                    bool address_only) {
        REQUIRE(sockaddr != NULL);
 
        size_t len = 0;
        const uint8_t *s = NULL;
        unsigned int p = 0;
        const struct in6_addr *in6;
-       isc_hash32_t hash;
-
-       isc_hash32_init(&hash);
 
        switch (sockaddr->type.sa.sa_family) {
        case AF_INET:
@@ -224,10 +222,19 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only) {
                UNREACHABLE();
        }
 
-       isc_hash32_hash(&hash, s, len, true);
+       isc_hash32_hash(hash, s, len, true);
        if (!address_only) {
-               isc_hash32_hash(&hash, &p, sizeof(p), true);
+               isc_hash32_hash(hash, &p, sizeof(p), true);
        }
+}
+
+uint32_t
+isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only) {
+       isc_hash32_t hash;
+
+       isc_hash32_init(&hash);
+
+       isc_sockaddr_hash_ex(&hash, sockaddr, address_only);
 
        return (isc_hash32_finalize(&hash));
 }