]> granicus.if.org Git - pdns/commitdiff
rec: Call `gettag()` for TCP queries
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Aug 2016 14:15:12 +0000 (16:15 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 26 Aug 2016 10:16:06 +0000 (12:16 +0200)
The `gettag()` hook used to be called to set a tag for the packet cache
and hence it did not make sense to call it for TCP queries, but now it
can also be used to policy tags.

pdns/pdns_recursor.cc

index fa2b40c9c0db1d4554d1504da6593d6f667b4b9a..b6c7130825ebb0f6b2389687013de78a6587c048 100644 (file)
@@ -1286,23 +1286,48 @@ void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       socklen_t len = dest.getSocklen();
       getsockname(conn->getFD(), (sockaddr*)&dest, &len); // if this fails, we're ok with it
       dc->setLocal(dest);
+      Netmask ednssubnet;
+      DNSName qname;
+      uint16_t qtype=0;
+      uint16_t qclass=0;
+      bool needECS = false;
 #ifdef HAVE_PROTOBUF
       auto luaconfsLocal = g_luaconfs.getLocal();
+      if (luaconfsLocal->protobufServer) {
+        needECS = true;
+      }
+#endif
+
+      if(needECS || (t_pdl->get() && (*t_pdl)->d_gettag)) {
+
+        try {
+          getQNameAndSubnet(std::string(conn->data, conn->qlen), &qname, &qtype, &qclass, &ednssubnet);
 
+          if(t_pdl->get() && (*t_pdl)->d_gettag) {
+            try {
+              dc->d_tag = (*t_pdl)->gettag(conn->d_remote, ednssubnet, dest, qname, qtype, &dc->d_policyTags);
+            }
+            catch(std::exception& e)  {
+              if(g_logCommonErrors)
+                L<<Logger::Warning<<"Error parsing a query packet qname='"<<qname<<"' for tag determination, setting tag=0: "<<e.what()<<endl;
+            }
+          }
+        }
+        catch(std::exception& e)
+        {
+          if(g_logCommonErrors)
+            L<<Logger::Warning<<"Error parsing a query packet for tag determination, setting tag=0: "<<e.what()<<endl;
+        }
+      }
+#ifdef HAVE_PROTOBUF
       if(luaconfsLocal->protobufServer) {
         dc->d_uuid = (*t_uuidGenerator)();
 
         try {
-          DNSName qname;
-          uint16_t qtype;
-          uint16_t qclass;
-          Netmask ednssubnet;
           const struct dnsheader* dh = (const struct dnsheader*) conn->data;
-
-          getQNameAndSubnet(std::string(conn->data, conn->qlen), &qname, &qtype, &qclass, &ednssubnet);
           dc->d_ednssubnet = ednssubnet;
 
-          protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, dc->d_uuid, dest, conn->d_remote, ednssubnet, true, dh->id, conn->qlen, qname, qtype, qclass, std::vector<std::string>());
+          protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, dc->d_uuid, dest, conn->d_remote, ednssubnet, true, dh->id, conn->qlen, qname, qtype, qclass, dc->d_policyTags);
         }
         catch(std::exception& e) {
           if(g_logCommonErrors)