Skip to content

Commit b3b970d

Browse files
kdrenardjelu
authored andcommitted
Adding field qlabel_count as the count of the number of labels in the query
1 parent 5624a84 commit b3b970d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

FIELDS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ the dns table, presented as JSON identifiers.
3434
{ "name": "ar_count","type": "int" },
3535
{ "name": "qtype","type": "int" },
3636
{ "name": "qclass","type": "int" },
37+
{ "name": "qlabel_count","type": "int" },
3738
{ "name": "atype","type": "int" },
3839
{ "name": "aclass","type": "int" },
3940
{ "name": "attl","type": "int" },

src/dns.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void Parse_dns::add_packet_columns()
8888
add_packet_column("ar_count", "", Coltype::_int, COLUMN_AR_COUNT);
8989
add_packet_column("qtype", "", Coltype::_int, COLUMN_QTYPE);
9090
add_packet_column("qclass", "", Coltype::_int, COLUMN_QCLASS);
91+
add_packet_column("qlabel_count", "", Coltype::_int, COLUMN_QLABEL_COUNT);
9192
add_packet_column("atype", "", Coltype::_int, COLUMN_ATYPE);
9293
add_packet_column("aclass", "", Coltype::_int, COLUMN_ACLASS);
9394
add_packet_column("attl", "", Coltype::_int, COLUMN_ATTL);
@@ -239,6 +240,7 @@ void Parse_dns::on_table_created(Table* table, const std::vector<int>& columns)
239240
acc_ar_count = table->get_accessor<int_column>("ar_count");
240241
acc_qtype = table->get_accessor<int_column>("qtype");
241242
acc_qclass = table->get_accessor<int_column>("qclass");
243+
acc_qlabel_count = table->get_accessor<int_column>("qlabel_count");
242244
acc_atype = table->get_accessor<int_column>("atype");
243245
acc_aclass = table->get_accessor<int_column>("aclass");
244246
acc_attl = table->get_accessor<int_column>("attl");
@@ -367,6 +369,10 @@ Packet::ParseResult Parse_dns::parse(Packet& packet, const std::vector<int>& col
367369
acc_qclass.value(r) = message.m_questions[0].qclass;
368370
break;
369371

372+
case COLUMN_QLABEL_COUNT:
373+
acc_qlabel_count.value(r) = message.m_questions[0].label_cnt;
374+
break;
375+
370376
case COLUMN_QNAME:
371377
acc_qname.value(r) = RefCountString::construct(message.m_questions[0].qname);
372378
break;

src/dns.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,19 @@ class DNSMessage {
114114
char qname[0x2000];
115115
int qtype;
116116
int qclass;
117+
int label_cnt;
117118

118119
Question()
119120
{
120121
qname[0] = 0;
121122
qtype = 0;
122123
qclass = 0;
124+
label_cnt = 0;
123125
}
124126

125127
int parse(DNSMessage& m, int offs)
126128
{
127-
offs = m.parse_dname(qname, sizeof(qname), offs);
129+
offs = m.parse_dname(qname, sizeof(qname), &label_cnt, offs);
128130
qtype = m.get_ushort(offs);
129131
offs += 2;
130132
qclass = m.get_ushort(offs);
@@ -154,7 +156,7 @@ class DNSMessage {
154156

155157
int parse(DNSMessage& m, int offs)
156158
{
157-
offs = m.parse_dname(name, sizeof(name), offs);
159+
offs = m.parse_dname(name, sizeof(name), NULL, offs);
158160
type = m.get_ushort(offs);
159161
if (type == 41) {
160162
m.m_opt_rr = this;
@@ -220,18 +222,21 @@ class DNSMessage {
220222

221223
parse();
222224
}
223-
int parse_dname(char* out, int size, int offs)
225+
int parse_dname(char* out, int size, int *label_cnt_p, int offs)
224226
{
225227
int p = 0;
226228
int savedoffs = 0;
227229
int n = get_ubyte(offs++);
230+
int label_cnt = 0;
228231
if (n == 0)
229232
out[p++] = '.';
230233

231234
while (n > 0) {
235+
label_cnt++;
232236
while (n >= 192) {
233237
if (savedoffs) {
234238
out[p++] = 0;
239+
if (label_cnt_p != NULL) *label_cnt_p = label_cnt;
235240
return savedoffs;
236241
}
237242
savedoffs = offs + 1;
@@ -262,6 +267,7 @@ class DNSMessage {
262267
if (savedoffs)
263268
offs = savedoffs;
264269
out[p++] = 0;
270+
if (label_cnt_p != NULL) *label_cnt_p = label_cnt;
265271
return offs;
266272
}
267273
void parse_opt_rr()
@@ -438,6 +444,7 @@ class Parse_dns : public Packet_handler {
438444
COLUMN_AR_COUNT,
439445
COLUMN_QTYPE,
440446
COLUMN_QCLASS,
447+
COLUMN_QLABEL_COUNT,
441448
COLUMN_ATYPE,
442449
COLUMN_ACLASS,
443450
COLUMN_ATTL,
@@ -489,6 +496,7 @@ class Parse_dns : public Packet_handler {
489496
Int_accessor acc_ar_count;
490497
Int_accessor acc_qtype;
491498
Int_accessor acc_qclass;
499+
Int_accessor acc_qlabel_count;
492500
Int_accessor acc_atype;
493501
Int_accessor acc_aclass;
494502
Int_accessor acc_attl;

0 commit comments

Comments
 (0)