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
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 \
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 \
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 \
}
+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);
+}
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
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()
}
}
-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) {
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)) {
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;