[svn] commit: r1884 - in /branches/trac167/src/bin: auth/main.cc bind10/bind10.py.in
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 20 22:40:32 UTC 2010
Author: each
Date: Thu May 20 22:40:31 2010
New Revision: 1884
Log:
Added '-a ADDRESS' options to bind10 and b10-auth, to specify an address
to listen on;.
Modified:
branches/trac167/src/bin/auth/main.cc
branches/trac167/src/bin/bind10/bind10.py.in
Modified: branches/trac167/src/bin/auth/main.cc
==============================================================================
--- branches/trac167/src/bin/auth/main.cc (original)
+++ branches/trac167/src/bin/auth/main.cc Thu May 20 22:40:31 2010
@@ -256,6 +256,21 @@
listening_, placeholders::error));
}
+ TCPServer(io_service& io_service, asio::ip::address addr, short port) :
+ io_service_(io_service), acceptor_(io_service_),
+ listening_(new TCPClient(io_service_))
+ {
+ tcp::endpoint endpoint(addr, port);
+ acceptor_.open(endpoint.protocol());
+
+ acceptor_.set_option(tcp::acceptor::reuse_address(true));
+ acceptor_.bind(endpoint);
+ acceptor_.listen();
+ acceptor_.async_accept(listening_->getSocket(),
+ boost::bind(&TCPServer::handleAccept, this,
+ listening_, placeholders::error));
+ }
+
~TCPServer() { delete listening_; }
void handleAccept(TCPClient* new_client,
@@ -297,6 +312,17 @@
} else {
socket_.bind(udp::endpoint(udp::v4(), port));
}
+ startReceive();
+ }
+
+ UDPServer(io_service& io_service, asio::ip::address addr, short port) :
+ io_service_(io_service),
+ socket_(io_service, addr.is_v6() ? udp::v6() : udp::v4()),
+ response_buffer_(0),
+ response_renderer_(response_buffer_),
+ dns_message_(Message::PARSE)
+ {
+ socket_.bind(udp::endpoint(addr, port));
startReceive();
}
@@ -370,19 +396,39 @@
};
void
-run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
+run_server(const char* address, const char* port,
+ const bool use_ipv4, const bool use_ipv6,
AuthSrv* srv UNUSED_PARAM)
{
ServerSet servers;
short portnum = atoi(port);
-
- if (use_ipv4) {
- servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum);
- servers.tcp4_server = new TCPServer(io_service_, AF_INET, portnum);
- }
- if (use_ipv6) {
- servers.udp6_server = new UDPServer(io_service_, AF_INET6, portnum);
- servers.tcp6_server = new TCPServer(io_service_, AF_INET6, portnum);
+ asio::ip::address addr;
+
+ if (address != NULL) {
+ addr = asio::ip::address::from_string(address);
+ if ((addr.is_v6() && !use_ipv6)) {
+ cout << "[b10-auth] Error: -4 conflicts with " << addr << endl;
+ exit(1);
+ }
+
+ if ((addr.is_v4() && !use_ipv4)) {
+ cout << "[b10-auth] Error: -6 conflicts with " << addr << endl;
+ exit(1);
+ }
+ }
+
+ if (address) {
+ servers.udp4_server = new UDPServer(io_service_, addr, portnum);
+ servers.tcp4_server = new TCPServer(io_service_, addr, portnum);
+ } else {
+ if (use_ipv4) {
+ servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum);
+ servers.tcp4_server = new TCPServer(io_service_, AF_INET, portnum);
+ }
+ if (use_ipv6) {
+ servers.udp6_server = new UDPServer(io_service_, AF_INET6, portnum);
+ servers.tcp6_server = new TCPServer(io_service_, AF_INET6, portnum);
+ }
}
cout << "Server started." << endl;
@@ -391,7 +437,7 @@
void
usage() {
- cerr << "Usage: b10-auth [-p port] [-4|-6]" << endl;
+ cerr << "Usage: b10-auth [-a address] [-p port] [-4|-6]" << endl;
exit(1);
}
} // end of anonymous namespace
@@ -400,9 +446,10 @@
main(int argc, char* argv[]) {
int ch;
const char* port = DNSPORT;
+ const char* address = NULL;
bool use_ipv4 = true, use_ipv6 = true;
- while ((ch = getopt(argc, argv, "46p:v")) != -1) {
+ while ((ch = getopt(argc, argv, "46a:p:v")) != -1) {
switch (ch) {
case '4':
// Note that -4 means "ipv4 only", we need to set "use_ipv6" here,
@@ -413,7 +460,11 @@
break;
case '6':
// The same note as -4 applies.
+cout << "here" << endl;
use_ipv4 = false;
+ break;
+ case 'a':
+ address = optarg;
break;
case 'p':
port = optarg;
@@ -455,7 +506,7 @@
auth_server->setConfigSession(&cs);
auth_server->updateConfig(ElementPtr());
- run_server(port, use_ipv4, use_ipv6, auth_server);
+ run_server(address, port, use_ipv4, use_ipv6, auth_server);
} catch (const std::exception& ex) {
cerr << ex.what() << endl;
ret = 1;
Modified: branches/trac167/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/trac167/src/bin/bind10/bind10.py.in (original)
+++ branches/trac167/src/bin/bind10/bind10.py.in Thu May 20 22:40:31 2010
@@ -58,6 +58,7 @@
import time
import select
import random
+import socket
from optparse import OptionParser, OptionValueError
import isc.cc
@@ -156,9 +157,33 @@
def respawn(self):
self._spawn()
+class IPAddr:
+ """Stores an IPv4 or IPv6 address."""
+ family = None
+ addr = None
+
+ def __init__(self, addr):
+ try:
+ f = socket.AF_INET
+ a = socket.inet_pton(f, addr)
+ except socket.error:
+ try:
+ f = socket.AF_INET6
+ a = socket.inet_pton(f, addr)
+ except socket.error as se:
+ raise se
+ except Exception as e:
+ print(str(e))
+
+ self.family = f
+ self.addr = a
+
+ def __str__(self):
+ return socket.inet_ntop(self.family, self.addr)
+
class BoB:
"""Boss of BIND class."""
- def __init__(self, c_channel_port=9912, auth_port=5300, verbose=False):
+ def __init__(self, c_channel_port=9912, auth_port=5300, address='', verbose=False):
"""Initialize the Boss of BIND. This is a singleton (only one
can run).
@@ -169,6 +194,9 @@
self.verbose = verbose
self.c_channel_port = c_channel_port
self.auth_port = auth_port
+ self.address = None
+ if address:
+ self.address = IPAddr(address)
self.cc_session = None
self.ccs = None
self.processes = {}
@@ -302,10 +330,15 @@
# start b10-auth
# XXX: this must be read from the configuration manager in the future
authargs = ['b10-auth', '-p', str(self.auth_port)]
- if self.verbose:
- sys.stdout.write("Starting b10-auth using port %d\n" %
+ if self.address:
+ authargs += ['-a', str(self.address)]
+ if self.verbose:
+ authargs += ['-v']
+ sys.stdout.write("Starting b10-auth using port %d" %
self.auth_port)
- authargs += ['-v']
+ if self.address:
+ sys.stdout.write(" on %s" % str(self.address))
+ sys.stdout.write("\n")
try:
auth = ProcessInfo("b10-auth", authargs,
{ 'ISC_MSGQ_PORT': str(self.c_channel_port)})
@@ -572,6 +605,18 @@
else:
raise OptionValueError("Unknown option " + opt_str)
+def check_addr(option, opt_str, value, parser):
+ """Function to insure that the address we are passed is actually
+ a valid address. Used by OptionParser() on startup."""
+ try:
+ IPAddr(value)
+ except:
+ raise OptionValueError("%s requires a valid IPv4 or IPv6 address" % opt_str)
+ if (opt_str == '-a' or opt_str == '--address'):
+ parser.values.address = value
+ else:
+ raise OptionValueError("Unknown option " + opt_str)
+
def main():
global options
global boss_of_bind
@@ -579,6 +624,9 @@
parser = OptionParser(version=__version__)
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
+ parser.add_option("-a", "--address", dest="address", type="string",
+ action="callback", callback=check_addr, default='',
+ help="address the b10-auth daemon will use (default: listen on all addresses)")
parser.add_option("-p", "--port", dest="auth_port", type="string",
action="callback", callback=check_port, default="5300",
help="port the b10-auth daemon will use (default 5300)")
@@ -608,7 +656,7 @@
# Go bob!
boss_of_bind = BoB(int(options.msgq_port), int(options.auth_port),
- options.verbose)
+ options.address, options.verbose)
startup_result = boss_of_bind.startup()
if startup_result:
sys.stderr.write("Error on startup: %s\n" % startup_result)
More information about the bind10-changes
mailing list