Skip to content

Commit

Permalink
Last major commit for version 0.2.2
Browse files Browse the repository at this point in the history
  * Fix so that "route-ttl" in ndppd.conf works

  * Fix a typo in ndppd.conf.5

  * Update "ndppd.conf" to reflect the big changes

  * Fix a bug with config loader

  * Fix so that "auto" will never forward a Neighbor Solicitation
    Message out through the "proxy" interface
  • Loading branch information
Daniel Adolfsson committed Feb 7, 2012
1 parent d51acba commit 13b81fd
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 62 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2012-02-06 Daniel Adolfsson <[email protected]>

* Version 0.2.2

* Removed "libconfuse" dependency.

* New "auto" configuration to detect outgoing interface, for forwarding
Neighbor Solicitation Messages.

* Improved logging.

* Bug fixes related to memory management.

2012-01-26 Daniel Adolfsson <[email protected]>

* Author changed e-mail address; updated copyright info.
Expand Down
52 changes: 31 additions & 21 deletions ndppd.conf-dist
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
# route-ttl <integer> (NEW)
# This tells 'ndppd' how often to reload the route file /proc/net/ipv6_route.
# Default value is '30000' (30 seconds).

route-ttl 30000

# proxy <interface>
# This sets up a listener, that will listen for any Neighbor Solicitation
# messages, and respond to them according to a set of rules (see below).
# <interface> is required.

# You may have several 'proxy' sections.
# <interface> is required. You may have several 'proxy' sections.

proxy eth0 {

# router = <yes|no|true|false>
# router <yes|no|true|false>
# This option turns on or off the router flag for Neighbor Advertisement
# messages. Default value is 'true'.

router = yes
router yes

# timeout = <integer>
# timeout <integer>
# Controls how long to wait for a Neighbor Advertisment message before
# invalidating the entry, in milliseconds. Default value is '500'.

timeout = 500
timeout 500

# ttl = <integer>
# ttl <integer>
# Controls how long a valid or invalid entry remains in the cache, in
# milliseconds. Default value is '30000' (30 seconds).

ttl = 30000
ttl 30000

# rule <ip>[/<mask>]
# This is a rule that the target address is to match against. If no netmask
# is provided, /128 is assumed. You may have several rule sections, and the
# addresses may or may not overlap.

rule 1111:: {
# Only one of 'static', 'auto' and 'interface' may be specified. Please
# read 'ndppd.conf' manpage for details about the methods below.

# iface = <interface>
# By setting this option, ndppd will forward the Neighbor Solicitation
# message to this interface and wait for a response. Only if a client
# responds with a Neighbor Advertisement message will the proxy respond.
# 'auto' should work in most cases.

# Note that if you do not provide an interface, this rule will match
# and immediately send a response through the proxy. It's recommended
# that you use the "iface" option as much as possible.
# static (NEW)
# 'ndppd' will immediately answer any Neighbor Solicitation Messages
# (if they match the IP rule).

# Using a prefix <= /120 without an interface will trigger a notice.
# iface <interface>
# 'ndppd' will forward the Neighbor Solicitation Message through the
# specified interface - and only respond if a matching Neighbor
# Advertisement Message is received.

# auto (NEW)
# Same as above, but instead of manually specifying the outgoing
# interface, 'ndppd' will check for a matching route in /proc/net/ipv6_route.

iface = eth1
}
auto

rule 1111::1/96 {
iface = eth2
# Note that before version 0.2.2 of 'ndppd', if you didn't choose a
# method, it defaulted to 'static'. For compatibility reasons we choose
# to keep this behavior - for now (it may be removed in a future version).
}
}
2 changes: 1 addition & 1 deletion ndppd.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ If this option is specified
.B ndppd
will attempt to detect which interface to use in order to forward
Neighbor Solicitation Messages, by reading the routing table
.BR /proc/sys/ipv6_route .
.BR /proc/net/ipv6_route .
.IP "static"
.B (NEW)
This option tells
Expand Down
58 changes: 23 additions & 35 deletions src/conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,27 @@ bool conf::is_block() const
return _is_block;
}

const char* conf::skip(const char* str, bool all)
const char* conf::skip(const char* str, bool newlines)
{
if (!all) {
while (*str && (*str != '\n') && isspace(*str))
str++;

return str;
}

while (*str) {
while (*str && isspace(*str))
while (*str && isspace(*str) && ((*str != '\n') || newlines))
str++;

if (!*str)
break;

if ((*str == '#') || ((*str == '/') && (*(str + 1) == '/'))) {
while (*str && (*str != '\n'))
while (*str && (*str != '\n')) {
str++;
continue;
}

if ((*str == '/') && (*(str + 1) == '*')) {
}
} else if ((*str == '/') && (*(str + 1) == '*')) {
while (*str) {
if ((*str == '*') && (*(str + 1) == '/')) {
str += 2;
break;
}
str++;
}
continue;
} else {
break;
}

break;
}

return str;
Expand All @@ -158,20 +145,23 @@ bool conf::parse_block(const char** str)
return true;
}

