Commit c7ee9a89 authored by Mark Andrews's avatar Mark Andrews
Browse files

improve cookie reporting; use more nmemonics

parent 470c508b
...@@ -59,6 +59,8 @@ ...@@ -59,6 +59,8 @@
#define ns_t_ta 32768 #define ns_t_ta 32768
#define ns_t_dlv 32769 #define ns_t_dlv 32769
#define ns_r_badcookie 23
static int eof = 0; static int eof = 0;
static int maxfd = -1; static int maxfd = -1;
static fd_set rfds, wfds; static fd_set rfds, wfds;
...@@ -163,6 +165,7 @@ static struct { ...@@ -163,6 +165,7 @@ static struct {
unsigned short flags; /* edns flags to be set */ unsigned short flags; /* edns flags to be set */
unsigned short version; /* edns version */ unsigned short version; /* edns version */
unsigned int tcp; /* use tcp */ unsigned int tcp; /* use tcp */
unsigned int cookie; /* opt record has cookie */
unsigned int ignore; /* ignore tc in response */ unsigned int ignore; /* ignore tc in response */
unsigned int tc; /* set tc in request */ unsigned int tc; /* set tc in request */
unsigned int rd; /* set rd in request */ unsigned int rd; /* set rd in request */
...@@ -174,114 +177,136 @@ static struct { ...@@ -174,114 +177,136 @@ static struct {
unsigned int opcode; /* use opcode for request */ unsigned int opcode; /* use opcode for request */
unsigned short type; /* query type code */ unsigned short type; /* query type code */
} opts[] = { } opts[] = {
/* size eflgs vr T ig tc rd ra cd ad aa z op type */ /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "dns", EDNS, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "dns", EDNS, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "aa", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, ns_t_soa }, { "aa", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, ns_t_soa },
{ "ad", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, ns_t_soa }, { "ad", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, ns_t_soa },
{ "cd", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, ns_t_soa }, { "cd", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, ns_t_soa },
{ "ra", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ns_t_soa }, { "ra", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ns_t_soa },
{ "rd", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "rd", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "tc", FULL, 0, "", 0, 0x0000, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "tc", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "zflag", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, ns_t_soa }, { "zflag", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, ns_t_soa },
{ "opcode", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0 }, { "opcode", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0 },
{ "opcodeflg", FULL, 0, "", 0, 0x0000, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 15, 0 }, { "opcodeflg", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 15, 0 },
{ "type666", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 666 }, { "type666", FULL, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 666 },
{ "tcp", FULL, 0, "", 0, 0x0000, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "tcp", FULL, 0, "", 0, 0x0000, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
/* size eflgs vr T ig tc rd ra cd ad aa z op type */ /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "edns", EDNS, 0, "", 4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "edns", EDNS, 0, "", 4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1", EDNS, 0, "", 4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "edns1", EDNS, 0, "", 4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns@512", EDNS, 0, "", 512, 0x0000, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey }, { "edns@512", EDNS, 0, "", 512, 0x0000, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey },
{ "ednsopt", EDNS, 4, "\x00\x64\x00", { "ednsopt", EDNS, 4, "\x00\x64\x00",
4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1opt", EDNS, 4, "\x00\x64\x00", { "edns1opt", EDNS, 4, "\x00\x64\x00",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "do", EDNS, 4, "\0\144\0", { "do", EDNS, 0, "",
4096, 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1do", FULL, 0, "", 4096, 0x8000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "edns1do", FULL, 0, "", 4096, 0x8000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednsflags", EDNS, 0, "", 4096, 0x0080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "ednsflags", EDNS, 0, "", 4096, 0x0080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "optlist", EDNS, 4 + 8 + 4 + 12, { "optlist", EDNS, 4 + 8 + 4 + 12,
"\x00\x03\x00\x00" /* NSID */ "\x00\x03\x00\x00" /* NSID */
"\x00\x08\x00\x04\x00\x01\x00\x00" /* ECS */ "\x00\x08\x00\x04\x00\x01\x00\x00" /* ECS */
"\x00\x09\x00\x00" /* EXPIRE */ "\x00\x09\x00\x00" /* EXPIRE */
"\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08", /* COOKIE */ "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08", /* COOKIE */
4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1ecs", FULL, 8, "\x00\x08\x00\x04\x00\x01\x00\x00",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "ednsnsid", FULL, 4, "\x00\x03\x00\x00",
4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednscookie", FULL, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08",
4096, 0x0000, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednsexpire", FULL, 4, "\x00\x09\x00\x00",
4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednssubnet", FULL, 8, "\x00\x08\x00\x04\x00\x01\x00\x00",
4096, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1nsid", FULL, 4, "\x00\x03\x00\x00", { "edns1nsid", FULL, 4, "\x00\x03\x00\x00",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "edns1cook", FULL, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08", { "edns1cookie", FULL, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednstcp", EDNS, 0, "", 512, 0x8000, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey }, { "edns1expire", FULL, 4, "\x00\x09\x00\x00",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
/* size eflgs vr T ig tc rd ra cd ad aa z op type */ { "edns1subnet", FULL, 8, "\x00\x08\x00\x04\x00\x01\x00\x00",
4096, 0x0000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "ednstcp", EDNS, 0, "", 512, 0x8000, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey },
/* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "bind11", COMM, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08", { "bind11", COMM, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08",
4096, 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, 4096, 0x8000, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "dig11", COMM, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08", { "dig11", COMM, 12, "\x00\x0a\x00\x08\x01\x02\x03\x04\x05\x06\x07\x08",
4096, 0x0000, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, ns_t_soa }, 4096, 0x0000, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, ns_t_soa },
{ "A", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_a },
{ "NS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ns }, /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "MD", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_md }, { "A", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_a },
{ "MF", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mf }, { "NS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ns },
{ "CNAME", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cname }, { "MD", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_md },
{ "SOA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa }, { "MF", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mf },
{ "MB", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mb }, { "CNAME", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cname },
{ "MG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mg }, { "SOA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_soa },
{ "MR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mr }, { "MB", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mb },
{ "NULL", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_null }, { "MG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mg },
{ "WKS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_wks }, { "MR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mr },
{ "PTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ptr }, { "NULL", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_null },
{ "HINFO", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_hinfo }, { "WKS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_wks },
{ "MINFO", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_minfo }, { "PTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ptr },
{ "MX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mx }, { "HINFO", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_hinfo },
{ "TXT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_txt }, { "MINFO", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_minfo },
{ "RP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rp },
{ "AFSDB", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_afsdb }, /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "X25", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_x25 }, { "MX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_mx },
{ "ISDN", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_isdn }, { "TXT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_txt },
{ "RT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rt }, { "RP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rp },
{ "NSAP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsap }, { "AFSDB", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_afsdb },
{ "NSAP-PTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsap_ptr }, { "X25", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_x25 },
{ "SIG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_sig }, { "ISDN", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_isdn },
{ "KEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_key }, { "RT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rt },
{ "PX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_px }, { "NSAP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsap },
{ "GPOS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_gpos }, { "NSAP-PTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsap_ptr },
{ "AAAA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_aaaa }, { "SIG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_sig },
{ "LOC", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_loc }, { "KEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_key },
{ "NXT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nxt }, { "PX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_px },
{ "SRV", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_srv }, { "GPOS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_gpos },
{ "NAPTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_naptr }, { "AAAA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_aaaa },
{ "KX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_kx }, { "LOC", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_loc },
{ "CERT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cert },
{ "A6", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_a6 }, /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "DNAME", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dname }, { "NXT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nxt },
{ "APL", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_apl }, { "SRV", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_srv },
{ "DS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ds }, { "NAPTR", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_naptr },
{ "SSHFP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_sshfp }, { "KX", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_kx },
{ "IPSECKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ipseckey }, { "CERT", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cert },
{ "RRSIG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rrsig }, { "A6", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_a6 },
{ "NSEC", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec }, { "DNAME", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dname },
{ "DNSKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey }, { "APL", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_apl },
{ "DHCID", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dhcid }, { "DS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ds },
{ "NSEC3", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec3 }, { "SSHFP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_sshfp },
{ "NSEC3PARAM",TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec3param }, { "IPSECKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_ipseckey },
{ "TLSA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_tlsa }, { "RRSIG", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_rrsig },
{ "SMIMEA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_smimea }, { "NSEC", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec },
{ "HIP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_hip },
{ "CDS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cds }, /* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "CDNSKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cdnskey }, { "DNSKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dnskey },
{ "OPENPGPKEY",TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_openpgpkey }, { "DHCID", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dhcid },
{ "SPF", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_spf }, { "NSEC3", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec3 },
{ "NID", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nid }, { "NSEC3PARAM",TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nsec3param },
{ "L32", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_l32 }, { "TLSA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_tlsa },
{ "L64", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_l34 }, { "SMIMEA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_smimea },
{ "LP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_lp }, { "HIP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_hip },
{ "EUI48", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_eui48 }, { "CDS", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cds },
{ "EUI64", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_eui64 }, { "CDNSKEY", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_cdnskey },
{ "URI", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_uri }, { "OPENPGPKEY",TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_openpgpkey },
{ "CAA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_caa }, { "SPF", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_spf },
{ "DLV", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dlv }, { "NID", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_nid },
{ "TYPE1000", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000 } { "L32", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_l32 },
/* size eflgs vr T ck ig tc rd ra cd ad aa z op type */
{ "L64", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_l34 },
{ "LP", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_lp },
{ "EUI48", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_eui48 },
{ "EUI64", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_eui64 },
{ "URI", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_uri },
{ "CAA", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_caa },
{ "DLV", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ns_t_dlv },
{ "TYPE1000", TYPE, 0, "", 0, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000 }
}; };
/* /*
...@@ -1011,19 +1036,19 @@ rcodetext(int code) { ...@@ -1011,19 +1036,19 @@ rcodetext(int code) {
static char buf[64]; static char buf[64];
switch(code) { switch(code) {
case 0: return("noerror"); case ns_r_noerror: return("noerror");
case 1: return("formerr"); case ns_r_formerr: return("formerr");
case 2: return("servfail"); case ns_r_servfail: return("servfail");
case 3: return("nxdomain"); case ns_r_nxdomain: return("nxdomain");
case 4: return("notimpl"); case ns_r_notimpl: return("notimpl");
case 5: return("refused"); case ns_r_refused: return("refused");
case 6: return("yxdomain"); case ns_r_yxdomain: return("yxdomain");
case 7: return("yxrrset"); case ns_r_yxrrset: return("yxrrset");
case 8: return("nxrrset"); case ns_r_nxrrset: return("nxrrset");
case 9: return("notauth"); case ns_r_notauth: return("notauth");
case 10: return("notzone"); case ns_r_notzone: return("notzone");
case 16: return("badvers"); case ns_r_badvers: return("badvers");
case 23: return("badcookie"); case ns_r_badcookie: return("badcookie");
default: default:
snprintf(buf, sizeof(buf), "rcode%u", code); snprintf(buf, sizeof(buf), "rcode%u", code);
return (buf); return (buf);
...@@ -1268,16 +1293,19 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1268,16 +1293,19 @@ process(struct workitem *item, unsigned char *buf, int n) {
int seennsid = 0, seenecs = 0, seenexpire = 0, seencookie = 0; int seennsid = 0, seenecs = 0, seenexpire = 0, seencookie = 0;
int seenecho = 0; int seenecho = 0;
char addrbuf[64]; char addrbuf[64];
int ednsvers = 0;
int ok = 1; int ok = 1;
/* process message header */ /* process message header */
id = buf[0] << 8| buf[1]; id = buf[0] << 8| buf[1];
qr = (buf[2] >> 7) & 0x1; qr = (buf[2] >> 7) & 0x1;
opcode = (buf[2] >> 3) & 0xf; opcode = (buf[2] >> 3) & 0xf;
aa = (buf[2] >> 2) & 0x1; aa = (buf[2] >> 2) & 0x1;
tc = (buf[2] >> 1) & 0x1; tc = (buf[2] >> 1) & 0x1;
rd = buf[2] & 0x1; rd = buf[2] & 0x1;
ra = (buf[3] >> 7) & 0x1; ra = (buf[3] >> 7) & 0x1;
z = (buf[3] >> 6) & 0x1; z = (buf[3] >> 6) & 0x1;
ad = (buf[3] >> 5) & 0x1; ad = (buf[3] >> 5) & 0x1;
...@@ -1322,17 +1350,17 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1322,17 +1350,17 @@ process(struct workitem *item, unsigned char *buf, int n) {
*/ */
if (item->type == ns_t_a && type == ns_t_a && if (item->type == ns_t_a && type == ns_t_a &&
strcasecmp(item->summary->ns, name) == 0 && strcasecmp(item->summary->ns, name) == 0 &&
rcode == 0 && ancount == 0) { rcode == ns_r_noerror && ancount == 0) {
item->summary->nodataa = 1; item->summary->nodataa = 1;
} }
if (item->type == ns_t_aaaa && type == ns_t_aaaa && if (item->type == ns_t_aaaa && type == ns_t_aaaa &&
strcasecmp(item->summary->ns, name) == 0 && strcasecmp(item->summary->ns, name) == 0 &&
rcode == 0 && ancount == 0) { rcode == ns_r_noerror && ancount == 0) {
item->summary->nodataaaaa = 1; item->summary->nodataaaaa = 1;
} }
if (item->type == ns_t_ns && type == ns_t_ns && if (item->type == ns_t_ns && type == ns_t_ns &&
strcasecmp(item->summary->zone, name) == 0 && strcasecmp(item->summary->zone, name) == 0 &&
rcode == 0 && ancount == 0) rcode == ns_r_noerror && ancount == 0)
item->summary->done = 1; item->summary->done = 1;
/* /*
...@@ -1340,15 +1368,15 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1340,15 +1368,15 @@ process(struct workitem *item, unsigned char *buf, int n) {
*/ */
if (item->type == ns_t_a && type == ns_t_a && if (item->type == ns_t_a && type == ns_t_a &&
strcasecmp(item->summary->ns, name) == 0 && strcasecmp(item->summary->ns, name) == 0 &&
rcode == 3 && ancount == 0) rcode == ns_r_nxdomain && ancount == 0)
item->summary->nxdomaina = 1; item->summary->nxdomaina = 1;
if (item->type == ns_t_aaaa && type == ns_t_aaaa && if (item->type == ns_t_aaaa && type == ns_t_aaaa &&
strcasecmp(item->summary->ns, name) == 0 && strcasecmp(item->summary->ns, name) == 0 &&
rcode == 3 && ancount == 0) rcode == ns_r_nxdomain && ancount == 0)
item->summary->nxdomainaaaa = 1; item->summary->nxdomainaaaa = 1;
if (item->type == ns_t_ns && type == ns_t_ns && if (item->type == ns_t_ns && type == ns_t_ns &&
strcasecmp(item->summary->zone, name) == 0 && strcasecmp(item->summary->zone, name) == 0 &&
rcode == 3 && ancount == 0) rcode == ns_r_nxdomain && ancount == 0)
item->summary->nxdomain = 1; item->summary->nxdomain = 1;
} }
...@@ -1492,7 +1520,8 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1492,7 +1520,8 @@ process(struct workitem *item, unsigned char *buf, int n) {
seenecs = 1; seenecs = 1;
if (code == 9 && optlen == 4) if (code == 9 && optlen == 4)
seenexpire = 1; seenexpire = 1;
if (code == 10 && optlen >= 16 && optlen <= 24) /* Server Cookie. */
if (code == 10 && optlen >= 16 && optlen <= 40)
seencookie = 1; seencookie = 1;
if (code == 100) if (code == 100)
seenecho = 1; seenecho = 1;
...@@ -1542,7 +1571,7 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1542,7 +1571,7 @@ process(struct workitem *item, unsigned char *buf, int n) {
if (seenopt && opcode == ns_o_query && if (seenopt && opcode == ns_o_query &&
(rcode == ns_r_noerror || rcode == ns_r_nxdomain || (rcode == ns_r_noerror || rcode == ns_r_nxdomain ||
(rcode == 16 && opts[item->test].version != 0))) (rcode == ns_r_badvers && opts[item->test].version != 0)))
item->summary->seenedns = 1; item->summary->seenedns = 1;
if (rcode != ns_r_refused && opts[item->test].version == 0) if (rcode != ns_r_refused && opts[item->test].version == 0)
...@@ -1552,15 +1581,28 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1552,15 +1581,28 @@ process(struct workitem *item, unsigned char *buf, int n) {
item->summary->allservfail = 0; item->summary->allservfail = 0;
if (opts[item->test].version == 0) { if (opts[item->test].version == 0) {
if (opts[item->test].opcode == 0 && rcode != 0) /* Expect NOERROR / BADCOOKIE */
if (opts[item->test].opcode == 0 &&
((rcode != 0 && !opts[item->test].cookie) ||
(rcode != 0 && (rcode != ns_r_badcookie || !seencookie) &&
opts[item->test].cookie)))
addtag(item, rcodetext(rcode)), ok = 0; addtag(item, rcodetext(rcode)), ok = 0;
/* Expect NOTIMP */
if (opts[item->test].opcode != 0 && rcode != 4) if (opts[item->test].opcode != 0 && rcode != 4)
addtag(item, rcodetext(rcode)), ok = 0; addtag(item, rcodetext(rcode)), ok = 0;
} }
/* Expect BADVERS to EDNS Version != 0 */
if (opts[item->test].version != 0) if (opts[item->test].version != 0)
if (rcode != 16) /* badvers */ if (rcode != ns_r_badvers)
addtag(item, rcodetext(rcode)), ok = 0; addtag(item, rcodetext(rcode)), ok = 0;
if ((ednsttl & 0xff0000) != 0)
/* Only EDNS version 0 is currently defined. */
ednsvers = (ednsttl >> 16) & 0xff;
if (ednsvers != 0 ||
(ednsvers < opts[item->test].version && rcode != ns_r_badvers &&
rcode != ns_r_formerr) ||
(ednsvers >= opts[item->test].version && rcode == ns_r_badvers))
addtag(item, "badversion"), ok = 0; addtag(item, "badversion"), ok = 0;
if (!seenopt && opts[item->test].udpsize) if (!seenopt && opts[item->test].udpsize)
addtag(item, "noopt"), ok = 0; addtag(item, "noopt"), ok = 0;
...@@ -1581,27 +1623,45 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1581,27 +1623,45 @@ process(struct workitem *item, unsigned char *buf, int n) {
if (seenrrsig && (opts[item->test].flags & 0x8000) != 0 && if (seenrrsig && (opts[item->test].flags & 0x8000) != 0 &&
(ednsttl & 0x8000) == 0) (ednsttl & 0x8000) == 0)
addtag(item, "nodo"), ok = 0; addtag(item, "nodo"), ok = 0;
/* AA is only defined for QUERY */
if (!aa && opts[item->test].version == 0 && if (!aa && opts[item->test].version == 0 &&
rcode == ns_r_noerror && opts[item->test].opcode == 0) rcode == ns_r_noerror && opts[item->test].opcode == 0)
addtag(item, "noaa"), ok = 0; addtag(item, "noaa"), ok = 0;
if (aa && opts[item->test].opcode != 0) if (aa && opts[item->test].opcode != 0)
addtag(item, "aa"), ok = 0; addtag(item, "aa"), ok = 0;
/* RA is only defined for QUERY */
if (ra && opts[item->test].opcode) if (ra && opts[item->test].opcode)
addtag(item, "ra"), ok = 0; addtag(item, "ra"), ok = 0;
/* RD is only defined for QUERY */
if (rd && (opts[item->test].opcode || !opts[item->test].rd)) if (rd && (opts[item->test].opcode || !opts[item->test].rd))
addtag(item, "rd"), ok = 0; addtag(item, "rd"), ok = 0;
if (!rd && opts[item->test].rd) if (!rd && opts[item->test].rd && opts[item->test].opcode == 0)
addtag(item, "nord"), ok = 0; addtag(item, "nord"), ok = 0;
/* AD is only defined for QUERY */
if (ad && (opts[item->test].opcode || if (ad && (opts[item->test].opcode ||
(!opts[item->test].ad && (opts[item->test].flags & 0x8000) == 0))) (!opts[item->test].ad && (opts[item->test].flags & 0x8000) == 0)))
addtag(item, "ad"), ok = 0; addtag(item, "ad"), ok = 0;
/* CD is only defined for QUERY */
if (cd && (opts[item->test].opcode || !opts[item->test].cd)) if (cd && (opts[item->test].opcode || !opts[item->test].cd))
addtag(item, "cd"), ok = 0; addtag(item, "cd"), ok = 0;
/* Last reserved bit. It is not supposed to be echoed per
RFC 1034. */
if (z) if (z)
addtag(item, "z"), ok = 0; addtag(item, "z"), ok = 0;
/* Only DO is currently defined. */
if ((ednsttl & 0x7fff) != 0) if ((ednsttl & 0x7fff) != 0)
addtag(item, "mbz"), ok = 0; addtag(item, "mbz"), ok = 0;
if (seenrrsig)
/* Only record seenrrsig if the test is "do". */
if (seenrrsig && strcmp(opts[item->test].name, "do") == 0)