]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add opcode support to sdig (so we can send NOTIFY)
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 27 Aug 2021 10:23:43 +0000 (12:23 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 16 Sep 2021 07:34:32 +0000 (09:34 +0200)
docs/manpages/sdig.1.rst
pdns/sdig.cc

index 9c6fad35f9763845c955d7e50011e652dbbef3ce..ee916ed50a3937b99359ddb5a49f8451422d81ec 100644 (file)
@@ -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
 --------
index e7503d26cf1788bd915b4be5da0e474fa7aa8162..8188a9e49521e44205aabe62d2e33c429a7c6b16 100644 (file)
@@ -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<uint8_t>& packet, const string& q, const string& t
                        bool dnssec, const boost::optional<Netmask> 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"<<endl;
+          exit(EXIT_FAILURE);
+        }
+        opcode = atoi(argv[++i]);
+      }
       else if (strcmp(argv[i], "subjectName") == 0) {
         if (argc < i + 2) {
           cerr << "subjectName needs an argument"<<endl;
@@ -367,7 +375,7 @@ try {
     vector<uint8_t> 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<uint8_t> 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<uint8_t> 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;