diff --git a/src/ndppd.c b/src/ndppd.c index af0ed39..5324940 100644 --- a/src/ndppd.c +++ b/src/ndppd.c @@ -33,7 +33,7 @@ #include "io.h" #include "ndppd.h" #include "proxy.h" -#include "rtnl.h" +#include "rt.h" #ifndef NDPPD_CONFIG_PATH # define NDPPD_CONFIG_PATH "../ndppd.conf" @@ -123,7 +123,7 @@ static bool ndL_daemonize() static void ndL_exit() { nd_iface_cleanup(); - nd_rtnl_cleanup(); + nd_rt_cleanup(); nd_alloc_cleanup(); } @@ -199,25 +199,25 @@ int main(int argc, char *argv[]) if (!nd_proxy_startup()) return -1; - if (!nd_rtnl_open()) + if (!nd_rt_open()) return -1; if (nd_opt_daemonize && !ndL_daemonize()) return -1; - nd_rtnl_query_routes(); + nd_rt_query_routes(); bool query_addresses = false; while (1) { - if (nd_current_time >= nd_rtnl_dump_timeout) - nd_rtnl_dump_timeout = 0; + if (nd_current_time >= nd_rt_dump_timeout) + nd_rt_dump_timeout = 0; - if (!query_addresses && !nd_rtnl_dump_timeout) + if (!query_addresses && !nd_rt_dump_timeout) { query_addresses = true; - nd_rtnl_query_addresses(); + nd_rt_query_addresses(); } if (!nd_io_poll()) diff --git a/src/proxy.c b/src/proxy.c index fe27636..cff18c1 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -23,7 +23,7 @@ #include "iface.h" #include "ndppd.h" #include "proxy.h" -#include "rtnl.h" +#include "rt.h" #include "rule.h" #include "session.h" @@ -107,7 +107,7 @@ void nd_proxy_handle_ns(nd_proxy_t *proxy, nd_addr_t *src, __attribute__((unused { /* TODO: Loop through valid routes. */ - nd_rtnl_route_t *route = nd_rtnl_find_route(tgt, rule->table); + nd_rt_route_t *route = nd_rt_find_route(tgt, rule->table); if (!route || route->oif == proxy->iface->index) { diff --git a/src/rtnl.c b/src/rt.c similarity index 85% rename from src/rtnl.c rename to src/rt.c index 1ec2806..ed00f46 100644 --- a/src/rtnl.c +++ b/src/rt.c @@ -33,17 +33,17 @@ #include "addr.h" #include "io.h" #include "ndppd.h" -#include "rtnl.h" +#include "rt.h" static nd_io_t *ndL_io; -static nd_rtnl_route_t *ndL_routes, *ndL_free_routes; -static nd_rtnl_addr_t *ndL_addrs, *ndL_free_addrs; +static nd_rt_route_t *ndL_routes, *ndL_free_routes; +static nd_rt_addr_t *ndL_addrs, *ndL_free_addrs; -long nd_rtnl_dump_timeout; +long nd_rt_dump_timeout; -static void ndL_add_route(unsigned int oif, nd_addr_t *dst, int pflen, int table) +static void ndL_new_route(unsigned int oif, nd_addr_t *dst, int pflen, int table) { - nd_rtnl_route_t *route; + nd_rt_route_t *route; ND_LL_FOREACH_NODEF(ndL_routes, route, next) { @@ -54,7 +54,7 @@ static void ndL_add_route(unsigned int oif, nd_addr_t *dst, int pflen, int table if ((route = ndL_free_routes)) ND_LL_DELETE(ndL_free_routes, route, next); else - route = ND_ALLOC(nd_rtnl_route_t); + route = ND_ALLOC(nd_rt_route_t); route->addr = *dst; route->pflen = pflen; @@ -65,7 +65,7 @@ static void ndL_add_route(unsigned int oif, nd_addr_t *dst, int pflen, int table * This will ensure the linked list is kept sorted, so it will be easier to find a match. */ - nd_rtnl_route_t *prev = NULL; + nd_rt_route_t *prev = NULL; ND_LL_FOREACH(ndL_routes, cur, next) { @@ -85,12 +85,12 @@ static void ndL_add_route(unsigned int oif, nd_addr_t *dst, int pflen, int table ND_LL_PREPEND(ndL_routes, route, next); } - nd_log_debug("rtnl: NEWROUTE %s/%d dev %d table %d", nd_aton(dst), pflen, oif, table); + nd_log_debug("rt: new route %s/%d dev %d table %d", nd_aton(dst), pflen, oif, table); } -static void ndL_remove_route(unsigned int oif, nd_addr_t *dst, int pflen, int table) +static void ndL_delete_route(unsigned int oif, nd_addr_t *dst, int pflen, int table) { - nd_rtnl_route_t *prev = NULL, *route; + nd_rt_route_t *prev = NULL, *route; ND_LL_FOREACH_NODEF(ndL_routes, route, next) { @@ -108,13 +108,13 @@ static void ndL_remove_route(unsigned int oif, nd_addr_t *dst, int pflen, int ta else ndL_routes = route->next; - nd_log_debug("rtnl: DELROUTE %s/%d dev %d table %d", nd_aton(dst), pflen, oif, table); + nd_log_debug("rt: delete route %s/%d dev %d table %d", nd_aton(dst), pflen, oif, table); ND_LL_PREPEND(ndL_free_routes, route, next); } -static void ndL_add_addr(unsigned int index, nd_addr_t *addr, int pflen) +static void ndL_new_addr(unsigned int index, nd_addr_t *addr, int pflen) { - nd_rtnl_addr_t *rt_addr; + nd_rt_addr_t *rt_addr; ND_LL_FOREACH_NODEF(ndL_addrs, rt_addr, next) { @@ -125,7 +125,7 @@ static void ndL_add_addr(unsigned int index, nd_addr_t *addr, int pflen) if ((rt_addr = ndL_free_addrs)) ND_LL_DELETE(ndL_free_addrs, rt_addr, next); else - rt_addr = ND_ALLOC(nd_rtnl_addr_t); + rt_addr = ND_ALLOC(nd_rt_addr_t); ND_LL_PREPEND(ndL_addrs, rt_addr, next); @@ -133,18 +133,18 @@ static void ndL_add_addr(unsigned int index, nd_addr_t *addr, int pflen) rt_addr->iif = index; rt_addr->addr = *addr; - nd_log_debug("rtnl: NEWADDR %s/%d if %d", nd_aton(addr), pflen, index); + nd_log_debug("rt: new address %s/%d if %d", nd_aton(addr), pflen, index); } -static void ndL_remove_addr(unsigned int index, nd_addr_t *addr, int pflen) +static void ndL_delete_addr(unsigned int index, nd_addr_t *addr, int pflen) { - nd_rtnl_addr_t *prev = NULL, *rt_addr; + nd_rt_addr_t *prev = NULL, *rt_addr; ND_LL_FOREACH_NODEF(ndL_addrs, rt_addr, next) { if (rt_addr->iif == index && nd_addr_eq(&rt_addr->addr, addr) && rt_addr->pflen == pflen) { - nd_log_debug("rtnl: DELADDR %s/%d if %d", nd_aton(addr), pflen, index); + nd_log_debug("rt: delete address %s/%d if %d", nd_aton(addr), pflen, index); if (prev) prev->next = rt_addr->next; @@ -159,7 +159,6 @@ static void ndL_remove_addr(unsigned int index, nd_addr_t *addr, int pflen) } } - #ifdef __linux__ static void ndL_handle_newaddr(struct ifaddrmsg *msg, int length) { @@ -174,7 +173,7 @@ static void ndL_handle_newaddr(struct ifaddrmsg *msg, int length) if (!addr) return; - ndL_add_addr(msg->ifa_index, addr, msg->ifa_prefixlen); + ndL_new_addr(msg->ifa_index, addr, msg->ifa_prefixlen); } static void ndL_handle_deladdr(struct ifaddrmsg *msg, int length) @@ -190,7 +189,7 @@ static void ndL_handle_deladdr(struct ifaddrmsg *msg, int length) if (!addr) return; - ndL_remove_addr(msg->ifa_index, addr, msg->ifa_prefixlen); + ndL_delete_addr(msg->ifa_index, addr, msg->ifa_prefixlen); } static void ndL_handle_newroute(struct rtmsg *msg, int rtl) @@ -209,7 +208,7 @@ static void ndL_handle_newroute(struct rtmsg *msg, int rtl) if (!dst || !oif) return; - ndL_add_route(oif, dst, msg->rtm_dst_len, msg->rtm_table); + ndL_new_route(oif, dst, msg->rtm_dst_len, msg->rtm_table); } static void ndL_handle_delroute(struct rtmsg *msg, int rtl) @@ -228,7 +227,7 @@ static void ndL_handle_delroute(struct rtmsg *msg, int rtl) if (!dst || !oif) return; - ndL_remove_route(oif, dst, msg->rtm_dst_len, msg->rtm_table); + ndL_delete_route(oif, dst, msg->rtm_dst_len, msg->rtm_table); } static void ndL_io_handler(__attribute__((unused)) nd_io_t *unused1, __attribute__((unused)) int unused2) @@ -247,14 +246,14 @@ static void ndL_io_handler(__attribute__((unused)) nd_io_t *unused1, __attribute { if (hdr->nlmsg_type == NLMSG_DONE) { - nd_rtnl_dump_timeout = 0; + nd_rt_dump_timeout = 0; break; } if (hdr->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); - nd_log_error("rtnl: Error \"%s\", type=%d", strerror(-e->error), e->msg.nlmsg_type); + nd_log_error("rt: Error \"%s\", type=%d", strerror(-e->error), e->msg.nlmsg_type); continue; } @@ -298,16 +297,16 @@ static void ndL_handle_rt(struct rt_msghdr *hdr) nd_addr_t *dst = &((struct sockaddr_in6 *)rtas[RTAX_DST])->sin6_addr; -#ifdef __FreeBSD__ +# ifdef __FreeBSD__ int tableid = 0; -#else +# else int tableid = hdr->rtm_tableid; -#endif +# endif if (hdr->rtm_type == RTM_GET || hdr->rtm_type == RTM_ADD) - ndL_add_route(hdr->rtm_index, dst, pflen, tableid); + ndL_new_route(hdr->rtm_index, dst, pflen, tableid); else if (hdr->rtm_type == RTM_DELETE) - ndL_remove_route(hdr->rtm_index, dst, pflen, tableid); + ndL_delete_route(hdr->rtm_index, dst, pflen, tableid); } static void ndL_handle_ifa(struct ifa_msghdr *hdr) @@ -323,9 +322,9 @@ static void ndL_handle_ifa(struct ifa_msghdr *hdr) nd_addr_t *ifa = &((struct sockaddr_in6 *)rtas[RTAX_IFA])->sin6_addr; if (hdr->ifam_type == RTM_NEWADDR) - ndL_add_addr(hdr->ifam_index, ifa, pflen); + ndL_new_addr(hdr->ifam_index, ifa, pflen); else if (hdr->ifam_type == RTM_DELADDR) - ndL_remove_addr(hdr->ifam_index, ifa, pflen); + ndL_delete_addr(hdr->ifam_index, ifa, pflen); } typedef struct @@ -406,7 +405,7 @@ static void ndL_io_handler(__attribute__((unused)) nd_io_t *unused1, __attribute #endif -bool nd_rtnl_open() +bool nd_rt_open() { if (ndL_io != NULL) return true; @@ -443,16 +442,16 @@ bool nd_rtnl_open() return true; } -void nd_rtnl_cleanup() +void nd_rt_cleanup() { if (ndL_io) nd_io_close(ndL_io); } -bool nd_rtnl_query_routes() +bool nd_rt_query_routes() { #ifdef __linux__ - if (nd_rtnl_dump_timeout) + if (nd_rt_dump_timeout) return false; struct @@ -475,7 +474,7 @@ bool nd_rtnl_query_routes() memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; - nd_rtnl_dump_timeout = nd_current_time + 5000; + nd_rt_dump_timeout = nd_current_time + 5000; nd_io_send(ndL_io, (struct sockaddr *)&addr, sizeof(addr), &req, sizeof(req)); return true; @@ -484,10 +483,10 @@ bool nd_rtnl_query_routes() #endif } -bool nd_rtnl_query_addresses() +bool nd_rt_query_addresses() { #ifdef __linux__ - if (nd_rtnl_dump_timeout) + if (nd_rt_dump_timeout) return false; struct @@ -509,7 +508,7 @@ bool nd_rtnl_query_addresses() memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; - nd_rtnl_dump_timeout = nd_current_time + 5000; + nd_rt_dump_timeout = nd_current_time + 5000; nd_io_send(ndL_io, (struct sockaddr *)&addr, sizeof(addr), &req, sizeof(req)); return true; @@ -518,7 +517,7 @@ bool nd_rtnl_query_addresses() #endif } -nd_rtnl_route_t *nd_rtnl_find_route(nd_addr_t *addr, int table) +nd_rt_route_t *nd_rt_find_route(nd_addr_t *addr, int table) { ND_LL_FOREACH(ndL_routes, route, next) { diff --git a/src/rtnl.h b/src/rt.h similarity index 66% rename from src/rtnl.h rename to src/rt.h index f2d89d0..73d4ad5 100644 --- a/src/rtnl.h +++ b/src/rt.h @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with ndppd. If not, see . */ -#ifndef NDPPD_RTNL_H -#define NDPPD_RTNL_H +#ifndef NDPPD_RT_H +#define NDPPD_RT_H #include "ndppd.h" -typedef struct nd_rtnl_route nd_rtnl_route_t; -typedef struct nd_rtnl_addr nd_rtnl_addr_t; +typedef struct nd_rt_route nd_rt_route_t; +typedef struct nd_rt_addr nd_rt_addr_t; -struct nd_rtnl_route +struct nd_rt_route { - nd_rtnl_route_t *next; + nd_rt_route_t *next; nd_addr_t addr; unsigned int oif; int pflen; @@ -34,20 +34,20 @@ struct nd_rtnl_route int metrics; }; -struct nd_rtnl_addr +struct nd_rt_addr { - nd_rtnl_addr_t *next; + nd_rt_addr_t *next; unsigned int iif; nd_addr_t addr; int pflen; }; -extern long nd_rtnl_dump_timeout; +extern long nd_rt_dump_timeout; -bool nd_rtnl_open(); -void nd_rtnl_cleanup(); -bool nd_rtnl_query_addresses(); -bool nd_rtnl_query_routes(); -nd_rtnl_route_t *nd_rtnl_find_route(nd_addr_t *addr, int table); +bool nd_rt_open(); +void nd_rt_cleanup(); +bool nd_rt_query_addresses(); +bool nd_rt_query_routes(); +nd_rt_route_t *nd_rt_find_route(nd_addr_t *addr, int table); -#endif /* NDPPD_RTNL_H */ +#endif /*NDPPD_RT_H*/