Commit e3fac0c7 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

merged trac #358 (various cleanups to the DNS message class)

(svn merge didn't work well, probably because the branch was too old, so I chose to apply the diff by hand)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@3439 e5f2f494-b856-4b98-b285-d166d9295462
parent 9b271698
......@@ -152,8 +152,8 @@ makeErrorMessage(Message& message, MessageRenderer& renderer,
// XXX: with the current implementation, it's not easy to set EDNS0
// depending on whether the query had it. So we'll simply omit it.
const qid_t qid = message.getQid();
const bool rd = message.getHeaderFlag(MessageFlag::RD());
const bool cd = message.getHeaderFlag(MessageFlag::CD());
const bool rd = message.getHeaderFlag(Message::HEADERFLAG_RD);
const bool cd = message.getHeaderFlag(Message::HEADERFLAG_CD);
const Opcode& opcode = message.getOpcode();
vector<QuestionPtr> questions;
......@@ -166,12 +166,12 @@ makeErrorMessage(Message& message, MessageRenderer& renderer,
message.clear(Message::RENDER);
message.setQid(qid);
message.setOpcode(opcode);
message.setHeaderFlag(MessageFlag::QR());
message.setHeaderFlag(Message::HEADERFLAG_QR);
if (rd) {
message.setHeaderFlag(MessageFlag::RD());
message.setHeaderFlag(Message::HEADERFLAG_RD);
}
if (cd) {
message.setHeaderFlag(MessageFlag::CD());
message.setHeaderFlag(Message::HEADERFLAG_CD);
}
for_each(questions.begin(), questions.end(), QuestionInserter(&message));
message.setRcode(rcode);
......@@ -231,7 +231,7 @@ AuthSrv::processMessage(const IOMessage& io_message, Message& message,
message.parseHeader(request_buffer);
// Ignore all responses.
if (message.getHeaderFlag(MessageFlag::QR())) {
if (message.getHeaderFlag(Message::HEADERFLAG_QR)) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] received unexpected response, ignoring"
<< endl;
......@@ -279,7 +279,7 @@ AuthSrv::processMessage(const IOMessage& io_message, Message& message,
return (true);
}
if (message.getRRCount(Section::QUESTION()) != 1) {
if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
impl_->verbose_mode_);
return (true);
......@@ -310,7 +310,7 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
Message::DEFAULT_MAX_UDPSIZE;
message.makeResponse();
message.setHeaderFlag(MessageFlag::AA());
message.setHeaderFlag(Message::HEADERFLAG_AA);
message.setRcode(Rcode::NOERROR());
if (remote_edns) {
......@@ -397,10 +397,10 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
{
// The incoming notify must contain exactly one question for SOA of the
// zone name.
if (message.getRRCount(Section::QUESTION()) != 1) {
if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
if (verbose_mode_) {
cerr << "[b10-auth] invalid number of questions in notify: "
<< message.getRRCount(Section::QUESTION()) << endl;
<< message.getRRCount(Message::SECTION_QUESTION) << endl;
}
makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
verbose_mode_);
......@@ -472,7 +472,7 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
}
message.makeResponse();
message.setHeaderFlag(MessageFlag::AA());
message.setHeaderFlag(Message::HEADERFLAG_AA);
message.setRcode(Rcode::NOERROR());
message.toWire(response_renderer);
return (true);
......
......@@ -321,18 +321,25 @@ headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
EXPECT_EQ(qid, message.getQid());
EXPECT_EQ(rcode, message.getRcode());
EXPECT_EQ(opcodeval, message.getOpcode().getCode());
EXPECT_EQ((flags & QR_FLAG) != 0, message.getHeaderFlag(MessageFlag::QR()));
EXPECT_EQ((flags & AA_FLAG) != 0, message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ((flags & TC_FLAG) != 0, message.getHeaderFlag(MessageFlag::TC()));
EXPECT_EQ((flags & RA_FLAG) != 0, message.getHeaderFlag(MessageFlag::RA()));
EXPECT_EQ((flags & RD_FLAG) != 0, message.getHeaderFlag(MessageFlag::RD()));
EXPECT_EQ((flags & AD_FLAG) != 0, message.getHeaderFlag(MessageFlag::AD()));
EXPECT_EQ((flags & CD_FLAG) != 0, message.getHeaderFlag(MessageFlag::CD()));
EXPECT_EQ(qdcount, message.getRRCount(Section::QUESTION()));
EXPECT_EQ(ancount, message.getRRCount(Section::ANSWER()));
EXPECT_EQ(nscount, message.getRRCount(Section::AUTHORITY()));
EXPECT_EQ(arcount, message.getRRCount(Section::ADDITIONAL()));
EXPECT_EQ((flags & QR_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_QR));
EXPECT_EQ((flags & AA_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_AA));
EXPECT_EQ((flags & TC_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_TC));
EXPECT_EQ((flags & RA_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_RA));
EXPECT_EQ((flags & RD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_RD));
EXPECT_EQ((flags & AD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_AD));
EXPECT_EQ((flags & CD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_CD));
EXPECT_EQ(qdcount, message.getRRCount(Message::SECTION_QUESTION));
EXPECT_EQ(ancount, message.getRRCount(Message::SECTION_ANSWER));
EXPECT_EQ(nscount, message.getRRCount(Message::SECTION_AUTHORITY));
EXPECT_EQ(arcount, message.getRRCount(Message::SECTION_ADDITIONAL));
}
// Unsupported requests. Should result in NOTIMP.
......@@ -540,7 +547,7 @@ TEST_F(AuthSrvTest, AXFRDisconnectFail) {
TEST_F(AuthSrvTest, notify) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -572,7 +579,7 @@ TEST_F(AuthSrvTest, notifyForCHClass) {
// Same as the previous test, but for the CH RRClass.
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::CH(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -588,7 +595,7 @@ TEST_F(AuthSrvTest, notifyEmptyQuestion) {
request_message.clear(Message::RENDER);
request_message.setOpcode(Opcode::NOTIFY());
request_message.setRcode(Rcode::NOERROR());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setQid(default_qid);
request_message.toWire(request_renderer);
createRequestPacket(IPPROTO_UDP);
......@@ -604,7 +611,7 @@ TEST_F(AuthSrvTest, notifyMultiQuestions) {
// add one more SOA question
request_message.addQuestion(Question(Name("example.com"), RRClass::IN(),
RRType::SOA()));
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -615,7 +622,7 @@ TEST_F(AuthSrvTest, notifyMultiQuestions) {
TEST_F(AuthSrvTest, notifyNonSOAQuestion) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::NS());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -636,7 +643,7 @@ TEST_F(AuthSrvTest, notifyWithoutAA) {
TEST_F(AuthSrvTest, notifyWithErrorRcode) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setRcode(Rcode::SERVFAIL());
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
......@@ -650,7 +657,7 @@ TEST_F(AuthSrvTest, notifyWithoutSession) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
// we simply ignore the notify and let it be resent if an internal error
......@@ -664,7 +671,7 @@ TEST_F(AuthSrvTest, notifySendFail) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
......@@ -676,7 +683,7 @@ TEST_F(AuthSrvTest, notifyReceiveFail) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -687,7 +694,7 @@ TEST_F(AuthSrvTest, notifyWithBogusSessionMessage) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -699,7 +706,7 @@ TEST_F(AuthSrvTest, notifyWithSessionMessageError) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......
......@@ -58,7 +58,7 @@ host_lookup(const char* const name, const char* const type) {
msg.setOpcode(Opcode::QUERY());
msg.setRcode(Rcode::NOERROR());
if (recursive_bit) {
msg.setHeaderFlag(MessageFlag::RD()); // set recursive bit
msg.setHeaderFlag(Message::HEADERFLAG_RD); // set recursive bit
}
msg.addQuestion(Question(Name(name),
......@@ -122,9 +122,10 @@ host_lookup(const char* const name, const char* const type) {
rmsg.fromWire(ibuffer);
if (!verbose) {
for (RRsetIterator it = rmsg.beginSection(Section::ANSWER());
it != rmsg.endSection(Section::ANSWER());
++it) {
for (RRsetIterator it =
rmsg.beginSection(Message::SECTION_ANSWER);
it != rmsg.endSection(Message::SECTION_ANSWER);
++it) {
if ((*it)->getType() != RRType::A()) {
continue;
}
......
......@@ -135,9 +135,9 @@ class MockXfrinConnection(XfrinConnection):
resp.set_opcode(Opcode.QUERY())
resp.set_rcode(rcode)
if response:
resp.set_header_flag(MessageFlag.QR())
resp.set_header_flag(Message.HEADERFLAG_QR)
[resp.add_question(q) for q in questions]
[resp.add_rrset(Section.ANSWER(), a) for a in answers]
[resp.add_rrset(Message.SECTION_ANSWER, a) for a in answers]
renderer = MessageRenderer()
resp.to_wire(renderer)
......
......@@ -240,7 +240,7 @@ class XfrinConnection(asyncore.dispatcher):
if msg_rcode != Rcode.NOERROR():
raise XfrinException('error response: %s' % msg_rcode.to_text())
if not msg.get_header_flag(MessageFlag.QR()):
if not msg.get_header_flag(Message.HEADERFLAG_QR):
raise XfrinException('response is not a response ')
if msg.get_qid() != self._query_id:
......@@ -251,10 +251,10 @@ class XfrinConnection(asyncore.dispatcher):
self._check_response_header(msg)
if msg.get_rr_count(Section.ANSWER()) == 0:
if msg.get_rr_count(Message.SECTION_ANSWER) == 0:
raise XfrinException('answer section is empty')
if msg.get_rr_count(Section.QUESTION()) > 1:
if msg.get_rr_count(Message.SECTION_QUESTION) > 1:
raise XfrinException('query section count greater than 1')
def _handle_answer_section(self, answer_section):
......@@ -294,7 +294,7 @@ class XfrinConnection(asyncore.dispatcher):
msg.from_wire(recvdata)
self._check_response_status(msg)
answer_section = msg.get_section(Section.ANSWER())
answer_section = msg.get_section(Message.SECTION_ANSWER)
for rr in self._handle_answer_section(answer_section):
yield rr
......
......@@ -115,7 +115,7 @@ class TestXfroutSession(unittest.TestCase):
self.assertEqual(msg.get_qid(), qid)
self.assertEqual(msg.get_opcode(), opcode)
self.assertEqual(msg.get_rcode(), rcode)
self.assertTrue(msg.get_header_flag(MessageFlag.AA()))
self.assertTrue(msg.get_header_flag(Message.HEADERFLAG_AA))
def test_reply_query_with_format_error(self):
......@@ -140,12 +140,12 @@ class TestXfroutSession(unittest.TestCase):
self.xfrsess._send_message_with_last_soa(msg, self.sock, rrset_soa, 0)
get_msg = self.sock.read_msg()
self.assertEqual(get_msg.get_rr_count(Section.QUESTION()), 1)
self.assertEqual(get_msg.get_rr_count(Section.ANSWER()), 1)
self.assertEqual(get_msg.get_rr_count(Section.AUTHORITY()), 0)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
#answer_rrset_iter = section_iter(get_msg, section.ANSWER())
answer = get_msg.get_section(Section.ANSWER())[0]#answer_rrset_iter.get_rrset()
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]#answer_rrset_iter.get_rrset()
self.assertEqual(answer.get_name().to_text(), "example.com.")
self.assertEqual(answer.get_class(), RRClass("IN"))
self.assertEqual(answer.get_type().to_text(), "SOA")
......@@ -160,7 +160,7 @@ class TestXfroutSession(unittest.TestCase):
msg = self.getmsg()
msg.make_response()
msg.add_rrset(Section.ANSWER(), rrset_a)
msg.add_rrset(Message.SECTION_ANSWER, rrset_a)
# give the function a value that is larger than MAX-len(rrset)
self.xfrsess._send_message_with_last_soa(msg, self.sock, rrset_soa, 65520)
......@@ -168,11 +168,11 @@ class TestXfroutSession(unittest.TestCase):
# (1 with the rrset we added manually, and 1 that triggered
# the sending in _with_last_soa)
get_msg = self.sock.read_msg()
self.assertEqual(get_msg.get_rr_count(Section.QUESTION()), 1)
self.assertEqual(get_msg.get_rr_count(Section.ANSWER()), 1)
self.assertEqual(get_msg.get_rr_count(Section.AUTHORITY()), 0)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
answer = get_msg.get_section(Section.ANSWER())[0]
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
self.assertEqual(answer.get_name().to_text(), "example.com.")
self.assertEqual(answer.get_class(), RRClass("IN"))
self.assertEqual(answer.get_type().to_text(), "A")
......@@ -180,12 +180,12 @@ class TestXfroutSession(unittest.TestCase):
self.assertEqual(rdata[0].to_text(), "192.0.2.1")
get_msg = self.sock.read_msg()
self.assertEqual(get_msg.get_rr_count(Section.QUESTION()), 0)
self.assertEqual(get_msg.get_rr_count(Section.ANSWER()), 1)
self.assertEqual(get_msg.get_rr_count(Section.AUTHORITY()), 0)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 0)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
#answer_rrset_iter = section_iter(get_msg, section.ANSWER())
answer = get_msg.get_section(Section.ANSWER())[0]
#answer_rrset_iter = section_iter(get_msg, Message.SECTION_ANSWER)
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
self.assertEqual(answer.get_name().to_text(), "example.com.")
self.assertEqual(answer.get_class(), RRClass("IN"))
self.assertEqual(answer.get_type().to_text(), "SOA")
......@@ -281,7 +281,7 @@ class TestXfroutSession(unittest.TestCase):
sqlite3_ds.get_zone_datas = get_zone_datas
self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock, "example.com.")
reply_msg = self.sock.read_msg()
self.assertEqual(reply_msg.get_rr_count(Section.ANSWER()), 2)
self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 2)
class MyCCSession():
def __init__(self):
......
......@@ -226,8 +226,8 @@ class XfroutSession(BaseRequestHandler):
msg.set_qid(qid)
msg.set_opcode(opcode)
msg.set_rcode(rcode)
msg.set_header_flag(MessageFlag.AA())
msg.set_header_flag(MessageFlag.QR())
msg.set_header_flag(Message.HEADERFLAG_AA)
msg.set_header_flag(Message.HEADERFLAG_QR)
return msg
def _create_rrset_from_db_record(self, record):
......@@ -247,11 +247,11 @@ class XfroutSession(BaseRequestHandler):
rrset_len = get_rrset_len(rrset_soa)
if message_upper_len + rrset_len < XFROUT_MAX_MESSAGE_SIZE:
msg.add_rrset(Section.ANSWER(), rrset_soa)
msg.add_rrset(Message.SECTION_ANSWER, rrset_soa)
else:
self._send_message(sock, msg)
msg = self._clear_message(msg)
msg.add_rrset(Section.ANSWER(), rrset_soa)
msg.add_rrset(Message.SECTION_ANSWER, rrset_soa)
self._send_message(sock, msg)
......@@ -259,10 +259,10 @@ class XfroutSession(BaseRequestHandler):
def _reply_xfrout_query(self, msg, sock, zone_name):
#TODO, there should be a better way to insert rrset.
msg.make_response()
msg.set_header_flag(MessageFlag.AA())
msg.set_header_flag(Message.HEADERFLAG_AA)
soa_record = sqlite3_ds.get_zone_soa(zone_name, self.server.get_db_file())
rrset_soa = self._create_rrset_from_db_record(soa_record)
msg.add_rrset(Section.ANSWER(), rrset_soa)
msg.add_rrset(Message.SECTION_ANSWER, rrset_soa)
message_upper_len = get_rrset_len(rrset_soa)
......@@ -282,13 +282,13 @@ class XfroutSession(BaseRequestHandler):
# may have reached the limit
rrset_len = get_rrset_len(rrset_)
if message_upper_len + rrset_len < XFROUT_MAX_MESSAGE_SIZE:
msg.add_rrset(Section.ANSWER(), rrset_)
msg.add_rrset(Message.SECTION_ANSWER, rrset_)
message_upper_len += rrset_len
continue
self._send_message(sock, msg)
msg = self._clear_message(msg)
msg.add_rrset(Section.ANSWER(), rrset_) # Add the rrset to the new message
msg.add_rrset(Message.SECTION_ANSWER, rrset_) # Add the rrset to the new message
message_upper_len = rrset_len
self._send_message_with_last_soa(msg, sock, rrset_soa, message_upper_len)
......
......@@ -82,12 +82,12 @@ public:
EXPECT_EQ(0, message.getQid());
EXPECT_EQ(Opcode::QUERY(), message.getOpcode());
EXPECT_EQ(Rcode::NOERROR(), message.getRcode());
EXPECT_FALSE(message.getHeaderFlag(MessageFlag::QR()));
EXPECT_FALSE(message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ(1, message.getRRCount(Section::QUESTION()));
EXPECT_EQ(0, message.getRRCount(Section::ANSWER()));
EXPECT_EQ(0, message.getRRCount(Section::AUTHORITY()));
EXPECT_EQ(0, message.getRRCount(Section::ADDITIONAL()));
EXPECT_FALSE(message.getHeaderFlag(Message::HEADERFLAG_QR));
EXPECT_FALSE(message.getHeaderFlag(Message::HEADERFLAG_AA));
EXPECT_EQ(1, message.getRRCount(Message::SECTION_QUESTION));
EXPECT_EQ(0, message.getRRCount(Message::SECTION_ANSWER));
EXPECT_EQ(0, message.getRRCount(Message::SECTION_AUTHORITY));
EXPECT_EQ(0, message.getRRCount(Message::SECTION_ADDITIONAL));
// Check if the question matches our original data, if the expected
// data is given.
......
......@@ -101,14 +101,14 @@ getAdditional(Query& q, ConstRRsetPtr rrset) {
const generic::NS& ns = dynamic_cast<const generic::NS&>(rd);
q.tasks().push(QueryTaskPtr(
new QueryTask(q, ns.getNSName(),
Section::ADDITIONAL(),
Message::SECTION_ADDITIONAL,
QueryTask::GLUE_QUERY,
QueryTask::GETADDITIONAL)));
} else if (rrset->getType() == RRType::MX()) {
const generic::MX& mx = dynamic_cast<const generic::MX&>(rd);
q.tasks().push(QueryTaskPtr(
new QueryTask(q, mx.getMXName(),
Section::ADDITIONAL(),
Message::SECTION_ADDITIONAL,
QueryTask::NOGLUE_QUERY,
QueryTask::GETADDITIONAL)));
}
......@@ -165,7 +165,7 @@ chaseCname(Query& q, QueryTaskPtr task, RRsetPtr rrset) {
q.tasks().push(QueryTaskPtr(
new QueryTask(q, dynamic_cast<const generic::CNAME&>
(it->getCurrent()).getCname(),
task->qtype, Section::ANSWER(),
task->qtype, Message::SECTION_ANSWER,
QueryTask::FOLLOWCNAME)));
}
......@@ -473,16 +473,19 @@ doQueryTask(QueryTask& task, ZoneInfo& zoneinfo, RRsetList& target) {
// checking first to ensure that there isn't already an RRset with
// the same name and type.
inline void
addToMessage(Query& q, const Section& sect, RRsetPtr rrset,
addToMessage(Query& q, const Message::Section sect, RRsetPtr rrset,
bool no_dnssec = false)
{
Message& m = q.message();
if (no_dnssec) {
if (rrset->getType() == RRType::RRSIG() || !m.hasRRset(sect, rrset)) {
if (rrset->getType() == RRType::RRSIG() ||
!m.hasRRset(sect, rrset->getName(), rrset->getClass(),
rrset->getType())) {
m.addRRset(sect, rrset, false);
}
} else {
if (!m.hasRRset(sect, rrset)) {
if (!m.hasRRset(sect, rrset->getName(), rrset->getClass(),
rrset->getType())) {
m.addRRset(sect, rrset, q.wantDnssec());
}
}
......@@ -498,7 +501,7 @@ copyAuth(Query& q, RRsetList& auth) {
if (rrset->getType() == RRType::DS() && !q.wantDnssec()) {
continue;
}
addToMessage(q, Section::AUTHORITY(), rrset);
addToMessage(q, Message::SECTION_AUTHORITY, rrset);
getAdditional(q, rrset);
}
}
......@@ -560,11 +563,11 @@ hasDelegation(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo) {
RRsetPtr r = ref.findRRset(RRType::DNAME(), q.qclass());
if (r != NULL) {
RRsetList syn;
addToMessage(q, Section::ANSWER(), r);
q.message().setHeaderFlag(MessageFlag::AA());
addToMessage(q, Message::SECTION_ANSWER, r);
q.message().setHeaderFlag(Message::HEADERFLAG_AA);
synthesizeCname(task, r, syn);
if (syn.size() == 1) {
addToMessage(q, Section::ANSWER(),
addToMessage(q, Message::SECTION_ANSWER,
syn.findRRset(RRType::CNAME(), q.qclass()));
chaseCname(q, task, syn.findRRset(RRType::CNAME(),
q.qclass()));
......@@ -582,7 +585,7 @@ hasDelegation(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo) {
// at the actual qname node.)
if (task->op == QueryTask::AUTH_QUERY &&
task->state == QueryTask::GETANSWER) {
q.message().setHeaderFlag(MessageFlag::AA());
q.message().setHeaderFlag(Message::HEADERFLAG_AA);
}
return (false);
......@@ -599,7 +602,7 @@ addSOA(Query& q, ZoneInfo& zoneinfo) {
return (DataSrc::ERROR);
}
addToMessage(q, Section::AUTHORITY(),
addToMessage(q, Message::SECTION_AUTHORITY,
soa.findRRset(RRType::SOA(), q.qclass()));
return (DataSrc::SUCCESS);
}
......@@ -611,7 +614,7 @@ addNSEC(Query& q, const Name& name, ZoneInfo& zoneinfo) {
QueryTask newtask(q, name, RRType::NSEC(), QueryTask::SIMPLE_QUERY);
RETERR(doQueryTask(newtask, zoneinfo, nsec));
if (newtask.flags == 0) {
addToMessage(q, Section::AUTHORITY(),
addToMessage(q, Message::SECTION_AUTHORITY,
nsec.findRRset(RRType::NSEC(), q.qclass()));
}
......@@ -680,7 +683,7 @@ proveNX(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, const bool wildcard) {
RRsetPtr rrset;
string hash1(nsec3->getHash(task->qname));
RETERR(getNsec3(q, zoneinfo, hash1, rrset));
addToMessage(q, Section::AUTHORITY(), rrset);
addToMessage(q, Message::SECTION_AUTHORITY, rrset);
// If this is an NXRRSET or NOERROR/NODATA, we're done
if ((task->flags & DataSrc::TYPE_NOT_FOUND) != 0) {
......@@ -705,7 +708,7 @@ proveNX(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, const bool wildcard) {
// we don't want to use one until we find an exact match
RETERR(getNsec3(q, zoneinfo, hash2, rrset));
if (hash2 == nodehash) {
addToMessage(q, Section::AUTHORITY(), rrset);
addToMessage(q, Message::SECTION_AUTHORITY, rrset);
break;
}
}
......@@ -720,7 +723,7 @@ proveNX(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, const bool wildcard) {
string hash3(nsec3->getHash(Name("*").concatenate(enclosure)));
RETERR(getNsec3(q, zoneinfo, hash3, rrset));
if (hash3 != hash1 && hash3 != hash2) {
addToMessage(q, Section::AUTHORITY(), rrset);
addToMessage(q, Message::SECTION_AUTHORITY, rrset);
}
} else {
Name nsecname(task->qname);
......@@ -778,7 +781,7 @@ tryWildcard(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, bool& found) {
for (int i = 1; i <= diff; ++i) {
const Name& wname(star.concatenate(task->qname.split(i)));
QueryTask newtask(q, wname, task->qtype, Section::ANSWER(),
QueryTask newtask(q, wname, task->qtype, Message::SECTION_ANSWER,
QueryTask::AUTH_QUERY);
result = doQueryTask(newtask, zoneinfo, wild);
if (result == DataSrc::SUCCESS) {
......@@ -820,13 +823,13 @@ tryWildcard(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, bool& found) {
RRsetPtr rrset = wild.findRRset(RRType::CNAME(), q.qclass());
if (rrset != NULL) {
rrset->setName(task->qname);
addToMessage(q, Section::ANSWER(), rrset);
addToMessage(q, Message::SECTION_ANSWER, rrset);
chaseCname(q, task, rrset);
}
} else {
BOOST_FOREACH (RRsetPtr rrset, wild) {
rrset->setName(task->qname);
addToMessage(q, Section::ANSWER(), rrset);
addToMessage(q, Message::SECTION_ANSWER, rrset);
}
RRsetList auth;
......@@ -855,7 +858,7 @@ DataSrc::doQuery(Query& q) {
// Process the query task queue. (The queue is initialized
// and the first task placed on it by the Query constructor.)
m.clearHeaderFlag(MessageFlag::AA());
m.setHeaderFlag(Message::HEADERFLAG_AA, false);
while (!q.tasks().empty()) {
QueryTaskPtr task = q.tasks().front();
q.tasks().pop();
......@@ -982,19 +985,19 @@ DataSrc::doQuery(Query& q) {
// The qname node contains an out-of-zone referral.
if (task->state == QueryTask::GETANSWER) {
RRsetList auth;
m.clearHeaderFlag(MessageFlag::AA());
m.setHeaderFlag(Message::HEADERFLAG_AA, false);
if (!refQuery(q, task->qname, zoneinfo, auth)) {
m.setRcode(Rcode::SERVFAIL());
return;
}
BOOST_FOREACH (RRsetPtr rrset, auth) {
if (rrset->getType() == RRType::NS()) {
addToMessage(q, Section::AUTHORITY(), rrset);