]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolved-dns-server.c
resolved: filter out duplicate DNS servers when writing resolv.conf
[thirdparty/systemd.git] / src / resolve / resolved-dns-server.c
index 30d9c8b34ed90fcccefc7a3ef6549e4acbb5b23e..043f6b637d8aedca68d5965ea2f68c7d12066ad9 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "siphash24.h"
+
 #include "resolved-dns-server.h"
 
 int dns_server_new(
@@ -97,3 +99,24 @@ DnsServer* dns_server_free(DnsServer *s)  {
 
         return NULL;
 }
+
+unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
+        const DnsServer *s = p;
+        uint64_t u;
+
+        siphash24((uint8_t*) &u, &s->address, FAMILY_ADDRESS_SIZE(s->family), hash_key);
+        u = u * hash_key[0] + u + s->family;
+
+        return u;
+}
+
+int dns_server_compare_func(const void *a, const void *b) {
+        const DnsServer *x = a, *y = b;
+
+        if (x->family < y->family)
+                return -1;
+        if (x->family > y->family)
+                return 1;
+
+        return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));
+}