diff --git a/Makefile b/Makefile index 7f37eca..adaff80 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/ndppd.cc b/src/ndppd.cc index fe6f05b..e645421 100644 --- a/src/ndppd.cc +++ b/src/ndppd.cc @@ -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; - route::update(elapsed_time); + 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; diff --git a/src/proxy.cc b/src/proxy.cc index d3b6e66..2de5a3e 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -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 } } } diff --git a/src/rule.cc b/src/rule.cc index ad4a7ec..3bd66ba 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -27,6 +27,8 @@ NDPPD_NS_BEGIN std::vector interfaces; +bool rule::_any_aut = false; + rule::rule() { } @@ -42,9 +44,13 @@ ptr rule::create(const ptr& pr, const address& addr, const ptrifa()->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::create(const ptr& 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; diff --git a/src/rule.h b/src/rule.h index 72c30ea..384b05c 100644 --- a/src/rule.h +++ b/src/rule.h @@ -43,6 +43,8 @@ public: bool check(const address& addr) const; + static bool any_auto(); + private: weak_ptr _ptr; @@ -54,6 +56,8 @@ private: bool _aut; + static bool _any_aut; + rule(); };