if(localname=="0.0.0.0")
setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one));
+ setSocketTimestamps(s);
+
#ifdef SO_REUSEPORT
if( d_can_reuseport )
if( setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) )
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)); // if this fails, we report an error in tcpreceiver too
}
+ setSocketTimestamps(s);
+
#ifdef SO_REUSEPORT
if( d_can_reuseport )
if( setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) )
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)
+{
+ 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;
+ }
+ }
+ return false;
+}
+
static bool HarvestDestinationAddress(struct msghdr* msgh, ComboAddress* destination)
{
memset(destination, 0, sizeof(*destination));
packet=prefilled;
else
packet=new DNSPacket; // don't forget to free it!
- packet->d_dt.set(); // timing
+
packet->setSocket(sock);
packet->setRemote(&remote);
packet->d_anyLocal = dest;
}
+ struct timeval recvtv;
+ if(HarvestTimestamp(&msgh, &recvtv)) {
+ packet->d_dt.setTimeval(recvtv);
+ }
+ else
+ packet->d_dt.set(); // timing
+
if(packet->parse(mesg, len)<0) {
S.inc("corrupt-packets");
S.ringAccount("remotes-corrupt", packet->getRemote());