Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP: Handle SNMP alarms so we can reconnect to the master #5328

Merged
merged 3 commits into from Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion build-scripts/travis.sh
Expand Up @@ -338,9 +338,11 @@ install_recursor() {
run "sudo apt-get -qq --no-install-recommends install \
authbind \
daemontools \
jq \
libfaketime \
libsnmp-dev \
moreutils \
jq"
snmpd"
run "cd .."
run "wget https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
run "unzip top-1m.csv.zip -d ${TRAVIS_BUILD_DIR}/regression-tests"
Expand Down
9 changes: 9 additions & 0 deletions m4/pdns_with_net_snmp.m4
Expand Up @@ -11,6 +11,15 @@ AC_DEFUN([PDNS_WITH_NET_SNMP], [
AS_IF([test "x$with_net_snmp" = "xyes" -o "x$with_net_snmp" = "xauto"], [
AC_CHECK_PROG([NET_SNMP_CFLAGS], [net-snmp-config], [`net-snmp-config --cflags`])
AC_CHECK_PROG([NET_SNMP_LIBS], [net-snmp-config], [`net-snmp-config --agent-libs`])
AC_CHECK_DECLS([snmp_select_info2], [ : ], [ : ],
[AC_INCLUDES_DEFAULT
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/definitions.h>
#include <net-snmp/types.h>
#include <net-snmp/utilities.h>
#include <net-snmp/config_api.h>
#include <net-snmp/session_api.h>
])
])
])
AS_IF([test "x$with_net_snmp" = "xyes"], [
Expand Down
9 changes: 4 additions & 5 deletions pdns/devpollmplexer.cc
Expand Up @@ -35,7 +35,6 @@
#include "misc.hh"
#include "syncres.hh"

#include "namespaces.hh"
#include "namespaces.hh"

class DevPollFDMultiplexer : public FDMultiplexer
Expand All @@ -47,7 +46,7 @@ class DevPollFDMultiplexer : public FDMultiplexer
close(d_devpollfd);
}

virtual int run(struct timeval* tv);
virtual int run(struct timeval* tv, int timeout=500);

virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const funcparam_t& parameter);
virtual void removeFD(callbackmap_t& cbmap, int fd);
Expand Down Expand Up @@ -113,15 +112,15 @@ void DevPollFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd)
}
}

int DevPollFDMultiplexer::run(struct timeval* now)
int DevPollFDMultiplexer::run(struct timeval* now, int timeout)
{
if(d_inrun) {
throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
}
struct dvpoll dvp;
dvp.dp_nfds = d_readCallbacks.size() + d_writeCallbacks.size();
dvp.dp_fds = new pollfd[dvp.dp_nfds];
dvp.dp_timeout = 500;
dvp.dp_timeout = timeout;
int ret=ioctl(d_devpollfd, DP_POLL, &dvp);
gettimeofday(now,0); // MANDATORY!

Expand Down Expand Up @@ -151,7 +150,7 @@ int DevPollFDMultiplexer::run(struct timeval* now)
}
delete[] dvp.dp_fds;
d_inrun=false;
return 0;
return ret;
}

#if 0
Expand Down
24 changes: 22 additions & 2 deletions pdns/dnsdistdist/Makefile.am
Expand Up @@ -47,7 +47,11 @@ EXTRA_DIST=dnslabeltext.rl \
bpf-filter.main.ebpf \
bpf-filter.qname.ebpf \
bpf-filter.ebpf.src \
DNSDIST-MIB.txt
DNSDIST-MIB.txt \
devpollmplexer.cc \
epollmplexer.cc \
kqueuemplexer.cc \
portsmplexer.cc

bin_PROGRAMS = dnsdist

Expand Down Expand Up @@ -93,15 +97,17 @@ dnsdist_SOURCES = \
ednscookies.cc ednscookies.hh \
ednssubnet.cc ednssubnet.hh \
gettime.cc gettime.hh \
htmlfiles.h \
iputils.cc iputils.hh \
lock.hh \
misc.cc misc.hh \
htmlfiles.h \
mplexer.hh \
namespaces.hh \
pdnsexception.hh \
protobuf.cc protobuf.hh \
qtype.cc qtype.hh \
remote_logger.cc remote_logger.hh \
selectmplexer.cc \
sholder.hh \
snmp-agent.cc snmp-agent.hh \
sodcrypto.cc sodcrypto.hh \
Expand Down Expand Up @@ -152,6 +158,20 @@ dnsdist.$(OBJEXT): dnsmessage.pb.cc
endif
endif

