]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/nproxy.cc
Merge pull request #7908 from omoerbeek/rec-4.1.14-changelog
[thirdparty/pdns.git] / pdns / nproxy.cc
index cf91e0a03019cdbe1b208581c6112bca444a30da..e79f8de75966accec800dc6336413b08e6f8dc10 100644 (file)
@@ -25,7 +25,6 @@
 #include <bitset>
 #include "dnsparser.hh"
 #include "iputils.hh"
-#undef L
 #include <boost/program_options.hpp>
 
 #include <boost/format.hpp>
@@ -38,6 +37,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <grp.h>
+#include <unistd.h>
 #include "dnsrecords.hh"
 #include "mplexer.hh"
 #include "statbag.hh"
@@ -51,7 +51,7 @@ po::variables_map g_vm;
 
 StatBag S;
 
-SelectFDMultiplexer g_fdm;
+FDMultiplexer* g_fdm;
 int g_pdnssocket;
 bool g_verbose;
 
@@ -78,9 +78,11 @@ try
 {
   char buffer[1500];
   struct NotificationInFlight nif;
+  /* make sure we report enough room for IPv6 */
+  nif.source.sin4.sin_family = AF_INET6;
   nif.origSocket = fd;
 
-  socklen_t socklen=sizeof(nif.source);
+  socklen_t socklen=nif.source.getSocklen();
 
   int res=recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&nif.source, &socklen);
   if(!res)
@@ -89,8 +91,7 @@ try
   if(res < 0) 
     throw runtime_error("reading packet from remote: "+stringerror());
     
-  string packet(buffer, res);
-  MOADNSParser mdp(true, packet);
+  MOADNSParser mdp(true, string(buffer,res));
   nif.domain = mdp.d_qname;
   nif.origID = mdp.d_header.id;
 
@@ -149,8 +150,10 @@ try
 {
   char buffer[1500];
   struct NotificationInFlight nif;
+  /* make sure we report enough room for IPv6 */
+  nif.source.sin4.sin_family = AF_INET6;
 
-  socklen_t socklen=sizeof(nif.source);
+  socklen_t socklen=nif.source.getSocklen();
 
   int len=recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&nif.source, &socklen);
   if(!len)
@@ -214,6 +217,11 @@ try
   reportAllTypes();
   openlog("nproxy", LOG_NDELAY | LOG_PID, LOG_DAEMON);
 
+  g_fdm = FDMultiplexer::getMultiplexerSilent();
+  if(!g_fdm) {
+    throw std::runtime_error("Could not enable a multiplexer");
+  }
+  
   po::options_description desc("Allowed options");
   desc.add_options()
     ("help,h", "produce help message")
@@ -269,7 +277,7 @@ try
     if(::bind(sock,(sockaddr*) &local, local.getSocklen()) < 0)
       throw runtime_error("Binding socket for incoming packets to '"+ local.toStringWithPort()+"': "+stringerror());
 
-    g_fdm.addReadFD(sock, handleOutsideUDPPacket); // add to fdmultiplexer for each socket
+    g_fdm->addReadFD(sock, handleOutsideUDPPacket); // add to fdmultiplexer for each socket
     syslogFmt(boost::format("Listening for external notifications on address %s") % local.toStringWithPort());
   }
 
@@ -290,7 +298,7 @@ try
 
   syslogFmt(boost::format("Sending notifications from %s to internal address %s") % originAddress.toString() % pdns.toStringWithPort());
 
-  g_fdm.addReadFD(g_pdnssocket, handleInsideUDPPacket);
+  g_fdm->addReadFD(g_pdnssocket, handleInsideUDPPacket);
 
   int null_fd=open("/dev/null",O_RDWR); /* open stdin */
   if(null_fd < 0)
@@ -328,7 +336,7 @@ try
   struct timeval now;
   for(;;) {
     gettimeofday(&now, 0);
-    g_fdm.run(&now);
+    g_fdm->run(&now);
     // check for notifications that have been outstanding for more than 10 seconds
     expireOldNotifications();
   }