Commit 0be6dcc6 authored by JINMEI Tatuya's avatar JINMEI Tatuya

had the AuthSrv maintain verbosity


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1378 e5f2f494-b856-4b98-b285-d166d9295462
parent 06f1826d
......@@ -71,11 +71,13 @@ public:
/// file change
isc::auth::ConstDataSrcPtr cur_datasrc_;
bool verbose_mode_;
/// Currently non-configurable, but will be.
static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096;
};
AuthSrvImpl::AuthSrvImpl() {
AuthSrvImpl::AuthSrvImpl() : verbose_mode_(false) {
// cur_datasrc_ is automatically initialized by the default constructor,
// effectively being an empty (sqlite) data source. once ccsession is up
// the datasource will be set by the configuration setting
......@@ -142,10 +144,20 @@ makeErrorMessage(Message& message, MessageRenderer& renderer,
}
}
void
AuthSrv::setVerbose(const bool on) {
impl_->verbose_mode_ = on;
}
bool
AuthSrv::getVerbose() const {
return (impl_->verbose_mode_);
}
bool
AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
MessageRenderer& response_renderer,
const bool udp_buffer, const bool verbose_mode)
const bool udp_buffer)
{
// First, check the header part. If we fail even for the base header,
// just drop the message.
......@@ -154,7 +166,7 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
// Ignore all responses.
if (message.getHeaderFlag(MessageFlag::QR())) {
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "received unexpected response, ignoring" << endl;
}
return (false);
......@@ -167,23 +179,23 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
try {
message.fromWire(request_buffer);
} catch (const DNSProtocolError& error) {
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "returning " << error.getRcode().toText() << ": "
<< error.what() << endl;
}
makeErrorMessage(message, response_renderer, error.getRcode(),
verbose_mode);
impl_->verbose_mode_);
return (true);
} catch (const Exception& ex) {
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "returning SERVFAIL: " << ex.what() << endl;
}
makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
verbose_mode);
impl_->verbose_mode_);
return (true);
} // other exceptions will be handled at a higher layer.
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "[AuthSrv] received a message:\n" << message.toText() << endl;
}
......@@ -191,17 +203,17 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
// In this implementation, we only support normal queries
if (message.getOpcode() != Opcode::QUERY()) {
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "unsupported opcode" << endl;
}
makeErrorMessage(message, response_renderer, Rcode::NOTIMP(),
verbose_mode);
impl_->verbose_mode_);
return (true);
}
if (message.getRRCount(Section::QUESTION()) != 1) {
makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
verbose_mode);
impl_->verbose_mode_);
return (true);
}
......@@ -218,17 +230,17 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
Query query(message, dnssec_ok);
impl_->data_sources_.doQuery(query);
} catch (const Exception& ex) {
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "Internal error, returning SERVFAIL: " << ex.what() << endl;
}
makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
verbose_mode);
impl_->verbose_mode_);
return (true);
}
response_renderer.setLengthLimit(udp_buffer ? remote_bufsize : 65535);
message.toWire(response_renderer);
if (verbose_mode) {
if (impl_->verbose_mode_) {
cerr << "sending a response (" <<
boost::lexical_cast<string>(response_renderer.getLength())
<< " bytes):\n" << message.toText() << endl;
......@@ -241,7 +253,9 @@ ElementPtr
AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) {
if (config) {
db_file_ = config->get("database_file")->stringValue();
cout << "[AuthSrv] Data source database file: " << db_file_ << endl;
if (verbose_mode_) {
cout << "[AuthSrv] Data source database file: " << db_file_ << endl;
}
}
// create SQL data source
......@@ -284,7 +298,9 @@ AuthSrv::updateConfig(isc::data::ElementPtr new_config) {
return answer;
} catch (const isc::Exception& error) {
cout << "[AuthSrv] error: " << error.what() << endl;
if (impl_->verbose_mode_) {
cerr << "[AuthSrv] error: " << error.what() << endl;
}
return isc::config::createAnswer(1, error.what());
}
}
......@@ -50,7 +50,9 @@ public:
bool processMessage(isc::dns::InputBuffer& request_buffer,
isc::dns::Message& message,
isc::dns::MessageRenderer& response_renderer,
bool udp_buffer, bool verbose_mode);
bool udp_buffer);
void setVerbose(bool on);
bool getVerbose() const;
void serve(std::string zone_name);
isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
private:
......
......@@ -149,8 +149,7 @@ public:
if (!error) {
InputBuffer dnsbuffer(data_, bytes_transferred);
if (auth_server->processMessage(dnsbuffer, dns_message_,
response_renderer_, false,
verbose_mode)) {
response_renderer_, false)) {
responselen_buffer_.writeUint16(response_buffer_.getLength());
async_write(socket_,
boost::asio::buffer(
......@@ -258,8 +257,7 @@ public:
dns_message_.clear(Message::PARSE);
response_renderer_.clear();
if (auth_server->processMessage(request_buffer, dns_message_,
response_renderer_, true,
verbose_mode)) {
response_renderer_, true)) {
socket_.async_send_to(
boost::asio::buffer(response_buffer_.getData(),
response_buffer_.getLength()),
......@@ -450,7 +448,7 @@ processMessageUDP(const int fd, Message& dns_message,
if ((cc = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, sa, &sa_len)) > 0) {
InputBuffer buffer(recvbuf, cc);
if (auth_server->processMessage(buffer, dns_message, response_renderer,
true, verbose_mode)) {
true)) {
sendto(fd, response_renderer.getData(),
response_renderer.getLength(), 0, sa, sa_len);
}
......@@ -496,7 +494,7 @@ processMessageTCP(const int fd, Message& dns_message,
dns_message.clear(Message::PARSE);
response_renderer.clear();
if (auth_server->processMessage(buffer, dns_message, response_renderer,
false, verbose_mode)) {
false)) {
size = response_renderer.getLength();
size_n = htons(size);
if (send(ts, &size_n, 2, 0) == 2) {
......@@ -639,6 +637,7 @@ main(int argc, char* argv[]) {
}
auth_server = new AuthSrv;
auth_server->setVerbose(verbose_mode);
// initialize command channel
int ret = 0;
......
......@@ -122,17 +122,26 @@ TEST_F(AuthSrvTest, unsupportedRequest) {
parse_message.clear(Message::PARSE);
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
headerCheck(parse_message, default_qid, Rcode::NOTIMP(), i, QR_FLAG,
0, 0, 0, 0);
}
}
// Simple API check
TEST_F(AuthSrvTest, verbose) {
EXPECT_FALSE(server.getVerbose());
server.setVerbose(true);
EXPECT_TRUE(server.getVerbose());
server.setVerbose(false);
EXPECT_FALSE(server.getVerbose());
}
// Multiple questions. Should result in FORMERR.
TEST_F(AuthSrvTest, multiQuestion) {
createDataFromFile("testdata/multiquestion_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
QR_FLAG, 2, 0, 0, 0);
......@@ -153,7 +162,7 @@ TEST_F(AuthSrvTest, multiQuestion) {
TEST_F(AuthSrvTest, shortMessage) {
createDataFromFile("testdata/shortmessage_fromWire");
EXPECT_EQ(false, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
}
// Response messages. Must be silently dropped, whether it's a valid response
......@@ -162,25 +171,25 @@ TEST_F(AuthSrvTest, response) {
// A valid (although unusual) response
createDataFromFile("testdata/simpleresponse_fromWire");
EXPECT_EQ(false, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
// A response with a broken question section. must be dropped rather than
// returning FORMERR.
createDataFromFile("testdata/shortresponse_fromWire");
EXPECT_EQ(false, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
// A response to iquery. must be dropped rather than returning NOTIMP.
createDataFromFile("testdata/iqueryresponse_fromWire");
EXPECT_EQ(false, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
}
// Query with a broken question
TEST_F(AuthSrvTest, shortQuestion) {
createDataFromFile("testdata/shortquestion_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
// Since the query's question is broken, the question section of the
// response should be empty.
headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
......@@ -191,7 +200,7 @@ TEST_F(AuthSrvTest, shortQuestion) {
TEST_F(AuthSrvTest, shortAnswer) {
createDataFromFile("testdata/shortanswer_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
// This is a bogus query, but question section is valid. So the response
// should copy the question section.
......@@ -210,7 +219,7 @@ TEST_F(AuthSrvTest, shortAnswer) {
TEST_F(AuthSrvTest, ednsBadVers) {
createDataFromFile("testdata/queryBadEDNS_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
// The response must have an EDNS OPT RR in the additional section.
// Note that the DNSSEC DO bit is cleared even if this bit in the query
......@@ -244,7 +253,7 @@ TEST_F(AuthSrvTest, updateConfig) {
// and authority section.
createDataFromFile("testdata/examplequery_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
headerCheck(parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
QR_FLAG | AA_FLAG, 1, 1, 1, 0);
}
......@@ -258,7 +267,7 @@ TEST_F(AuthSrvTest, datasourceFail) {
// be empty.
createDataFromFile("testdata/badExampleQuery_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
headerCheck(parse_message, default_qid, Rcode::SERVFAIL(), opcode.getCode(),
QR_FLAG, 1, 0, 0, 0);
}
......@@ -273,7 +282,7 @@ TEST_F(AuthSrvTest, updateConfigFail) {
// The original data source should still exist.
createDataFromFile("testdata/examplequery_fromWire");
EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
response_renderer, true));
headerCheck(parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
QR_FLAG | AA_FLAG, 1, 1, 1, 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