if HAVE_FREEBSD
dnsdist_SOURCES += kqueuemplexer.cc
endif

if HAVE_LINUX
dnsdist_SOURCES += epollmplexer.cc
endif

if HAVE_SOLARIS
dnsdist_SOURCES += \
devpollmplexer.cc \
portsmplexer.cc
endif

testrunner_SOURCES = \
base64.hh \
dns.hh \
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsdistdist/devpollmplexer.cc
1 change: 1 addition & 0 deletions pdns/dnsdistdist/epollmplexer.cc
1 change: 1 addition & 0 deletions pdns/dnsdistdist/kqueuemplexer.cc
1 change: 1 addition & 0 deletions pdns/dnsdistdist/mplexer.hh
1 change: 1 addition & 0 deletions pdns/dnsdistdist/portsmplexer.cc
1 change: 1 addition & 0 deletions pdns/dnsdistdist/selectmplexer.cc
9 changes: 4 additions & 5 deletions pdns/epollmplexer.cc
Expand Up @@ -31,7 +31,6 @@
#include <sys/epoll.h>
#endif

#include "namespaces.hh"
#include "namespaces.hh"

class EpollFDMultiplexer : public FDMultiplexer
Expand All @@ -43,7 +42,7 @@ class EpollFDMultiplexer : public FDMultiplexer
close(d_epollfd);
}

virtual int run(struct timeval* tv);
virtual int run(struct timeval* tv, int timeout=500);

virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const funcparam_t& parameter);
virtual void removeFD(callbackmap_t& cbmap, int fd);
Expand Down Expand Up @@ -124,13 +123,13 @@ void EpollFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd)
throw FDMultiplexerException("Removing fd from epoll set: "+stringerror());
}

int EpollFDMultiplexer::run(struct timeval* now)
int EpollFDMultiplexer::run(struct timeval* now, int timeout)
{
if(d_inrun) {
throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
}

int ret=epoll_wait(d_epollfd, d_eevents.get(), s_maxevents, 500);
int ret=epoll_wait(d_epollfd, d_eevents.get(), s_maxevents, timeout);
gettimeofday(now,0); // MANDATORY

if(ret < 0 && errno!=EINTR)
Expand All @@ -154,7 +153,7 @@ int EpollFDMultiplexer::run(struct timeval* now)
}
}
d_inrun=false;
return 0;
return ret;
}

#if 0
Expand Down
12 changes: 5 additions & 7 deletions pdns/kqueuemplexer.cc
Expand Up @@ -27,14 +27,12 @@
#include <iostream>
#include <unistd.h>
#include "misc.hh"
#include "syncres.hh"
#include <sys/types.h>
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <sys/event.h>
#endif
#include <sys/time.h>

#include "namespaces.hh"
#include "namespaces.hh"

class KqueueFDMultiplexer : public FDMultiplexer
Expand All @@ -46,7 +44,7 @@ class KqueueFDMultiplexer : public FDMultiplexer
close(d_kqueuefd);
}

virtual int run(struct timeval* tv);
virtual int run(struct timeval* tv, int timeout=500);

virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const boost::any& parameter);
virtual void removeFD(callbackmap_t& cbmap, int fd);
Expand Down Expand Up @@ -105,15 +103,15 @@ void KqueueFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd)
throw FDMultiplexerException("Removing fd from kqueue set: "+stringerror());
}

int KqueueFDMultiplexer::run(struct timeval* now)
int KqueueFDMultiplexer::run(struct timeval* now, int timeout)
{
if(d_inrun) {
throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
}

struct timespec ts;
ts.tv_sec=0;
ts.tv_nsec=500000000U;
ts.tv_sec=timeout/1000;
ts.tv_nsec=(timeout % 1000) * 1000000;

int ret=kevent(d_kqueuefd, 0, 0, d_kevents.get(), s_maxevents, &ts);
gettimeofday(now,0); // MANDATORY!
Expand Down Expand Up @@ -141,7 +139,7 @@ int KqueueFDMultiplexer::run(struct timeval* now)
}

d_inrun=false;
return 0;
return ret;
}

#if 0
Expand Down
9 changes: 4 additions & 5 deletions pdns/mplexer.hh
Expand Up @@ -30,7 +30,6 @@
#include <map>
#include <stdexcept>
#include <string>
#include "utility.hh"

