Fix compilation problems and issue #20

- Netlink is disabled per default (compile with WITH_ND_NETLINK)

- Automatic loading of routes is only done if at least one rule
  uses the "auto" setting.
This commit is contained in:
Daniel Adolfsson 2017-05-08 12:31:13 +02:00
parent ce3815d954
commit 8a8f7b065c
5 changed files with 34 additions and 5 deletions

View File

@ -11,13 +11,17 @@ MANDIR ?= ${DESTDIR}${PREFIX}/share/man
SBINDIR ?= ${DESTDIR}${PREFIX}/sbin
PKG_CONFIG ?= pkg-config
LIBS = `${PKG_CONFIG} --libs glib-2.0 libnl-3.0 libnl-route-3.0` -pthread
CPPFLAGS = `${PKG_CONFIG} --cflags glib-2.0 libnl-3.0 libnl-route-3.0`
OBJS = src/logger.o src/ndppd.o src/iface.o src/proxy.o src/address.o \
src/rule.o src/session.o src/conf.o src/route.o src/nd-netlink.o
src/rule.o src/session.o src/conf.o src/route.o
all: ndppd ndppd.1.gz ndppd.conf.5.gz nd-proxy
ifdef WITH_ND_NETLINK
LIBS = `${PKG_CONFIG} --libs glib-2.0 libnl-3.0 libnl-route-3.0` -pthread
CPPFLAGS = `${PKG_CONFIG} --cflags glib-2.0 libnl-3.0 libnl-route-3.0`
OBJ = ${OBJ} src/nd-netlink.o
endif
all: ndppd ndppd.1.gz ndppd.conf.5.gz
install: all
mkdir -p ${SBINDIR} ${MANDIR} ${MANDIR}/man1 ${MANDIR}/man5

View File

@ -286,7 +286,9 @@ int main(int argc, char* argv[], char* env[])
gettimeofday(&t1, 0);
#ifdef WITH_ND_NETLINK
netlink_setup();
#endif
while (running) {
if (iface::poll_all() < 0) {
@ -306,11 +308,16 @@ int main(int argc, char* argv[], char* env[])
t1.tv_sec = t2.tv_sec;
t1.tv_usec = t2.tv_usec;
if (rule::any_auto())
route::update(elapsed_time);
session::update_all(elapsed_time);
}
#ifdef WITH_ND_NETLINK
netlink_teardown();
#endif
logger::notice() << "Bye";
return 0;

View File

@ -126,11 +126,13 @@ void proxy::handle_solicit(const address& saddr, const address& daddr,
return;
} else {
se->add_iface((*it)->ifa());
#ifdef WITH_ND_NETLINK
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();
}
#endif
}
}
}

View File

@ -27,6 +27,8 @@ NDPPD_NS_BEGIN
std::vector<interface> interfaces;
bool rule::_any_aut = false;
rule::rule()
{
}
@ -42,9 +44,13 @@ ptr<rule> rule::create(const ptr<proxy>& pr, const address& addr, const ptr<ifac
unsigned int ifindex;
ifindex = if_nametoindex(pr->ifa()->name().c_str());
#ifdef WITH_ND_NETLINK
if_add_to_list(ifindex, pr->ifa());
#endif
ifindex = if_nametoindex(ifa->name().c_str());
#ifdef WITH_ND_NETLINK
if_add_to_list(ifindex, ifa);
#endif
logger::debug() << "rule::create() if=" << pr->ifa()->name() << ", addr=" << addr;
@ -58,6 +64,7 @@ ptr<rule> rule::create(const ptr<proxy>& pr, const address& addr, bool aut)
ru->_pr = pr;
ru->_addr = addr;
ru->_aut = aut;
_any_aut = _any_aut || aut;
logger::debug()
<< "rule::create() if=" << pr->ifa()->name().c_str() << ", addr=" << addr
@ -81,6 +88,11 @@ bool rule::is_auto() const
return _aut;
}
bool rule::any_auto()
{
return _any_aut;
}
bool rule::check(const address& addr) const
{
return _addr == addr;

View File

@ -43,6 +43,8 @@ public:
bool check(const address& addr) const;
static bool any_auto();
private:
weak_ptr<rule> _ptr;
@ -54,6 +56,8 @@ private:
bool _aut;
static bool _any_aut;
rule();
};