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

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