Commit d6d7f115 authored by Scott Mann's avatar Scott Mann
Browse files

put root server ip list into recursive query object

parent ce2fead0
......@@ -76,7 +76,7 @@ public:
void querySetup(DNSService& dnss) {
assert(!rec_query_); // queryShutdown must be called first
dlog("Query setup");
rec_query_ = new RecursiveQuery(dnss, upstream_);
rec_query_ = new RecursiveQuery(dnss, upstream_,upstream_root_);
}
void queryShutdown() {
......@@ -110,8 +110,8 @@ public:
queryShutdown();
upstream_root_ = upstream_root;
if (dnss) {
if (!upstream_.empty()) {
dlog("Setting forward addresses:");
if (!upstream_root_.empty()) {
dlog("Setting root addresses:");
BOOST_FOREACH(const addr_t& address, upstream_root) {
dlog(" " + address.first + ":" +
boost::lexical_cast<string>(address.second));
......@@ -457,6 +457,7 @@ parseAddresses(ConstElementPtr addresses) {
}
result.push_back(addr_t(addr->stringValue(),
port->intValue()));
dlog("[Resolver] tmpDebug: Adding " + addr->stringValue() + "\n");
}
catch (const TypeError &e) { // Better error message
isc_throw(TypeError,
......@@ -465,7 +466,7 @@ parseAddresses(ConstElementPtr addresses) {
}
} else if (addresses->getType() != Element::null) {
isc_throw(TypeError,
"forward_addresses config element must be a list");
"root_addresses, forward_addresses, and listen_on config element must be a list");
}
}
return (result);
......
......@@ -41,6 +41,32 @@
]
}
},
{
"item_name": "root_addresses",
"item_type": "list",
"item_optional": True,
"item_default": [],
"list_item_spec" : {
"item_name": "address",
"item_type": "map",
"item_optional": False,
"item_default": {},
"map_item_spec": [
{
"item_name": "address",
"item_type": "string",
"item_optional": False,
"item_default": "::1"
},
{
"item_name": "port",
"item_type": "integer",
"item_optional": False,
"item_default": 53
}
]
}
},
{
"item_name": "listen_on",
"item_type": "list",
......
......@@ -27,6 +27,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
......@@ -287,8 +288,11 @@ typedef std::vector<std::pair<std::string, uint16_t> > AddressVector;
}
RecursiveQuery::RecursiveQuery(DNSService& dns_service,
const AddressVector& upstream, int timeout, unsigned retries) :
const AddressVector& upstream,
const AddressVector& upstream_root,
int timeout, unsigned retries) :
dns_service_(dns_service), upstream_(new AddressVector(upstream)),
upstream_root_(new AddressVector(upstream_root)),
timeout_(timeout), retries_(retries)
{}
......@@ -348,6 +352,9 @@ private:
// we should differentiate between forwarding and resolving
shared_ptr<AddressVector> upstream_;
// root servers...just copied over to the zone_servers_
shared_ptr<AddressVector> upstream_root_;
// Buffer to store the result.
OutputBufferPtr buffer_;
......@@ -472,12 +479,14 @@ private:
public:
RunningQuery(asio::io_service& io, const Question &question,
MessagePtr answer_message, shared_ptr<AddressVector> upstream,
shared_ptr<AddressVector> upstream_root,
OutputBufferPtr buffer, DNSServer* server, int timeout,
unsigned retries) :
io_(io),
question_(question),
answer_message_(answer_message),
upstream_(upstream),
upstream_root_(upstream_root),
buffer_(buffer),
server_(server->clone()),
timeout_(timeout),
......@@ -487,9 +496,28 @@ public:
dlog("Started a new RunningQuery");
done = false;
// hardcoded f.root-servers.net now, should use NSAS
// should use NSAS for root servers
// Adding root servers if not a forwarder
if (upstream_->empty()) {
zone_servers_.push_back(addr_t("192.5.5.241", 53));
dlog("====checking upstream_root_");
if (upstream_root_->empty()) { //if no root ips given, use this
zone_servers_.push_back(addr_t("192.5.5.241", 53));
}
else
{
//copy the list (would be faster to just point, but that
//should be done in NSAS, I think...)
zone_servers_.push_back(addr_t("192.5.5.241", 53));
//BOOST_FOREACH(addr_t& address, upstream_root);
//{
// zone_servers_.push_back(address);
dlog("Found root server ");
/* + \
boost::lexical_cast<string>(upstream_root_->size()) + \
"\n");
*/
//}
}
}
send();
}
......@@ -542,8 +570,8 @@ RecursiveQuery::sendQuery(const Question& question,
// we're only going to handle UDP.
asio::io_service& io = dns_service_.get_io_service();
// It will delete itself when it is done
new RunningQuery(io, question, answer_message, upstream_, buffer,
server, timeout_, retries_);
new RunningQuery(io, question, answer_message, upstream_, upstream_root_,
buffer, server, timeout_, retries_);
}
class IntervalTimerImpl {
......
......@@ -540,6 +540,8 @@ public:
/// query on.
/// \param upstream Addresses and ports of the upstream servers
/// to forward queries to.
/// \param upstream_root Addresses and ports of the root servers
/// to forward queries to.
/// \param timeout How long to timeout the query, in ms
/// -1 means never timeout (but do not use that).
/// TODO: This should be computed somehow dynamically in future
......@@ -547,7 +549,10 @@ public:
/// and return if it returs).
RecursiveQuery(DNSService& dns_service,
const std::vector<std::pair<std::string, uint16_t> >&
upstream, int timeout = -1, unsigned retries = 0);
upstream,
const std::vector<std::pair<std::string, uint16_t> >&
upstream_root,
int timeout = -1, unsigned retries = 0);
//@}
/// \brief Initiates an upstream query in the \c RecursiveQuery object.
......@@ -568,6 +573,8 @@ private:
DNSService& dns_service_;
boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
upstream_;
boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
upstream_root_;
int timeout_;
unsigned retries_;
};
......
......@@ -647,15 +647,15 @@ singleAddress(const string &address, uint16_t port) {
TEST_F(ASIOLinkTest, recursiveSetupV4) {
setDNSService(true, false);
uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
EXPECT_NO_THROW(RecursiveQuery(*dns_service_, singleAddress(TEST_IPV6_ADDR,
port)));
EXPECT_NO_THROW(RecursiveQuery(*dns_service_, singleAddress(TEST_IPV4_ADDR,
port),singleAddress(TEST_IPV4_ADDR,port)));
}
TEST_F(ASIOLinkTest, recursiveSetupV6) {
setDNSService(false, true);
uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
EXPECT_NO_THROW(RecursiveQuery(*dns_service_, singleAddress(TEST_IPV6_ADDR,
port)));
port),singleAddress(TEST_IPV6_ADDR,port)));
}
// XXX:
......@@ -671,7 +671,8 @@ TEST_F(ASIOLinkTest, forwarderSend) {
uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
MockServer server(*io_service_);
RecursiveQuery rq(*dns_service_, singleAddress(TEST_IPV4_ADDR, port));
RecursiveQuery rq(*dns_service_, singleAddress(TEST_IPV4_ADDR, port),
singleAddress(TEST_IPV4_ADDR, port));
Question q(Name("example.com"), RRClass::IN(), RRType::TXT());
OutputBufferPtr buffer(new OutputBuffer(0));
......@@ -718,7 +719,7 @@ TEST_F(ASIOLinkTest, recursiveTimeout) {
// Do the answer
const uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
RecursiveQuery query(*dns_service_, singleAddress(TEST_IPV4_ADDR, port),
10, 2);
singleAddress(TEST_IPV4_ADDR, port),10, 2);
Question question(Name("example.net"), RRClass::IN(), RRType::A());
OutputBufferPtr buffer(new OutputBuffer(0));
MessagePtr answer(new Message(Message::RENDER));
......@@ -762,7 +763,7 @@ TEST_F(ASIOLinkTest, recursiveSendOk) {
MockServerStop server(*io_service_, &done);
vector<pair<string, uint16_t> > empty_vector;
RecursiveQuery rq(*dns_service_, empty_vector, 10000, 0);
RecursiveQuery rq(*dns_service_, empty_vector, empty_vector, 10000, 0);
Question q(Name("www.isc.org"), RRClass::IN(), RRType::A());
OutputBufferPtr buffer(new OutputBuffer(0));
......@@ -787,7 +788,7 @@ TEST_F(ASIOLinkTest, recursiveSendNXDOMAIN) {
MockServerStop server(*io_service_, &done);
vector<pair<string, uint16_t> > empty_vector;
RecursiveQuery rq(*dns_service_, empty_vector, 10000, 0);
RecursiveQuery rq(*dns_service_, empty_vector, empty_vector, 10000, 0);
Question q(Name("wwwdoesnotexist.isc.org"), RRClass::IN(), RRType::A());
OutputBufferPtr buffer(new OutputBuffer(0));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment