From: Peter van Dijk Date: Fri, 27 Aug 2021 10:23:43 +0000 (+0200) Subject: add opcode support to sdig (so we can send NOTIFY) X-Git-Tag: dnsdist-1.7.0-alpha1~14^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af40821f9b9b3a8ddd7bc81524f7375a216dfb98;p=thirdparty%2Fpdns.git add opcode support to sdig (so we can send NOTIFY) --- diff --git a/docs/manpages/sdig.1.rst b/docs/manpages/sdig.1.rst index 9c6fad35f9..ee916ed50a 100644 --- a/docs/manpages/sdig.1.rst +++ b/docs/manpages/sdig.1.rst @@ -57,6 +57,8 @@ tlsProvider *name* when using DoT, use TLS provider *name*. Currently supported (if compiled in): `openssl` and `gnutls`. Default is `openssl` if available. xpf *XPFCODE* *XPFVERSION* *XPFPROTO* *XPFSRC* *XPFDST* Send an *XPF* additional with these parameters. +opcode *OPNUM* + Use opcode *OPNUM* instead of 0 (Query). For example, ``sdig 192.0.2.1 53 example.com SOA opcode 4`` sends a ``NOTIFY``. Examples -------- diff --git a/pdns/sdig.cc b/pdns/sdig.cc index e7503d26cf..8188a9e495 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -42,7 +42,7 @@ static void usage() "[tcp] [dot] [insecure] [fastOpen] [subjectName name] [caStore file] [tlsProvider openssl|gnutls] " "[xpf XPFDATA] [class CLASSNUM] " "[proxy UDP(0)/TCP(1) SOURCE-IP-ADDRESS-AND-PORT DESTINATION-IP-ADDRESS-AND-PORT] " - "[dumpluaraw]" + "[dumpluaraw] [opcode OPNUM]" << endl; } @@ -60,9 +60,9 @@ static void fillPacket(vector& packet, const string& q, const string& t bool dnssec, const boost::optional ednsnm, bool recurse, uint16_t xpfcode, uint16_t xpfversion, uint64_t xpfproto, char* xpfsrc, char* xpfdst, - QClass qclass, uint16_t qid) + QClass qclass, uint8_t opcode, uint16_t qid) { - DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t), qclass); + DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t), qclass, opcode); if (dnssec || ednsnm || getenv("SDIGBUFSIZE")) { char* sbuf = getenv("SDIGBUFSIZE"); @@ -212,6 +212,7 @@ try { uint16_t xpfcode = 0, xpfversion = 0, xpfproto = 0; char *xpfsrc = NULL, *xpfdst = NULL; QClass qclass = QClass::IN; + uint8_t opcode = 0; string proxyheader; string subjectName; string caStore; @@ -282,6 +283,13 @@ try { } qclass = atoi(argv[++i]); } + else if (strcmp(argv[i], "opcode") == 0) { + if (argc < i+2) { + cerr << "opcode needs an argument"< packet; s_expectedIDs.insert(0); fillPacket(packet, name, type, dnssec, ednsnm, recurse, xpfcode, xpfversion, - xpfproto, xpfsrc, xpfdst, qclass, 0); + xpfproto, xpfsrc, xpfdst, qclass, opcode, 0); MiniCurl mc; MiniCurl::MiniCurlHeaders mch; mch.insert(std::make_pair("Content-Type", "application/dns-message")); @@ -422,7 +430,7 @@ try { vector packet; s_expectedIDs.insert(counter); fillPacket(packet, it.first, it.second, dnssec, ednsnm, recurse, xpfcode, - xpfversion, xpfproto, xpfsrc, xpfdst, qclass, counter); + xpfversion, xpfproto, xpfsrc, xpfdst, qclass, opcode, counter); counter++; // Prefer to do a single write, so that fastopen can send all the data on SYN @@ -453,7 +461,7 @@ try { vector packet; s_expectedIDs.insert(0); fillPacket(packet, name, type, dnssec, ednsnm, recurse, xpfcode, xpfversion, - xpfproto, xpfsrc, xpfdst, qclass, 0); + xpfproto, xpfsrc, xpfdst, qclass, opcode, 0); string question(packet.begin(), packet.end()); Socket sock(dest.sin4.sin_family, SOCK_DGRAM); question = proxyheader + question;