Blame SOURCES/rsyslog-8.24.0-rhbz1512551-caching-sockaddr.patch

c17bfd
From 5f828658a317c86095fc2b982801b58bf8b8ee6f Mon Sep 17 00:00:00 2001
c17bfd
From: mosvald <mosvald@redhat.com>
c17bfd
Date: Mon, 4 Dec 2017 08:10:37 +0100
c17bfd
Subject: [PATCH] cache sin_addr instead of the whole sockaddr structure
c17bfd
c17bfd
---
c17bfd
 runtime/dnscache.c | 41 +++++++++++++++++++++++++++++++----------
c17bfd
 1 file changed, 31 insertions(+), 10 deletions(-)
c17bfd
c17bfd
diff --git a/runtime/dnscache.c b/runtime/dnscache.c
c17bfd
index 388a64f5e..d1d6e10a1 100644
c17bfd
--- a/runtime/dnscache.c
c17bfd
+++ b/runtime/dnscache.c
c17bfd
@@ -79,22 +79,43 @@ static prop_t *staticErrValue;
c17bfd
 static unsigned int
c17bfd
 hash_from_key_fn(void *k) 
c17bfd
 {
c17bfd
-    int len;
c17bfd
-    uchar *rkey = (uchar*) k; /* we treat this as opaque bytes */
c17bfd
-    unsigned hashval = 1;
c17bfd
-
c17bfd
-    len = SALEN((struct sockaddr*)k);
c17bfd
-    while(len--)
c17bfd
-        hashval = hashval * 33 + *rkey++;
c17bfd
+	int len = 0;
c17bfd
+	uchar *rkey; /* we treat this as opaque bytes */
c17bfd
+	unsigned hashval = 1;
c17bfd
+
c17bfd
+	switch (((struct sockaddr *)k)->sa_family) {
c17bfd
+		case AF_INET:
c17bfd
+			len = sizeof (struct in_addr);
c17bfd
+			rkey = (uchar*) &(((struct sockaddr_in *)k)->sin_addr);
c17bfd
+			break;
c17bfd
+		case AF_INET6:
c17bfd
+			len = sizeof (struct in6_addr);
c17bfd
+			rkey = (uchar*) &(((struct sockaddr_in6 *)k)->sin6_addr);
c17bfd
+			break;
c17bfd
+	}
c17bfd
+	while(len--)
c17bfd
+		hashval = hashval * 33 + *rkey++;
c17bfd
 
c17bfd
-    return hashval;
c17bfd
+	return hashval;
c17bfd
 }
c17bfd
 
c17bfd
 static int
c17bfd
 key_equals_fn(void *key1, void *key2)
c17bfd
 {
c17bfd
-	return (SALEN((struct sockaddr*)key1) == SALEN((struct sockaddr*) key2) 
c17bfd
-		   && !memcmp(key1, key2, SALEN((struct sockaddr*) key1)));
c17bfd
+	int RetVal = 0;
c17bfd
+
c17bfd
+	if (((struct sockaddr *)key1)->sa_family != ((struct sockaddr *)key2)->sa_family)
c17bfd
+		return 0;
c17bfd
+	 switch (((struct sockaddr *)key1)->sa_family) {
c17bfd
+		case AF_INET:
c17bfd
+			RetVal = !memcmp(&((struct sockaddr_in *)key1)->sin_addr, &((struct sockaddr_in *)key2)->sin_addr, sizeof (struct in_addr));
c17bfd
+			break;
c17bfd
+		case AF_INET6:
c17bfd
+			RetVal = !memcmp(&((struct sockaddr_in6 *)key1)->sin6_addr, &((struct sockaddr_in6 *)key2)->sin6_addr, sizeof (struct in6_addr));
c17bfd
+			break;
c17bfd
+	}
c17bfd
+
c17bfd
+	return RetVal;
c17bfd
 }
c17bfd
 
c17bfd
 /* destruct a cache entry.
c17bfd
-- 
c17bfd
2.14.3
c17bfd