On Fri, 2021-08-27 at 14:39 +0200, Dominik DL6ER wrote:
> Slightly simplified/optimized patch attached. This ensures replies
> cannot be mistakenly logged as "cached" under certain circumstances
> by hard-coding flags handed to log_query().

I missed non-cacheable PTR replies. They are handled in a different if-
branch. The attached patch is meant to come on-top of my previously
submitted patch.

Test case:

dig PTR ptr.dns.netmeister.org

Best,
Dominik
From 7fa1fb118d9e9637a46e32b74d66eb2fe9b2670b Mon Sep 17 00:00:00 2001
From: Dominik DL6ER <dl...@dl6er.de>
Date: Sat, 28 Aug 2021 23:06:42 +0200
Subject: [PATCH] Log non-cacheable PTR replies

Signed-off-by: Dominik DL6ER <dl...@dl6er.de>
---
 src/rfc1035.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/rfc1035.c b/src/rfc1035.c
index 93c3363..78aee89 100644
--- a/src/rfc1035.c
+++ b/src/rfc1035.c
@@ -609,9 +609,6 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
 	{ 
 	  int name_encoding = in_arpa_name_2_addr(name, &addr);
 	  
-	  if (!name_encoding)
-	    continue;
-
 	  if (!(flags & F_NXDOMAIN))
 	    {
 	    cname_loop:
@@ -637,7 +634,15 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
 		    }
 		  GETSHORT(ardlen, p1);
 		  endrr = p1+ardlen;
-		  
+
+		  if (!name_encoding)
+		    { /* Handle non-cacheable PTR. We still want to log them */
+		      char *atype = querystr("non-cached ", aqtype);
+		      log_query(F_FORWARD | F_UPSTREAM, name, NULL, atype);
+		      p1 = endrr;
+		      continue;
+		    }
+
 		  /* TTL of record is minimum of CNAMES and PTR */
 		  if (attl < cttl)
 		    cttl = attl;
-- 
2.25.1

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to