Put in the skeleton around the auto wiring functionality

This commit is contained in:
John Sharratt 2017-07-01 09:28:39 +02:00
parent ca91245d3f
commit 8ed35f841f
9 changed files with 85 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2017-01-07 Johnathan Sharratt <johnathan.sharratt@gmail.com>
* Version 0.2.6
* Added a feature that will automatically create route entries
in the routing tables, thus providing an alternative to this
https://github.com/google/ndprbrd projects use-case.
2016-04-18 Daniel Adolfsson <daniel@priv.nu>
* Version 0.2.5

View File

@ -22,6 +22,13 @@ proxy eth0 {
# invalidating the entry, in milliseconds. Default value is '500'.
timeout 500
# auto-wire <yes|no|true|false>
# Controls whether whether ndppd will automatically create host entries
# in the routing tables when it receives Neighbor Advertisements on a
# listening interface. The the default value is no.
auto-wire no
# ttl <integer>
# Controls how long a valid or invalid entry remains in the cache, in

View File

@ -48,6 +48,12 @@ Controls how long
.B ndppd
will cache an entry. This is in milliseconds, and the default value
is 30000 (30 seconds).
.IP "auto-wire <yes|no>"
Controls whether
.B ndppd
will automatically create host entries in the routing tables when
.B ndppd receives Neighbor Advertisements on a listening interface.
The default value is no.
.IP "timeout <value>"
Controls how long
.B ndppd

View File

@ -589,7 +589,7 @@ int iface::poll_all()
const ptr<session> sess = *s_it;
if ((sess->taddr() == taddr) && (sess->status() == session::WAITING)) {
sess->handle_advert();
sess->handle_advert(ifa);
break;
}
}

View File

@ -159,6 +159,11 @@ static bool configure(ptr<conf>& cf)
pr->router(true);
else
pr->router(*x_cf);
if (!(x_cf = pr_cf->find("autowire")))
pr->autowire(false);
else
pr->autowire(*x_cf);
if (!(x_cf = pr_cf->find("ttl")))
pr->ttl(30000);

View File

@ -30,7 +30,7 @@ NDPPD_NS_BEGIN
std::list<ptr<proxy> > proxy::_list;
proxy::proxy() :
_router(true), _ttl(30000), _timeout(500)
_router(true), _ttl(30000), _timeout(500), _autowire(false)
{
}
@ -104,7 +104,7 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
if (ru->addr() == taddr) {
if (!se) {
se = session::create(_ptr, saddr, daddr, taddr);
se = session::create(_ptr, saddr, daddr, taddr, _autowire);
}
if (ru->is_auto()) {
@ -130,7 +130,7 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
if (if_addr_find((*it)->ifa()->name(), &taddr.const_addr())) {
logger::debug() << "Sending NA out " << (*it)->ifa()->name();
se->add_iface(_ifa);
se->handle_advert();
se->handle_advert(_ifa);
}
#endif
}
@ -177,6 +177,16 @@ void proxy::router(bool val)
_router = val;
}
bool proxy::autowire() const
{
return _autowire;
}
void proxy::autowire(bool val)
{
_autowire = val;
}
int proxy::ttl() const
{
return _ttl;

View File

@ -48,6 +48,10 @@ public:
bool router() const;
void router(bool val);
bool autowire() const;
void autowire(bool val);
int timeout() const;
@ -69,6 +73,8 @@ private:
std::list<ptr<session> > _sessions;
bool _router;
bool _autowire;
int _ttl, _timeout;

View File

@ -65,16 +65,17 @@ session::~session()
}
ptr<session> session::create(const ptr<proxy>& pr, const address& saddr,
const address& daddr, const address& taddr)
const address& daddr, const address& taddr, bool auto_wire)
{
ptr<session> se(new session());
se->_ptr = se;
se->_pr = pr;
se->_saddr = address("::") == saddr ? all_nodes : saddr;
se->_taddr = taddr;
se->_daddr = daddr;
se->_ttl = pr->timeout();
se->_ptr = se;
se->_pr = pr;
se->_saddr = address("::") == saddr ? all_nodes : saddr;
se->_taddr = taddr;
se->_daddr = daddr;
se->_autowire = auto_wire;
se->_ttl = pr->timeout();
_sessions.push_back(se);
@ -110,6 +111,23 @@ void session::send_advert()
_pr->ifa()->write_advert(_saddr, _taddr, _pr->router());
}
void session::handle_auto_wire(const ptr<iface>& ifa)
{
logger::debug()
<< "session::handle_auto_wire() taddr=" << _taddr << ", ifa=" << ifa->name();
logger::debug() << "session::handle_auto_wire()";
}
void session::handle_advert(const ptr<iface>& ifa)
{
if (_autowire == true) {
handle_auto_wire(ifa);
}
handle_advert();
}
void session::handle_advert()
{
_status = VALID;
@ -133,6 +151,11 @@ const address& session::daddr() const
return _daddr;
}
bool session::autowire() const
{
return _autowire;
}
int session::status() const
{
return _status;

View File

@ -31,6 +31,8 @@ private:
weak_ptr<proxy> _pr;
address _saddr, _daddr, _taddr;
bool _autowire;
// An array of interfaces this session is monitoring for
// ND_NEIGHBOR_ADVERT on.
@ -58,7 +60,7 @@ public:
~session();
static ptr<session> create(const ptr<proxy>& pr, const address& saddr,
const address& daddr, const address& taddr);
const address& daddr, const address& taddr, bool autowire);
void add_iface(const ptr<iface>& ifa);
@ -67,12 +69,18 @@ public:
const address& daddr() const;
const address& saddr() const;
bool autowire() const;
int status() const;
void status(int val);
void handle_advert();
void handle_advert(const ptr<iface>& ifa);
void handle_auto_wire(const ptr<iface>& ifa);
void send_advert();