[svn] commit: r3335 - in /branches/vorner-recursor-config/src/bin/recurse: main.cc recursor.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Oct 23 12:17:11 UTC 2010
Author: vorner
Date: Sat Oct 23 12:17:08 2010
New Revision: 3335
Log:
Implement configuring of forward addresses
Modified:
branches/vorner-recursor-config/src/bin/recurse/main.cc
branches/vorner-recursor-config/src/bin/recurse/recursor.cc
Modified: branches/vorner-recursor-config/src/bin/recurse/main.cc
==============================================================================
--- branches/vorner-recursor-config/src/bin/recurse/main.cc (original)
+++ branches/vorner-recursor-config/src/bin/recurse/main.cc Sat Oct 23 12:17:08 2010
@@ -108,11 +108,10 @@
int ch;
const char* port = DNSPORT;
const char* address = NULL;
- const char* forward = NULL;
const char* uid = NULL;
bool use_ipv4 = true, use_ipv6 = true;
- while ((ch = getopt(argc, argv, "46a:f:p:u:v")) != -1) {
+ while ((ch = getopt(argc, argv, "46a:p:u:v")) != -1) {
switch (ch) {
case '4':
// Note that -4 means "ipv4 only", we need to set "use_ipv6" here,
@@ -128,9 +127,6 @@
case 'a':
address = optarg;
break;
- case 'f':
- forward = optarg;
- break;
case 'p':
port = optarg;
break;
@@ -159,11 +155,6 @@
if ((!use_ipv4 || !use_ipv6) && address != NULL) {
cerr << "[b10-auth] Error: Cannot specify -4 or -6 "
<< "at the same time as -a" << endl;
- usage();
- }
-
- if (forward == NULL) {
- cerr << "[b10-recurse] No forward name server specified" << endl;
usage();
}
@@ -181,7 +172,7 @@
specfile = string(RECURSE_SPECFILE_LOCATION);
}
- recursor = new Recursor(*forward);
+ recursor = new Recursor();
recursor->setVerbose(verbose_mode);
cout << "[b10-recurse] Server created." << endl;
@@ -218,7 +209,7 @@
}
recursor->setConfigSession(config_session);
- recursor->updateConfig(ElementPtr());
+ recursor->updateConfig(config_session->getFullConfig());
cout << "[b10-recurse] Server started." << endl;
io_service->run();
Modified: branches/vorner-recursor-config/src/bin/recurse/recursor.cc
==============================================================================
--- branches/vorner-recursor-config/src/bin/recurse/recursor.cc (original)
+++ branches/vorner-recursor-config/src/bin/recurse/recursor.cc Sat Oct 23 12:17:08 2010
@@ -24,6 +24,7 @@
#include <vector>
#include <asiolink/asiolink.h>
+#include <asiolink/ioaddress.h>
#include <boost/foreach.hpp>
@@ -63,9 +64,10 @@
RecursorImpl(const RecursorImpl& source);
RecursorImpl& operator=(const RecursorImpl& source);
public:
- RecursorImpl(const char& forward) :
- config_session_(NULL), verbose_mode_(false),
- forward_(forward), rec_query_()
+ RecursorImpl() :
+ config_session_(NULL),
+ verbose_mode_(false),
+ rec_query_()
{}
~RecursorImpl() {
@@ -73,12 +75,26 @@
}
void querySetup(IOService& ios) {
- rec_query_ = new RecursiveQuery(ios, forward_);
+ rec_query_ = new RecursiveQuery(ios, upstream_);
}
void queryShutdown() {
- if (rec_query_) {
- delete rec_query_;
+ delete rec_query_;
+ rec_query_ = NULL;
+ }
+
+ void setForwardAddresses(const vector<pair<string, uint16_t> >& upstream,
+ IOService* ios)
+ {
+ queryShutdown();
+ upstream_ = upstream;
+ if (ios) {
+ if (upstream_.empty()) {
+ cerr << "[b10-recurse] Asked to do full recursive." << endl <<
+ ", but not implemented yet. I'll do nothing." << endl;
+ } else {
+ querySetup(*ios);
+ }
}
}
@@ -92,10 +108,10 @@
/// These members are public because Recursor accesses them directly.
ModuleCCSession* config_session_;
bool verbose_mode_;
+ /// Addresses of the forward nameserver
+ vector<pair<string, uint16_t> > upstream_;
private:
- /// Address of the forward nameserver
- const char& forward_;
/// Object to handle upstream queries
RecursiveQuery* rec_query_;
@@ -281,8 +297,8 @@
Recursor* server_;
};
-Recursor::Recursor(const char& forward) :
- impl_(new RecursorImpl(forward)),
+Recursor::Recursor() :
+ impl_(new RecursorImpl()),
checkin_(new ConfigCheck(this)),
dns_lookup_(new MessageLookup(this)),
dns_answer_(new MessageAnswer(this))
@@ -432,10 +448,48 @@
}
ConstElementPtr
-Recursor::updateConfig(ConstElementPtr new_config UNUSED_PARAM) {
+Recursor::updateConfig(ConstElementPtr config) {
+ if (impl_->verbose_mode_) {
+ cout << "[b10-recurse] Update with config: " << config->str() << endl;
+ }
try {
- // We will do configuration updates here. None are presently
- // defined, so we just return an empty answer.
+ // Parse forward_addresses
+ vector<pair<string, uint16_t> > addresses;
+ ConstElementPtr forwardAddresses(config->get("forward_addresses"));
+ if (forwardAddresses) {
+ if (forwardAddresses->getType() == Element::list) {
+ for (size_t i(0); i < forwardAddresses->size(); ++ i) {
+ ConstElementPtr addrPair(forwardAddresses->get(i));
+ ConstElementPtr addr(addrPair->get("address"));
+ ConstElementPtr port(addrPair->get("port"));
+ if (!addr || ! port) {
+ isc_throw(BadValue, "Address must contain both the IP"
+ "address and port");
+ }
+ try {
+ IOAddress(addr->stringValue());
+ if (port->intValue() < 0 ||
+ port->intValue() > 0xffff) {
+ isc_throw(BadValue, "Bad port value (" <<
+ port->intValue() << ")");
+ }
+ addresses.push_back(pair<string, uint16_t>(
+ addr->stringValue(), port->intValue()));
+ }
+ catch (const TypeError &e) { // Better error message
+ isc_throw(TypeError,
+ "Address must be a string and port an integer");
+ }
+ }
+ } else if (forwardAddresses->getType() != Element::null) {
+ isc_throw(TypeError,
+ "forward_addresses config element must be a list");
+ }
+ }
+ // Everything OK, so commit the changes
+ if (forwardAddresses) {
+ setForwardAddresses(addresses);
+ }
return (isc::config::createAnswer());
} catch (const isc::Exception& error) {
if (impl_->verbose_mode_) {
@@ -444,3 +498,19 @@
return (isc::config::createAnswer(1, error.what()));
}
}
+
+void
+Recursor::setForwardAddresses(const vector<pair<string, uint16_t> >&
+ addresses)
+{
+ impl_->setForwardAddresses(addresses, io_);
+}
+
+bool
+Recursor::isForwarding() const {
+ return (!impl_->upstream_.empty());
+}
+
+vector<pair<string, uint16_t> > Recursor::getForwardAddresses() const {
+ return (impl_->upstream_);
+}
More information about the bind10-changes
mailing list