while (*p && isalpha(*p)) {
while (isalnum(*p) || (*p == '_') || (*p == '-')) {
ss << *p++;
}

p = skip(p);
p = skip(p, false);

if (*p == '=') {
p++;
p = skip(p, false);
}

ptr<conf> cf(new conf);

if (cf->parse(&p)) {
_map.insert(std::pair<std::string, ptr<conf> >(ss.str(), cf));
} else {
return false;
}
}

Expand All @@ -186,18 +176,14 @@ bool conf::parse(const char** str)

p = skip(p, false);

if (!*p) {
return false;
} else if ((*p == '\'') || (*p == '"')) {
for (char e = *p++; *p && (*p != e); p++)
ss <<* p;
} else if (isalnum(*p)) {
while (*p && (isalnum(*p) || strchr(":/.",* p)))
ss <<* p++;
if ((*p == '\'') || (*p == '"')) {
for (char e = *p++; *p && (*p != e) && (*p != '\n'); p++)
ss << *p;
p = skip(p, false);
} else {
_value = "";
*str = p;
return true;
while (*p && isgraph(*p) && (*p != '{') && (*p != '}')) {
ss << *p++;
}
}

_value = ss.str();
Expand All @@ -207,11 +193,13 @@ bool conf::parse(const char** str)
if (*p == '{') {
p++;

if (!parse_block(&p))
if (!parse_block(&p)) {
return false;
}

if (*p != '}')
if (*p != '}') {
return false;
}

p++;
}
Expand Down
12 changes: 9 additions & 3 deletions src/ndppd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,22 @@ int daemonize()

bool configure(const std::string& path)
{
ptr<conf> cf;
ptr<conf> cf, x_cf;

if (!(cf = conf::load(path)))
return false;

if (!(x_cf = cf->find("route-ttl")))
route::ttl(30000);
else
route::ttl(*x_cf);

std::vector<ptr<conf> >::const_iterator p_it;

std::vector<ptr<conf> > proxies(cf->find_all("proxy"));

for (p_it = proxies.begin(); p_it != proxies.end(); p_it++) {
ptr<conf> pr_cf =* p_it, x_cf;
ptr<conf> pr_cf = *p_it;

if (pr_cf->empty()) {
logger::error() << "'proxy' section is missing interface name";
Expand Down Expand Up @@ -221,7 +226,7 @@ int main(int argc, char* argv[], char* env[])
if (!configure(config_path))
return -1;

route::load("/proc/net/ipv6_route");
//route::load("/proc/net/ipv6_route");

// Time stuff.

Expand All @@ -247,6 +252,7 @@ int main(int argc, char* argv[], char* env[])
t1.tv_sec = t2.tv_sec;
t1.tv_usec = t2.tv_usec;

route::update(elapsed_time);
session::update_all(elapsed_time);
}

Expand Down
6 changes: 4 additions & 2 deletions src/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,

if (ru->is_auto()) {
ptr<iface> ifa = route::find_and_open(taddr);
// TODO: Check if it's a good interface.
if (ifa) {

// If we could find a route matching our rule in /proc/net/ipv6_route,
// and it's not the same interface as the one pr (proxy) is using.
if (ifa && (ifa != ru->ifa())) {
se->add_iface(ifa);
continue;
}
Expand Down
22 changes: 22 additions & 0 deletions src/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ NDPPD_NS_BEGIN

std::list<ptr<route> > route::_routes;

int route::_ttl;

int route::_c_ttl;

route::route(const address& addr, const std::string& ifname) :
_addr(addr), _ifname(ifname)
{
Expand Down Expand Up @@ -112,6 +116,14 @@ void route::load(const std::string& path)
}
}

void route::update(int elapsed_time)
{
if ((_c_ttl -= elapsed_time) <= 0) {
load("/proc/net/ipv6_route");
_c_ttl = _ttl;
}
}

ptr<route> route::create(const address& addr, const std::string& ifname)
{
ptr<route> rt(new route(addr, ifname));
Expand Down Expand Up @@ -162,5 +174,15 @@ const address& route::addr() const
return _addr;
}

int route::ttl()
{
return _ttl;
}

void route::ttl(int ttl)
{
_ttl = ttl;
}

NDPPD_NS_END

10 changes: 10 additions & 0 deletions src/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ class route {

static void load(const std::string& path);

static void update(int elapsed_time);

static int ttl();

static void ttl(int ttl);

const std::string& ifname() const;

const address& addr() const;

ptr<iface> ifa();

private:
static int _ttl;

static int _c_ttl;

address _addr;

std::string _ifname;
Expand Down

0 comments on commit 13b81fd

Please sign in to comment.