]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
move infrastructure for serving from 0.0.0.0 and :: from Auth server to a shared...
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 8 Jan 2015 13:50:49 +0000 (14:50 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 8 Jan 2015 13:50:49 +0000 (14:50 +0100)
pdns/Makefile-recursor
pdns/Makefile.am
pdns/dist-recursor
pdns/iputils.cc
pdns/iputils.hh
pdns/nameserver.cc

index 2415dc6887da80609b8f170a34f43050baa11ae4..215521441f5755bdcefd2d335a2898d75a50e668 100644 (file)
@@ -24,7 +24,7 @@ dns_random.o pubsuffix.o ext/polarssl/library/aes.o dnslabeltext.o \
 lua-pdns.o lua-recursor.o randomhelper.o recpacketcache.o dns.o \
 reczones.o base32.o nsecrecords.o json.o ws-recursor.o ws-api.o \
 version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o ext/yahttp/yahttp/router.o \
-rec-carbon.o secpoll-recursor.o lua-iputils.o
+rec-carbon.o secpoll-recursor.o lua-iputils.o iputils.o
 
 REC_CONTROL_OBJECTS=rec_channel.o rec_control.o arguments.o misc.o \
        unix_utility.o logger.o qtype.o
index 45b71f9b7788b4e83e1e7b14fe22830401cc23f6..ffff79dbe6c5fa02b4414b8828dec40df4275aa2 100644 (file)
@@ -132,7 +132,7 @@ pdns_server_SOURCES = \
        dynlistener.cc dynlistener.hh \
        dynmessenger.hh \
        ednssubnet.cc ednssubnet.hh \
-       iputils.hh \
+       iputils.cc iputils.hh \
        json.cc json.hh \
        lock.hh \
        logger.cc logger.hh \
@@ -897,6 +897,7 @@ pdns_recursor_SOURCES = \
        dnswriter.cc dnswriter.hh \
        epollmplexer.cc \
        htimer.cc htimer.hh \
+       iputils.cc \
        json.cc json.hh \
        logger.cc \
        lua-pdns.cc lua-pdns.hh lua-iputils.cc \
index c4f39ffec44ce9b947a0fea3f0d782713866e6a9..ced2005cc6a1b63419a68bbf60b7993873dffb9e 100755 (executable)
@@ -33,7 +33,7 @@ recpacketcache.hh base32.hh cachecleaner.hh json.hh version.hh \
 ws-recursor.hh ws-api.hh secpoll-recursor.hh \
 responsestats.hh webserver.hh"
 
-CFILES="syncres.cc  misc.cc unix_utility.cc qtype.cc \
+CFILES="syncres.cc iputils.cc  misc.cc unix_utility.cc qtype.cc \
 logger.cc arguments.cc  lwres.cc pdns_recursor.cc lua-iputils.cc \
 recursor_cache.cc  dnsparser.cc dnswriter.cc  dnsrecords.cc  rcpgenerator.cc  \
 base64.cc  zoneparser-tng.cc  rec_channel.cc rec_channel_rec.cc rec_control.cc \
index d9eb9b5a6e4a72294920cc34179dd651712ac612..11f8181af5ab43041c04e134e5243ff0ad4c6e0a 100644 (file)
@@ -58,3 +58,78 @@ int SSetsockopt(int sockfd, int level, int opname, int value)
 }
 
 
+bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv) 
+{
+#ifdef SO_TIMESTAMP
+  struct cmsghdr *cmsg;
+  for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh,cmsg)) {
+    if ((cmsg->cmsg_level == SOL_SOCKET) && (cmsg->cmsg_type == SO_TIMESTAMP) && 
+       CMSG_LEN(sizeof(*tv)) == cmsg->cmsg_len) {
+      memcpy(tv, CMSG_DATA(cmsg), sizeof(*tv));
+      return true;
+    }
+  }
+#endif
+  return false;
+}
+bool HarvestDestinationAddress(struct msghdr* msgh, ComboAddress* destination)
+{
+  memset(destination, 0, sizeof(*destination));
+  struct cmsghdr *cmsg;
+  for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh,cmsg)) {
+#if defined(IP_PKTINFO)
+     if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
+        struct in_pktinfo *i = (struct in_pktinfo *) CMSG_DATA(cmsg);
+        destination->sin4.sin_addr = i->ipi_addr;
+        destination->sin4.sin_family = AF_INET;
+        return true;
+    }
+#elif defined(IP_RECVDSTADDR)
+    if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_RECVDSTADDR)) {
+      struct in_addr *i = (struct in_addr *) CMSG_DATA(cmsg);
+      destination->sin4.sin_addr = *i;
+      destination->sin4.sin_family = AF_INET;      
+      return true;
+    }
+#endif
+
+    if ((cmsg->cmsg_level == IPPROTO_IPV6) && (cmsg->cmsg_type == IPV6_PKTINFO)) {
+        struct in6_pktinfo *i = (struct in6_pktinfo *) CMSG_DATA(cmsg);
+        destination->sin6.sin6_addr = i->ipi6_addr;
+        destination->sin4.sin_family = AF_INET6;
+        return true;
+    }
+  }
+  return false;
+}
+
+bool IsAnyAddress(const ComboAddress& addr)
+{
+  if(addr.sin4.sin_family == AF_INET)
+    return addr.sin4.sin_addr.s_addr == 0;
+  else if(addr.sin4.sin_family == AF_INET6)
+    return !memcmp(&addr.sin6.sin6_addr, &in6addr_any, sizeof(addr.sin6.sin6_addr));
+  
+  return false;
+}
+
+int sendfromto(int sock, const char* data, int len, int flags, const ComboAddress& from, const ComboAddress& to)
+{
+  struct msghdr msgh;
+  struct iovec iov;
+  char cbuf[256];
+
+  /* Set up iov and msgh structures. */
+  memset(&msgh, 0, sizeof(struct msghdr));
+  iov.iov_base = (void*)data;
+  iov.iov_len = len;
+  msgh.msg_iov = &iov;
+  msgh.msg_iovlen = 1;
+  msgh.msg_name = (struct sockaddr*)&to;
+  msgh.msg_namelen = to.getSocklen();
+
+  if(from.sin4.sin_family) {
+    addCMsgSrcAddr(&msgh, cbuf, &from);
+  }
+  return sendmsg(sock, &msgh, flags);
+}
index 7b7ce628242d9d1e1bd9595105565c93fbee3e63..99abd3384e2b35de1cd505b753290a43c8104b69 100644 (file)
@@ -433,4 +433,14 @@ int SAccept(int sockfd, ComboAddress& remote);
 int SListen(int sockfd, int limit);
 int SSetsockopt(int sockfd, int level, int opname, int value);
 
