Skip to content

Commit

Permalink
ldns-testns match on edns0 udp_size
Browse files Browse the repository at this point in the history
  • Loading branch information
wtoorop committed Jun 2, 2023
1 parent 0ede967 commit 8d67453
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/ldns-testpkts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions examples/ldns-testpkts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8d67453

Please sign in to comment.