class FDMultiplexerException : public std::runtime_error
{
Expand All @@ -50,7 +49,6 @@ public:
class FDMultiplexer
{
public:
// typedef boost::variant<PacketID, TCPConnection> funcparam_t;
typedef boost::any funcparam_t;
protected:

Expand All @@ -68,7 +66,9 @@ public:
virtual ~FDMultiplexer()
{}

virtual int run(struct timeval* tv) = 0;
/* tv will be updated to 'now' before run returns */
/* timeout is in ms */
virtual int run(struct timeval* tv, int timeout=500) = 0;

//! Add an fd to the read watch list - currently an fd can only be on one list at a time!
virtual void addReadFD(int fd, callbackfunc_t toDo, const funcparam_t& parameter=funcparam_t())
Expand Down Expand Up @@ -131,7 +131,6 @@ public:

virtual std::string getName() = 0;


protected:
typedef std::map<int, Callback> callbackmap_t;
callbackmap_t d_readCallbacks, d_writeCallbacks;
Expand Down Expand Up @@ -168,7 +167,7 @@ public:
virtual ~SelectFDMultiplexer()
{}

virtual int run(struct timeval* tv);
virtual int run(struct timeval* tv, int timeout=500);

virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const funcparam_t& parameter);
virtual void removeFD(callbackmap_t& cbmap, int fd);
Expand Down
13 changes: 5 additions & 8 deletions pdns/pollmplexer.cc
Expand Up @@ -6,9 +6,6 @@
#include <iostream>
#include <poll.h>
#include "misc.hh"
#include "syncres.hh"
#include "utility.hh"
#include "namespaces.hh"
#include "namespaces.hh"


Expand Down Expand Up @@ -49,7 +46,7 @@ bool pollfdcomp(const struct pollfd& a, const struct pollfd& b)
return a.fd < b.fd;
}

int PollFDMultiplexer::run(struct timeval* now)
int PollFDMultiplexer::run(struct timeval* now, int timeout=500)
{
if(d_inrun) {
throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
Expand All @@ -70,15 +67,15 @@ int PollFDMultiplexer::run(struct timeval* now)
pollfds.push_back(pollfd);
}

int ret=poll(&pollfds[0], pollfds.size(), 500);
Utility::gettimeofday(now, 0); // MANDATORY!
int ret=poll(&pollfds[0], pollfds.size(), timeout);
gettimeofday(now, 0); // MANDATORY!

if(ret < 0 && errno!=EINTR)
throw FDMultiplexerException("poll returned error: "+stringerror());

d_iter=d_readCallbacks.end();
d_inrun=true;

for(unsigned int n = 0; n < pollfds.size(); ++n) {
if(pollfds[n].revents == POLLIN) {
d_iter=d_readCallbacks.find(pollfds[n].fd);
Expand All @@ -97,7 +94,7 @@ int PollFDMultiplexer::run(struct timeval* now)
}
}
d_inrun=false;
return 0;
return ret;
}

#if 0
Expand Down
15 changes: 7 additions & 8 deletions pdns/portsmplexer.cc
Expand Up @@ -11,9 +11,7 @@
#include <iostream>

#include "misc.hh"
#include "syncres.hh"

#include "namespaces.hh"
#include "namespaces.hh"

class PortsFDMultiplexer : public FDMultiplexer
Expand All @@ -25,7 +23,7 @@ class PortsFDMultiplexer : public FDMultiplexer
close(d_portfd);
}

virtual int run(struct timeval* tv);
virtual int run(struct timeval* tv, int timeout=500);

virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const boost::any& parameter);
virtual void removeFD(callbackmap_t& cbmap, int fd);
Expand Down Expand Up @@ -80,16 +78,17 @@ void PortsFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd)
throw FDMultiplexerException("Removing fd from port set: "+stringerror());
}

int PortsFDMultiplexer::run(struct timeval* now)
int PortsFDMultiplexer::run(struct timeval* now, int timeout)
{
if(d_inrun) {
throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
}

struct timespec timeout;
timeout.tv_sec=0; timeout.tv_nsec=500000000;
struct timespec timeoutspec;
timeoutspec.tv_sec = time / 1000;
timeoutspec.tv_nsec = (time % 1000) * 1000000;
unsigned int numevents=1;
int ret= port_getn(d_portfd, d_pevents.get(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeout);
int ret= port_getn(d_portfd, d_pevents.get(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeoutspec);

/* port_getn has an unusual API - (ret == -1, errno == ETIME) can
mean partial success; you must check (*numevents) in this case
Expand Down Expand Up @@ -133,7 +132,7 @@ int PortsFDMultiplexer::run(struct timeval* now)
}

d_inrun=false;
return 0;
return numevents;
}

#if 0
Expand Down