Tweak packet-reduction code going from TCP->UDP. tcp-trunc holly/tcp-trunc origin/tcp-trunc
authorSimon Kelley <simon@thekelleys.org.uk>
Sun, 13 Oct 2024 22:09:48 +0000 (23:09 +0100)
committerSimon Kelley <simon@thekelleys.org.uk>
Sun, 13 Oct 2024 22:09:48 +0000 (23:09 +0100)
src/forward.c

index 8f58311..e9a50a3 100644 (file)
@@ -2143,11 +2143,18 @@ int tcp_from_udp(time_t now, int status, struct dns_header *header, ssize_t *ple
 
          if (n >= daemon->edns_pktsz)
            {
-             new_header->ancount = htons(0);
+             /* still too bug, strip optional sections and try again. */
              new_header->nscount = htons(0);
              new_header->arcount = htons(0);
-             n = resize_packet(header, n, NULL, 0);
-             new_status = STAT_TRUNCATED;
+             n = resize_packet(new_header, n, NULL, 0);
+             if (n >= daemon->edns_pktsz)
+               {
+                 /* truncating the packet will break the answers, so remove them too
+                    and mark the reply as truncated. */
+                 new_header->ancount = htons(0);
+                 n = resize_packet(new_header, n, NULL, 0);
+                 new_status = STAT_TRUNCATED;
+               }
            }
 
          /* return the stripped or truncated reply. */