Commit fadf58e7 authored by Jeremy C. Reed's avatar Jeremy C. Reed
Browse files

Remove parkinglot from trunk. It is still in branches/parkinglot if needed.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@784 e5f2f494-b856-4b98-b285-d166d9295462
parent bde60771
......@@ -148,7 +148,6 @@ AC_CONFIG_FILES([Makefile
src/bin/host/Makefile
src/bin/msgq/Makefile
src/bin/auth/Makefile
src/bin/parkinglot/Makefile
src/lib/Makefile
src/lib/cc/Makefile
src/lib/cc/cpp/Makefile
......@@ -181,7 +180,6 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
src/bin/msgq/msgq_test
src/bin/msgq/run_msgq.sh
src/bin/auth/config.h
src/bin/parkinglot/config.h
src/lib/config/cpp/data_def_unittests_config.h
src/lib/config/python/isc/config/config_test
src/lib/dns/cpp/gen-rdatacode.py
......
SUBDIRS = bind10 bindctl cfgmgr msgq host cmdctl auth parkinglot
SUBDIRS = bind10 bindctl cfgmgr msgq host cmdctl auth
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/src/lib -I$(top_builddir)/src/lib/dns/cpp -I$(top_builddir)/include/dns/cpp -I$(top_builddir)/include -I$(top_srcdir)/ext
pkglibexecdir = $(libexecdir)/@PACKAGE@
pkglibexec_PROGRAMS = b10-parkinglot
b10_parkinglot_SOURCES = b10-parkinglot.cc b10-parkinglot.h
b10_parkinglot_SOURCES += common.cc common.h zoneset.h zoneset.cc main.cc
b10_parkinglot_SOURCES += data_source_plot.h data_source_plot.cc
b10_parkinglot_SOURCES += data_source.h data_source.cc
b10_parkinglot_SOURCES += builtin.h builtin.cc
b10_parkinglot_LDADD = $(top_builddir)/src/lib/dns/cpp/.libs/libdns.a
b10_parkinglot_LDADD += $(top_builddir)/src/lib/config/cpp/libcfgclient.a
b10_parkinglot_LDADD += $(top_builddir)/src/lib/cc/cpp/libcc.a
b10_parkinglot_LDADD += $(top_builddir)/src/lib/exceptions/cpp/.libs/libexceptions.a
b10_parkinglotdir = $(DESTDIR)$(pkgdatadir)
b10_parkinglot_DATA = parkinglot.spec
# TODO: don't install this here
bin_PROGRAMS = builtin_bench
builtin_bench_SOURCES = builtin_bench.cc builtin.h builtin.cc
builtin_bench_LDADD = $(top_builddir)/src/lib/dns/cpp/.libs/libdns.a
builtin_bench_LDADD += $(top_builddir)/src/lib/exceptions/cpp/.libs/libexceptions.a
// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <dns/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/question.h>
#include <dns/rdataclass.h>
#include <dns/rrset.h>
#include <dns/rrttl.h>
#include <dns/message.h>
#include <cc/data.h>
#include "common.h"
#include "builtin.h"
#include "b10-parkinglot.h"
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
using namespace isc::data;
ParkingLot::ParkingLot(int port) {
/*ns1 = Rdata::RdataPtr(new NS("ns1.parking.example"));
ns2 = Rdata::RdataPtr(new NS("ns2.parking.example"));
ns3 = Rdata::RdataPtr(new NS("ns3.parking.example"));
a = Rdata::RdataPtr(new A("127.0.0.1"));
aaaa = Rdata::RdataPtr(new AAAA("::1"));
*/
int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0)
throw FatalError("failed to open socket");
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(port);
socklen_t sa_len = sizeof(sin);
#ifdef HAVE_SIN_LEN
sin.sin_len = sa_len;
#endif
if (bind(s, (struct sockaddr *)&sin, sa_len) < 0)
throw FatalError("could not bind socket");
sock = s;
}
namespace {
struct GlueInserter {
GlueInserter(const DataSourceParkingLot& data_source,
const Name& zname, const RRClass& qclass,
Message& msg) :
data_source_(&data_source), zname_(&zname), qclass_(&qclass),
msg_(&msg)
{}
void operator()(const RRsetPtr rrset)
{
if (rrset->getType() == RRType::NS()) {
RdataIteratorPtr it = rrset->getRdataIterator();
for (it->first(); !it->isLast(); it->next()) {
const generic::NS& nsrdata =
dynamic_cast<const generic::NS&>(it->getCurrent());
data_source_->addToMessage(*msg_, Section::ADDITIONAL(),
*zname_, nsrdata.getNSName(),
*qclass_, RRType::A());
data_source_->addToMessage(*msg_, Section::ADDITIONAL(),
*zname_, nsrdata.getNSName(),
*qclass_, RRType::AAAA());
}
}
}
const DataSourceParkingLot* data_source_;
const Name* zname_;
const RRClass* qclass_;
Message* msg_;
};
}
namespace {
const Name authors_name("authors.bind");
const Name version_name("version.bind");
}
void
ParkingLot::processMessage() {
struct sockaddr_storage ss;
socklen_t sa_len = sizeof(ss);
struct sockaddr* sa = static_cast<struct sockaddr*>((void*)&ss);
int s = sock;
char recvbuf[4096];
int cc;
if ((cc = recvfrom(s, recvbuf, sizeof(recvbuf), 0, sa, &sa_len)) > 0) {
Message msg;
InputBuffer buffer(recvbuf, cc);
try {
msg.fromWire(buffer);
} catch (...) {
cerr << "parse failed" << endl;
return;
}
cout << "received a message:\n" << msg.toText() << endl;
if (msg.getRRCount(Section::QUESTION()) != 1) {
return;
}
QuestionPtr query = *msg.beginQuestion();
msg.makeResponse();
msg.setHeaderFlag(MessageFlag::AA());
Name zname("."); // ugly, but should work for now
msg.setRcode(Rcode::NOERROR());
if (query->getType() == RRType::TXT() &&
query->getClass() == RRClass::CH() &&
query->getName() == authors_name) {
msg.addRRset(Section::ANSWER(), getBuiltinAuthors().getAnswer());
msg.addRRset(Section::AUTHORITY(),
getBuiltinAuthors().getAuthority());
} else if (query->getType() == RRType::TXT() &&
query->getClass() == RRClass::CH() &&
query->getName() == version_name) {
msg.addRRset(Section::ANSWER(), getBuiltinVersion().getAnswer());
msg.addRRset(Section::AUTHORITY(),
getBuiltinVersion().getAuthority());
} else if (data_source.hasZoneFor(query->getName(), zname)) {
SearchResult::status_type status =
data_source.addToMessage(msg, Section::ANSWER(), zname,
query->getName(), query->getClass(),
query->getType());
bool included_ns = false;
// rcode is based on this result?
if (status == SearchResult::name_not_found) {
msg.setRcode(Rcode::NXDOMAIN());
if (query->getType() != RRType::NS()) {
status = data_source.addToMessage(msg, Section::AUTHORITY(),
zname, zname,
query->getClass(),
RRType::SOA());
}
} else {
if (query->getType() != RRType::NS()) {
status = data_source.addToMessage(msg, Section::AUTHORITY(),
zname, zname,
query->getClass(),
RRType::NS());
}
included_ns = true;
}
// If we included NS records, and their target falls below the zone, add glue
if (included_ns) {
for_each(msg.beginSection(Section::ANSWER()),
msg.endSection(Section::ANSWER()),
GlueInserter(data_source, zname, query->getClass(),
msg));
for_each(msg.beginSection(Section::AUTHORITY()),
msg.endSection(Section::AUTHORITY()),
GlueInserter(data_source, zname, query->getClass(),
msg));
}
} else {
msg.setRcode(Rcode::SERVFAIL());
}
OutputBuffer obuffer(4096);
MessageRenderer renderer(obuffer);
msg.toWire(renderer);
cout << "sending a response (" <<
boost::lexical_cast<string>(obuffer.getLength())
<< " bytes):\n" << msg.toText() << endl;
sendto(s, obuffer.getData(), obuffer.getLength(), 0, sa, sa_len);
}
}
ElementPtr
ParkingLot::updateConfig(isc::data::ElementPtr config) {
if (config->contains("zones")) {
data_source.clear_zones();
BOOST_FOREACH(isc::data::ElementPtr zone_el, config->get("zones")->listValue()) {
data_source.serve(zone_el->stringValue());
}
}
if (config->contains("port")) {
// todo: what to do with port change. restart automatically?
// ignore atm
}
if (config->contains("a_records")) {
data_source.clearARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("a_records")->listValue()) {
data_source.addARecord(rel->stringValue());
}
}
if (config->contains("aaaa_records")) {
data_source.clearAAAARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("aaaa_records")->listValue()) {
data_source.addAAAARecord(rel->stringValue());
}
}
if (config->contains("ns_records")) {
data_source.clearNSRecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("ns_records")->listValue()) {
data_source.addNSRecord(rel->stringValue());
}
}
return isc::data::Element::createFromString("{ \"result\": [0] }");
}
// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#ifndef __PARKINGLOT_H
#define __PARKINGLOT_H 1
#include "zoneset.h"
#include <cc/data.h>
#include "data_source_plot.h"
class ParkingLot {
public:
explicit ParkingLot(int port);
virtual ~ParkingLot() {}
int getSocket() { return (sock); }
void processMessage();
void command(std::pair<std::string,isc::data::ElementPtr>);
void serve(std::string zone_name);
isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
private:
isc::dns::DataSourceParkingLot data_source;
int sock;
};
#endif // __PARKINGLOT_H
// Local Variables:
// mode: c++
// End:
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#include <string>
#include <vector>
#include <dns/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/rdata.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <dns/rrttl.h>
#include <dns/rrset.h>
#include "builtin.h"
using namespace std;
using namespace isc::dns;
using namespace isc::dns::rdata;
namespace {
const Name authors_name("authors.bind");
const Name version_name("version.bind");
const char* authors[] = {
"Han Feng",
"Kazunori Fujiwara",
"Michael Graff",
"Evan Hunt",
"Jelte Jansen",
"Jin Jian",
"JINMEI Tatuya",
"Naoki Kambe",
"Shane Kerr",
"Zhang Likun",
"Jeremy C. Reed",
NULL
};
const char* version[] = {
"BIND10 0.0.1",
NULL
};
const char* author_authorities[] = {
"authors.bind",
NULL
};
const char* version_authorities[] = {
"version.bind",
NULL
};
class BuiltinRRset : public AbstractRRset {
private:
BuiltinRRset(const BuiltinRRset& source);
void operator=(const BuiltinRRset& source);
public:
BuiltinRRset(const Name& name, const RRType& rrtype,
const char** rdata_string_list);
virtual void addRdata(const rdata::RdataPtr rdata)
{
// ignore it (or we might throw an exception)
}
virtual unsigned int getRdataCount() const { return (num_rdata_); }
virtual const Name& getName() const { return (name_); }
virtual const RRClass& getClass() const { return (rrclass_); }
virtual const RRType& getType() const { return (rrtype_); }
virtual const RRTTL& getTTL() const { return (rrttl_); }
virtual void setTTL(const RRTTL& ttl)
{
// ignore it (or we might throw an exception)
}
virtual unsigned int toWire(MessageRenderer& renderer) const;
virtual RdataIteratorPtr getRdataIterator() const;
const Name name_;
const RRType rrtype_;
const RRClass rrclass_;
const RRTTL rrttl_;
vector<RdataPtr> rdatavector_;
unsigned int num_rdata_;
OutputBuffer wire_data_; // pre-rendered RRset
size_t data_offset_; // offset to the RRset data
static const size_t DATA_OFFSET = 12; // length of DNS header
};
class BuiltinRdataIterator : public RdataIterator {
private:
BuiltinRdataIterator() {}
public:
BuiltinRdataIterator(const vector<RdataPtr>& datavector) :
datavector_(&datavector) {}
~BuiltinRdataIterator() {}
virtual void first() { it_ = datavector_->begin(); }
virtual void next() { ++it_; }
virtual const rdata::Rdata& getCurrent() const { return (**it_); }
virtual bool isLast() const { return (it_ == datavector_->end()); }
private:
const vector<RdataPtr>* datavector_;
vector<RdataPtr>::const_iterator it_;
};
}
BuiltinRRset::BuiltinRRset(const Name& name, const RRType& rrtype,
const char** rdata_string_list) :
name_(name), rrtype_(rrtype), rrclass_(RRClass::CH()), rrttl_(RRTTL(0)),
num_rdata_(0), wire_data_(512)
{
MessageRenderer renderer(wire_data_);
renderer.skip(DATA_OFFSET); // leave the space for the DNS header
renderer.writeName(name);
data_offset_ = renderer.getLength(); // remember the start position
RRset tmprrset(name, rrclass_, rrtype_, rrttl_);
for (int i = 0; rdata_string_list[i] != NULL; ++i) {
RdataPtr rdata = createRdata(rrtype_, rrclass_,
string(rdata_string_list[i]));
rdatavector_.push_back(rdata);
tmprrset.addRdata(rdata);
}
// pre-render the RRset
tmprrset.toWire(renderer);
num_rdata_ = rdatavector_.size();
}
unsigned int
BuiltinRRset::toWire(MessageRenderer& renderer) const
{
// XXX: we should confirm the query name matches the pre-rendered data
// and it's stored in the Question section. This proof-of-concept
// implementation omits the check for brevity.
renderer.writeData(static_cast<const uint8_t*>(wire_data_.getData())
+ data_offset_, wire_data_.getLength() - data_offset_);
return (num_rdata_);
}
RdataIteratorPtr
BuiltinRRset::getRdataIterator() const
{
return (RdataIteratorPtr(new BuiltinRdataIterator(rdatavector_)));
}
struct BuiltinRRsetsImpl {
BuiltinRRsetsImpl(const Name& answer_name, const char** answers,
const char** authorities);
RRsetPtr rrset_answer;
RRsetPtr rrset_authority;
};
BuiltinRRsetsImpl::BuiltinRRsetsImpl(const Name& answer_name,
const char** answers,
const char** authorities)
{
rrset_answer = RRsetPtr(new BuiltinRRset(answer_name, RRType::TXT(),
answers));
rrset_authority = RRsetPtr(new BuiltinRRset(answer_name, RRType::NS(),
authorities));
}
BuiltinRRsets::BuiltinRRsets(const Name& name,
const char** answers,
const char** authorities)
{
impl_ = new BuiltinRRsetsImpl(name, answers, authorities);
}
BuiltinRRsets::~BuiltinRRsets()
{
delete impl_;
}
RRsetPtr
BuiltinRRsets::getAnswer() const
{
return (impl_->rrset_answer);
}
RRsetPtr
BuiltinRRsets::getAuthority() const
{
return (impl_->rrset_authority);
}
const BuiltinRRsets&
getBuiltinAuthors()
{
static BuiltinRRsets builtin_authors(authors_name, authors,
author_authorities);
return (builtin_authors);
}
const BuiltinRRsets&
getBuiltinVersion()
{
static BuiltinRRsets builtin_version(version_name, version,
version_authorities);
return (builtin_version);
}
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#ifndef __BUILTIN_H
#define __BUILTIN_H 1
#include <boost/shared_ptr.hpp>
#include <dns/name.h>
#include <dns/rrset.h>
struct BuiltinRRsetsImpl;
class isc::dns::Name;
class BuiltinRRsets {
public:
BuiltinRRsets(const isc::dns::Name& name, const char** answers,
const char** authorities);
~BuiltinRRsets();
isc::dns::RRsetPtr getAnswer() const;
isc::dns::RRsetPtr getAuthority() const;
private:
BuiltinRRsets(const BuiltinRRsets& source);
void operator=(const BuiltinRRsets& source);
BuiltinRRsetsImpl* impl_;
};
const BuiltinRRsets& getBuiltinAuthors();
const BuiltinRRsets& getBuiltinVersion();
#endif // __BUILTIN_H
// Local Variables:
// mode: c++
// End:
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY