]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: allow setting server IP with -c
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 24 Feb 2016 13:20:01 +0000 (14:20 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 24 Feb 2016 14:23:05 +0000 (15:23 +0100)
This will allow you to connect to any dnsdist server by setting the IP
on the commandline

docs/manpages/dnsdist.1.md
pdns/dnsdist.cc

index 003e81c86cf332b3b8b2fa1bed49c0662f8a577b..fb74fab6a2cc6bc5f5daade981761150f82127fd 100644 (file)
@@ -52,8 +52,10 @@ Server for example is often mentioned.
      for errors. dnsdist will show the errors and exit with a non-zero exit-code
      when errors are found.
 
--c,--client
-:    Operate as a client, connect to dnsdist.
+-c,--client [*ADDRESS*[:*PORT*]]
+:    Operate as a client, connect to dnsdist. This will read the dnsdist configuration
+     for the **controlSocket** statement and connect to it. When *ADDRESS* (with
+     optional *PORT*) is set, dnsdist will connect to that instead.
 
 -d,--daemon
 :    Operate as a daemon.
index 7f588b7b0eee0dcd239a38c532313b9c8fd0ac4f..0b2a73cb5067bb39416df485a5dd7088880e99ad 100644 (file)
@@ -1199,6 +1199,7 @@ try
   }
   
 #endif
+  ComboAddress clientAddress = ComboAddress();
   g_cmdLine.config=SYSCONFDIR "/dnsdist.conf";
   struct option longopts[]={ 
     {"acl", required_argument, 0, 'a'},
@@ -1245,13 +1246,15 @@ try
     case 'h':
       cout<<"dnsdist "<<VERSION<<endl;
       cout<<endl;
-      cout<<"Syntax: dnsdist [-C,--config file] [-c,--client] [-d,--daemon]\n";
+      cout<<"Syntax: dnsdist [-C,--config file] [-c,--client [IP[:PORT]]] [-d,--daemon]\n";
       cout<<"[-p,--pidfile file] [-e,--execute cmd] [-h,--help] [-l,--local addr]\n";
       cout<<"[-v,--verbose]\n";
       cout<<"\n";
       cout<<"-a,--acl netmask      Add this netmask to the ACL\n";
       cout<<"-C,--config file      Load configuration from 'file'\n";
-      cout<<"-c,--client           Operate as a client, connect to dnsdist\n";
+      cout<<"-c,--client           Operate as a client, connect to dnsdist. This reads\n";
+      cout<<"                      controlSocket from your configuration file, but also\n";
+      cout<<"                      accepts an IP:PORT argument\n";
       cout<<"-d,--daemon           Operate as a daemon\n";
       cout<<"-e,--execute cmd      Connect to dnsdist and execute 'cmd'\n";
       cout<<"-g,--gid gid          Change the process group ID after binding sockets\n";
@@ -1293,7 +1296,11 @@ try
   argc-=optind;
   argv+=optind;
   for(auto p = argv; *p; ++p) {
-    g_cmdLine.remotes.push_back(*p);
+    if(g_cmdLine.beClient) {
+      clientAddress = ComboAddress(*p, 5199);
+    } else {
+      g_cmdLine.remotes.push_back(*p);
+    }
   }
 
   g_maxOutstanding = 1024;
@@ -1303,6 +1310,8 @@ try
   g_policy.setState(leastOutstandingPol);
   if(g_cmdLine.beClient || !g_cmdLine.command.empty()) {
     setupLua(true, g_cmdLine.config);
+    if (clientAddress != ComboAddress())
+      g_serverControl = clientAddress;
     doClient(g_serverControl, g_cmdLine.command);
     _exit(EXIT_SUCCESS);
   }