]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
ldns-testns match on edns0 udp_size
authorWillem Toorop <willem@nlnetlabs.nl>
Fri, 2 Jun 2023 08:11:17 +0000 (10:11 +0200)
committerWillem Toorop <willem@nlnetlabs.nl>
Fri, 2 Jun 2023 08:11:38 +0000 (10:11 +0200)
examples/ldns-testpkts.c
examples/ldns-testpkts.h

index 09b5c23ba46119100012537fc5b1cdc1cf457ca1..c67a82594c5d000517d50d3d7322d9dda716d1b5 100644 (file)
@@ -130,6 +130,13 @@ static void matchline(char* line, struct entry* e)
                        e->ixfr_soa_serial = (uint32_t)strtol(parse, (char**)&parse, 10);
                        while(isspace((int)*parse)) 
                                parse++;
+               } else if(str_keyword(&parse, "udp_size")) {
+                       if(*parse != '=' && *parse != ':')
+                               error("expected = or : in MATCH: %s", line);
+                       parse++;
+                       e->match_udp_size = (uint32_t)strtol(parse, (char**)&parse, 10);
+                       while(isspace((int)*parse)) 
+                               parse++;
                } else {
                        error("could not parse MATCH: '%s'", parse);
                }
@@ -243,6 +250,7 @@ static struct entry* new_entry(void)
        e->match_serial = false;
        e->ixfr_soa_serial = 0;
        e->match_transport = transport_any;
+       e->match_udp_size = 0;
        e->reply_list = NULL;
        e->copy_id = false;
        e->copy_query = false;
@@ -795,6 +803,12 @@ find_match(struct entry* entries, ldns_pkt* query_pkt,
                        verbose(3, "bad transport\n");
                        continue;
                }
+               if(p->match_udp_size > 0 && transport == transport_udp && (
+                       !ldns_pkt_edns(query_pkt) ||
+                       ldns_pkt_edns_udp_size(query_pkt) < p->match_udp_size)) {
+                       verbose(3, "bad udp_size\n");
+                       continue;
+               }
                if(p->match_all && !match_all(query_pkt, reply, p->match_ttl)) {
                        verbose(3, "bad allmatch\n");
                        continue;
index 26a71dad8dd1381c08a04c6b4ca0e6b3d54d97eb..0a20d016ae483a6ed68f5a66721ddd4dabda83dc 100644 (file)
@@ -49,6 +49,9 @@
        ; 'DO' will match only queries with DO bit set.
        ; 'noedns' matches queries without EDNS OPT records.
        ; 'ednsdata' matches queries to HEX_EDNS section.
+       ; 'udp_size=1232' makes the query match if:
+       ;   udp_size in query edns0 field >= 1232,
+       ;   or the query came over TCP.
        MATCH [opcode] [qtype] [qname] [serial=<value>] [all] [ttl]
        MATCH [UDP|TCP] DO
        MATCH ...
@@ -185,6 +188,8 @@ struct entry {
        uint32_t ixfr_soa_serial; 
        /** match on UDP/TCP */
        enum transport_type match_transport; 
+       /** match on edns udp size (larger or equal) */
+       uint16_t match_udp_size;
 
        /** pre canned reply */
        struct reply_packet *reply_list;