From 8ed35f841f926f8dee58d2f4dce01d3b64b04201 Mon Sep 17 00:00:00 2001 From: John Sharratt Date: Sat, 1 Jul 2017 09:28:39 +0200 Subject: [PATCH] Put in the skeleton around the auto wiring functionality --- ChangeLog | 8 ++++++++ ndppd.conf-dist | 7 +++++++ ndppd.conf.5 | 6 ++++++ src/iface.cc | 2 +- src/ndppd.cc | 5 +++++ src/proxy.cc | 16 +++++++++++++--- src/proxy.h | 6 ++++++ src/session.cc | 37 ++++++++++++++++++++++++++++++------- src/session.h | 10 +++++++++- 9 files changed, 85 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebcc24e..a88fb7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-01-07 Johnathan Sharratt + + * 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 * Version 0.2.5 diff --git a/ndppd.conf-dist b/ndppd.conf-dist index 37656c7..719abf8 100644 --- a/ndppd.conf-dist +++ b/ndppd.conf-dist @@ -22,6 +22,13 @@ proxy eth0 { # invalidating the entry, in milliseconds. Default value is '500'. timeout 500 + + # auto-wire + # 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 # Controls how long a valid or invalid entry remains in the cache, in diff --git a/ndppd.conf.5 b/ndppd.conf.5 index 785bce2..1489093 100644 --- a/ndppd.conf.5 +++ b/ndppd.conf.5 @@ -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 " +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 " Controls how long .B ndppd diff --git a/src/iface.cc b/src/iface.cc index 74d2fd6..2e6b524 100644 --- a/src/iface.cc +++ b/src/iface.cc @@ -589,7 +589,7 @@ int iface::poll_all() const ptr sess = *s_it; if ((sess->taddr() == taddr) && (sess->status() == session::WAITING)) { - sess->handle_advert(); + sess->handle_advert(ifa); break; } } diff --git a/src/ndppd.cc b/src/ndppd.cc index e645421..cb5450c 100644 --- a/src/ndppd.cc +++ b/src/ndppd.cc @@ -159,6 +159,11 @@ static bool configure(ptr& 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); diff --git a/src/proxy.cc b/src/proxy.cc index 2de5a3e..2b6d1c9 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -30,7 +30,7 @@ NDPPD_NS_BEGIN std::list > 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; diff --git a/src/proxy.h b/src/proxy.h index 0a77698..9baf720 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -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 > _sessions; bool _router; + + bool _autowire; int _ttl, _timeout; diff --git a/src/session.cc b/src/session.cc index 05091f4..ec6b337 100644 --- a/src/session.cc +++ b/src/session.cc @@ -65,16 +65,17 @@ session::~session() } ptr session::create(const ptr& pr, const address& saddr, - const address& daddr, const address& taddr) + const address& daddr, const address& taddr, bool auto_wire) { ptr 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& ifa) +{ + logger::debug() + << "session::handle_auto_wire() taddr=" << _taddr << ", ifa=" << ifa->name(); + + logger::debug() << "session::handle_auto_wire()"; +} + +void session::handle_advert(const ptr& 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; diff --git a/src/session.h b/src/session.h index d70b930..18dd691 100644 --- a/src/session.h +++ b/src/session.h @@ -31,6 +31,8 @@ private: weak_ptr _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 create(const ptr& pr, const address& saddr, - const address& daddr, const address& taddr); + const address& daddr, const address& taddr, bool autowire); void add_iface(const ptr& 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& ifa); + + void handle_auto_wire(const ptr& ifa); void send_advert();