From: bert hubert Date: Wed, 11 Feb 2015 16:00:21 +0000 (+0100) Subject: on Linux, SO_TIMESTAMP == SCM_TIMESTAMP, on at least FreeBSD, it is not, causing... X-Git-Tag: dnsdist-1.0.0-alpha1~295^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22cf1fda34eca2d88505f08afd1ef26a6b33835b;p=pdns on Linux, SO_TIMESTAMP == SCM_TIMESTAMP, on at least FreeBSD, it is not, causing us to miss harvesting the timestamp, and dropping all packets as too old. With this change, we don't drop if we can't find the timestamp, plus harvest it properly --- diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 2f09d5192..83c48d9ca 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -1,4 +1,6 @@ #include "iputils.hh" +#include + /** these functions provide a very lightweight wrapper to the Berkeley sockets API. Errors -> exceptions! */ static void RuntimeError(const boost::format& fmt) @@ -63,7 +65,7 @@ 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) && + if ((cmsg->cmsg_level == SOL_SOCKET) && (cmsg->cmsg_type == SO_TIMESTAMP || cmsg->cmsg_type == SCM_TIMESTAMP) && CMSG_LEN(sizeof(*tv)) == cmsg->cmsg_len) { memcpy(tv, CMSG_DATA(cmsg), sizeof(*tv)); return true; diff --git a/pdns/misc.cc b/pdns/misc.cc index 6e0fa7ecf..01529cf05 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -21,6 +21,7 @@ */ #include +#include #include #include #include diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index e07e9afd0..fdee0f115 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -934,7 +934,7 @@ string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fr struct timeval diff = g_now - tv; double delta=(diff.tv_sec*1000 + diff.tv_usec/1000.0); - if(delta > 1000.0) { + if(tv.tv_sec && delta > 1000.0) { g_stats.tooOldDrops++; return 0; }