From f6f016d119d246825e7a1a44a968c1b19937689c Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Sat, 18 Mar 2006 11:10:53 +0000 Subject: [PATCH] add beginnings of recursor control channel git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@593 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/Makefile.am | 8 ++++++-- pdns/dynlistener.cc | 9 +++------ pdns/pdns_recursor.cc | 2 -- pdns/rec_channel.cc | 32 ++++++++++++++++++++++++++++++++ pdns/rec_channel.hh | 18 ++++++++++++++++++ pdns/rec_control.cc | 3 +++ 6 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 pdns/rec_channel.cc create mode 100644 pdns/rec_channel.hh create mode 100644 pdns/rec_control.cc diff --git a/pdns/Makefile.am b/pdns/Makefile.am index be65ea5d3..c4e628c39 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -12,11 +12,13 @@ sysconf_DATA = pdns.conf-dist if RECURSOR sbin_PROGRAMS = pdns_server pdns_recursor +bin_PROGRAMS = pdns_control rec_control else sbin_PROGRAMS = pdns_server +bin_PROGRAMS = pdns_control endif -bin_PROGRAMS = pdns_control + EXTRA_PROGRAMS=pdns_recursor sdig dnspbench pdns_control qgen dnsscope dnsreplay_mindex dnswasher dnsreplay @@ -87,11 +89,13 @@ dnsscope_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ # INCLUDES=-I/usr/include/mysql +rec_control_SOURCES=rec_channel.cc rec_channel.hh rec_control.cc + pdns_recursor_SOURCES=syncres.cc resolver.hh misc.cc unix_utility.cc qtype.cc \ logger.cc statbag.cc dnspacket.cc arguments.cc lwres.cc pdns_recursor.cc lwres.hh \ mtasker.hh sillyrecords.cc syncres.hh recursor_cache.cc recursor_cache.hh dnsparser.cc \ dnswriter.cc dnswriter.hh dnsrecords.cc dnsrecords.hh rcpgenerator.cc rcpgenerator.hh \ -base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh +base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh rec_channel.cc rec_channel.hh if NEDMALLOC pdns_recursor_SOURCES += ext/nedmalloc/malloc.c diff --git a/pdns/dynlistener.cc b/pdns/dynlistener.cc index f339e7c19..50f7d4764 100644 --- a/pdns/dynlistener.cc +++ b/pdns/dynlistener.cc @@ -1,11 +1,10 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 PowerDNS.COM BV + Copyright (C) 2002 - 2006 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,8 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id$ -/* (C) Copyright 2002 PowerDNS.COM BV */ #include #include #include diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2dde854b9..99383c230 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -48,8 +48,6 @@ #include "zoneparser-tng.hh" using namespace boost; - - #ifdef __FreeBSD__ // see cvstrac ticket #26 #include #include diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc new file mode 100644 index 000000000..48f087a8c --- /dev/null +++ b/pdns/rec_channel.cc @@ -0,0 +1,32 @@ +#include "rec_channel.hh" +#include +#include +#include +#include "ahuexception.hh" + +using namespace std; + +int RecursorControlChannel::listen(const string& fname) +{ + struct sockaddr_un local; + d_fd=socket(AF_UNIX,SOCK_DGRAM,0); + + if(d_fd < 0) + throw AhuException("Creating UNIX domain socket: "+string(strerror(errno))); + + int tmp=1; + if(setsockopt(d_fd, SOL_SOCKET, SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) + throw AhuException(string("Setsockopt failed: ")+strerror(errno)); + + int err=unlink(fname.c_str()); + if(err < 0 && errno!=ENOENT) + throw AhuException("Unable to remove (previous) controlsocket: "+string(strerror(errno))); + + memset(&local,0,sizeof(local)); + local.sun_family=AF_UNIX; + strcpy(local.sun_path, fname.c_str()); + + if(bind(d_fd, (sockaddr*)&local,sizeof(local))<0) + throw AhuException("Unable to bind to controlsocket: "+string(strerror(errno))); + +} diff --git a/pdns/rec_channel.hh b/pdns/rec_channel.hh new file mode 100644 index 000000000..c10ae79fd --- /dev/null +++ b/pdns/rec_channel.hh @@ -0,0 +1,18 @@ +#ifndef PDNS_REC_CHANNEL +#define PDNS_REC_CHANNEL +#include +#include + +/** this class is used both to send and answer channel commands to the PowerDNS Recursor */ +class RecursorControlChannel +{ +public: + int listen(const std::string& filename); + void connect(const std::string& filename); + + uint64_t getStat(const std::string& name); +private: + int d_fd; +}; + +#endif diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc new file mode 100644 index 000000000..6f8df379b --- /dev/null +++ b/pdns/rec_control.cc @@ -0,0 +1,3 @@ +int main(int argc, char** argv) +{ +} -- 2.49.0