]> granicus.if.org Git - pdns/commitdiff
add beginnings of recursor control channel
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 18 Mar 2006 11:10:53 +0000 (11:10 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 18 Mar 2006 11:10:53 +0000 (11:10 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@593 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/Makefile.am
pdns/dynlistener.cc
pdns/pdns_recursor.cc
pdns/rec_channel.cc [new file with mode: 0644]
pdns/rec_channel.hh [new file with mode: 0644]
pdns/rec_control.cc [new file with mode: 0644]

index be65ea5d318e017cee6ab3db79e69c25974c528b..c4e628c39f5ac7b968727b46de3ce79a24751b3a 100644 (file)
@@ -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
index f339e7c198d42047d5e73392fb0a2fe1bbe72d65..50f7d47644ee962277a8fa9a463e2dc3695d7eaa 100644 (file)
@@ -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 <cstring>
 #include <string>
 #include <map>
index 2dde854b96cb5c618a5c487796a5625eb274d7fb..99383c230d94b75d777b2cc636f5381851f30c47 100644 (file)
@@ -48,8 +48,6 @@
 #include "zoneparser-tng.hh"
 using namespace boost;
 
-
-
 #ifdef __FreeBSD__           // see cvstrac ticket #26
 #include <pthread.h>
 #include <semaphore.h>
diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc
new file mode 100644 (file)
index 0000000..48f087a
--- /dev/null
@@ -0,0 +1,32 @@
+#include "rec_channel.hh"
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <cerrno>
+#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 (file)
index 0000000..c10ae79
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef PDNS_REC_CHANNEL
+#define PDNS_REC_CHANNEL
+#include <string>
+#include <stdint.h>
+
+/** 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 (file)
index 0000000..6f8df37
--- /dev/null
@@ -0,0 +1,3 @@
+int main(int argc, char** argv)
+{
+}