From 22cf1fda34eca2d88505f08afd1ef26a6b33835b Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 11 Feb 2015 17:00:21 +0100 Subject: [PATCH] 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 --- pdns/iputils.cc | 4 +++- pdns/misc.cc | 1 + pdns/pdns_recursor.cc | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) 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; } -- 2.40.0