From: Willem Toorop Date: Fri, 2 Jun 2023 08:11:17 +0000 (+0200) Subject: ldns-testns match on edns0 udp_size X-Git-Tag: testns-1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d6745364652c923444269e75fb9bb85258309d4;p=thirdparty%2Fldns.git ldns-testns match on edns0 udp_size --- diff --git a/examples/ldns-testpkts.c b/examples/ldns-testpkts.c index 09b5c23b..c67a8259 100644 --- a/examples/ldns-testpkts.c +++ b/examples/ldns-testpkts.c @@ -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; diff --git a/examples/ldns-testpkts.h b/examples/ldns-testpkts.h index 26a71dad..0a20d016 100644 --- a/examples/ldns-testpkts.h +++ b/examples/ldns-testpkts.h @@ -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=] [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;