+#if defined(IP_PKTINFO)
+  #define GEN_IP_PKTINFO IP_PKTINFO
+#elif defined(IP_RECVDSTADDR)
+  #define GEN_IP_PKTINFO IP_RECVDSTADDR 
+#endif
+bool IsAnyAddress(const ComboAddress& addr);
+bool HarvestDestinationAddress(struct msghdr* msgh, ComboAddress* destination);
+bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv);
+
+
 #endif
index 4eaaddc5242f884535ab62afae49f3522d552607..fca61417007c28a4098da7b61371b762f2129352 100644 (file)
@@ -81,12 +81,6 @@ extern StatBag S;
     The main() of PowerDNS can be found in receiver.cc - start reading there for further insights into the operation of the nameserver
 */
 
-#if defined(IP_PKTINFO)
-  #define GEN_IP_PKTINFO IP_PKTINFO
-#elif defined(IP_RECVDSTADDR)
-  #define GEN_IP_PKTINFO IP_RECVDSTADDR 
-#endif
-
 vector<ComboAddress> g_localaddresses; // not static, our unit tests need to poke this
 
 void UDPNameserver::bindIPv4()
@@ -157,17 +151,6 @@ void UDPNameserver::bindIPv4()
   }
 }
 
-static bool IsAnyAddress(const ComboAddress& addr)
-{
-  if(addr.sin4.sin_family == AF_INET)
-    return addr.sin4.sin_addr.s_addr == 0;
-  else if(addr.sin4.sin_family == AF_INET6)
-    return !memcmp(&addr.sin6.sin6_addr, &in6addr_any, sizeof(addr.sin6.sin6_addr));
-  
-  return false;
-}
-
-
 bool AddressIsUs(const ComboAddress& remote)
 {
   BOOST_FOREACH(const ComboAddress& us, g_localaddresses) {
@@ -224,7 +207,6 @@ void UDPNameserver::bindIPv6()
     if(!Utility::setNonBlocking(s))
       throw PDNSException("Unable to set UDPv6 socket to non-blocking: "+stringerror());
 
-
     ComboAddress locala(localname, ::arg().asNum("local-port"));
     
     if(IsAnyAddress(locala)) {
@@ -333,52 +315,6 @@ void UDPNameserver::send(DNSPacket *p)
     L<<Logger::Error<<"Error sending reply with sendmsg (socket="<<p->getSocket()<<", dest="<<p->d_remote.toStringWithPort()<<"): "<<strerror(errno)<<endl;
 }
 
-static bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv) 
-{
-#ifdef SO_TIMESTAMP
-  struct cmsghdr *cmsg;
-  for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh,cmsg)) {
-    if ((cmsg->cmsg_level == SOL_SOCKET) && (cmsg->cmsg_type == SO_TIMESTAMP) && 
-       CMSG_LEN(sizeof(*tv)) == cmsg->cmsg_len) {
-      memcpy(tv, CMSG_DATA(cmsg), sizeof(*tv));
-      return true;
-    }
-  }
-#endif
-  return false;
-}
-
-static bool HarvestDestinationAddress(struct msghdr* msgh, ComboAddress* destination)
-{
-  memset(destination, 0, sizeof(*destination));
-  struct cmsghdr *cmsg;
-  for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh,cmsg)) {
-#if defined(IP_PKTINFO)
-     if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
-        struct in_pktinfo *i = (struct in_pktinfo *) CMSG_DATA(cmsg);
-        destination->sin4.sin_addr = i->ipi_addr;
-        destination->sin4.sin_family = AF_INET;
-        return true;
-    }
-#elif defined(IP_RECVDSTADDR)
-    if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_RECVDSTADDR)) {
-      struct in_addr *i = (struct in_addr *) CMSG_DATA(cmsg);
-      destination->sin4.sin_addr = *i;
-      destination->sin4.sin_family = AF_INET;      
-      return true;
-    }
-#endif
-
-    if ((cmsg->cmsg_level == IPPROTO_IPV6) && (cmsg->cmsg_type == IPV6_PKTINFO)) {
-        struct in6_pktinfo *i = (struct in6_pktinfo *) CMSG_DATA(cmsg);
-        destination->sin6.sin6_addr = i->ipi6_addr;
-        destination->sin4.sin_family = AF_INET6;
-        return true;
-    }
-  }
-  return false;
-}
-
 DNSPacket *UDPNameserver::receive(DNSPacket *prefilled)
 {
   ComboAddress remote;