From 869fdbca2a02729f66aba1528050a677aa3856bb Mon Sep 17 00:00:00 2001 From: Daniel Adolfsson Date: Sun, 18 Sep 2011 02:46:51 +0200 Subject: [PATCH] Add support for static rules --- src/conf.cc | 9 ++++++++- src/proxy.cc | 17 ++++++++++++++--- src/session.cc | 5 +++++ src/session.h | 2 ++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/conf.cc b/src/conf.cc index d3d31bf..f2827fb 100644 --- a/src/conf.cc +++ b/src/conf.cc @@ -77,10 +77,17 @@ bool conf::setup(cfg_t *cfg) std::string ifname(cfg_getstr(rule_cfg, "iface")); - if(ifname == "") + if(ifname.empty()) + { + if(addr.prefix() <= 120) + NCE("Static rule prefix /%d <= 120 - is this what you want?", addr.prefix()); + pr->add_rule(addr); + } else + { pr->add_rule(addr, iface::open_ifd(ifname)); + } } } } diff --git a/src/proxy.cc b/src/proxy.cc index da76b79..13ea54c 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -89,14 +89,25 @@ void proxy::handle_solicit(const address& saddr, const address& daddr, for(std::list >::iterator it = _rules.begin(); it != _rules.end(); it++) { - DBG("comparing %s against %s", - (*it)->addr().to_string().c_str(), taddr.to_string().c_str()); + strong_ptr ru = *it; - if((*it)->addr() == taddr) + DBG("comparing %s against %s", + ru->addr().to_string().c_str(), taddr.to_string().c_str()); + + if(ru->addr() == taddr) { if(se.is_null()) se = session::create(_ptr, saddr, daddr, taddr); + if(ru->ifa().is_null()) + { + // This rule doesn't have an interface, and thus we'll consider + // it "static" and immediately send the response. + + se->handle_advert(); + return; + } + se->add_iface((*it)->ifa()); } } diff --git a/src/session.cc b/src/session.cc index 68215cb..397a70a 100644 --- a/src/session.cc +++ b/src/session.cc @@ -136,4 +136,9 @@ int session::status() const return _status; } +void session::status(int val) +{ + _status = val; +} + __NDPPD_NS_END diff --git a/src/session.h b/src/session.h index 3ce0492..52130c1 100644 --- a/src/session.h +++ b/src/session.h @@ -72,6 +72,8 @@ public: int status() const; + void status(int val); + void handle_advert(); void send_advert();