From 8290ad9f7a47edc0594ca13bbe45e8efd476def5 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 28 May 2015 14:34:59 +0200 Subject: [PATCH] spread support for reporting udp packet drops from auth to recursor - needs documentation! --- pdns/dynhandler.cc | 26 -------------------------- pdns/misc.cc | 30 ++++++++++++++++++++++++++++++ pdns/misc.hh | 1 + pdns/rec_channel_rec.cc | 7 +++++++ 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index fa7651ac6..b0e8d0126 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -324,32 +324,6 @@ string DLReloadHandler(const vector&parts, Utility::pid_t ppid) return "Ok"; } -uint64_t udpErrorStats(const std::string& str) -{ - ifstream ifs("/proc/net/snmp"); - if(!ifs) - return 0; - string line; - vector parts; - while(getline(ifs,line)) { - if(boost::starts_with(line, "Udp: ") && isdigit(line[5])) { - stringtok(parts, line, " \n\t\r"); - if(parts.size() < 7) - break; - if(str=="udp-rcvbuf-errors") - return boost::lexical_cast(parts[5]); - else if(str=="udp-sndbuf-errors") - return boost::lexical_cast(parts[6]); - else if(str=="udp-noport-errors") - return boost::lexical_cast(parts[2]); - else if(str=="udp-in-errors") - return boost::lexical_cast(parts[3]); - else - return 0; - } - } - return 0; -} string DLListZones(const vector&parts, Utility::pid_t ppid) { diff --git a/pdns/misc.cc b/pdns/misc.cc index 8d3a8b4ba..77461b987 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include "misc.hh" #include #include @@ -971,3 +972,32 @@ bool setCloseOnExec(int sock) return true; } +// please feel free to add other operating systems here. What we need are stats on dropped UDP packets +uint64_t udpErrorStats(const std::string& str) +{ +#ifdef __linux__ + ifstream ifs("/proc/net/snmp"); + if(!ifs) + return 0; + string line; + vector parts; + while(getline(ifs,line)) { + if(boost::starts_with(line, "Udp: ") && isdigit(line[5])) { + stringtok(parts, line, " \n\t\r"); + if(parts.size() < 7) + break; + if(str=="udp-rcvbuf-errors") + return boost::lexical_cast(parts[5]); + else if(str=="udp-sndbuf-errors") + return boost::lexical_cast(parts[6]); + else if(str=="udp-noport-errors") + return boost::lexical_cast(parts[2]); + else if(str=="udp-in-errors") + return boost::lexical_cast(parts[3]); + else + return 0; + } + } +#endif + return 0; +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 99632853d..6cd29f34d 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -553,4 +553,5 @@ bool setBlocking( int sock ); bool setNonBlocking( int sock ); int closesocket(int fd); bool setCloseOnExec(int sock); +uint64_t udpErrorStats(const std::string& str); #endif diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 1a1da6d9e..e61066417 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -556,6 +556,13 @@ RecursorControlParser::RecursorControlParser() addGetStat("chain-resends", &g_stats.chainResends); addGetStat("tcp-clients", boost::bind(TCPConnection::getCurrentConnections)); +#ifdef __linux__ + addGetStat("udp-recvbuf-errors", boost::bind(udpErrorStats, "udp-recvbuf-errors")); + addGetStat("udp-sndbuf-errors", boost::bind(udpErrorStats, "udp-sndbuf-errors")); + addGetStat("udp-noport-errors", boost::bind(udpErrorStats, "udp-noport-errors")); + addGetStat("udp-in-errors", boost::bind(udpErrorStats, "udp-in-errors")); +#endif + addGetStat("edns-ping-matches", &g_stats.ednsPingMatches); addGetStat("edns-ping-mismatches", &g_stats.ednsPingMismatches); -- 2.50.0