Skip to content

Commit

Permalink
EDNS parsing
Browse files Browse the repository at this point in the history
- Only parse entire DNS message if EDNS indexers are used
  • Loading branch information
jelu committed Jun 30, 2023
1 parent 9b0dd6e commit 8fd7b7a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dns_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ static indexer indexers[] = {
{ "certain_qnames", 0, certain_qnames_indexer, certain_qnames_iterator },
{ "query_classification", 0, query_classification_indexer, query_classification_iterator },
{ "idn_qname", 0, idn_qname_indexer, idn_qname_iterator },
{ "edns_version", 0, edns_version_indexer, edns_version_iterator },
{ "edns_bufsiz", 0, edns_bufsiz_indexer, edns_bufsiz_iterator },
{ "edns_version", edns_version_init, edns_version_indexer, edns_version_iterator },
{ "edns_bufsiz", edns_bufsiz_init, edns_bufsiz_indexer, edns_bufsiz_iterator },
{ "do_bit", 0, do_bit_indexer, do_bit_iterator },
{ "rd_bit", 0, rd_bit_indexer, rd_bit_iterator },
{ "tc_bit", 0, tc_bit_indexer, tc_bit_iterator },
Expand Down
4 changes: 4 additions & 0 deletions src/dns_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ static off_t skip_rr(const u_char* buf, int len, off_t offset)
return offset;
}

int dns_protocol_parse_edns0 = 0;

int dns_protocol_handler(const u_char* buf, int len, void* udata)
{
transport_message* tm = udata;
Expand Down Expand Up @@ -304,6 +306,8 @@ int dns_protocol_handler(const u_char* buf, int len, void* udata)
offset = new_offset;
qdcount--;
}
if (!dns_protocol_parse_edns0)
goto handle_m;
assert(offset <= len);

/*
Expand Down
2 changes: 2 additions & 0 deletions src/dns_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#include <sys/types.h>

extern int dns_protocol_parse_edns0;

int dns_protocol_handler(const u_char* buf, int len, void* udata);

#endif /* __dsc_dns_protocol_h */
6 changes: 6 additions & 0 deletions src/edns_bufsiz_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
#include "config.h"

#include "edns_bufsiz_index.h"
#include "dns_protocol.h"

void edns_bufsiz_init(void)
{
dns_protocol_parse_edns0 = 1;
}

int edns_bufsiz_max = 0;

Expand Down
1 change: 1 addition & 0 deletions src/edns_bufsiz_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "dns_message.h"

void edns_bufsiz_init(void);
int edns_bufsiz_indexer(const dns_message*);
int edns_bufsiz_iterator(const char** label);

Expand Down
6 changes: 6 additions & 0 deletions src/edns_version_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
#include "config.h"

#include "edns_version_index.h"
#include "dns_protocol.h"

void edns_version_init(void)
{
dns_protocol_parse_edns0 = 1;
}

int edns_version_max = 0;

Expand Down
1 change: 1 addition & 0 deletions src/edns_version_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "dns_message.h"

void edns_version_init(void);
int edns_version_indexer(const dns_message*);
int edns_version_iterator(const char** label);

Expand Down

0 comments on commit 8fd7b7a

Please sign in to comment.