Rename rtnl to rt

This commit is contained in:
Daniel Adolfsson 2019-12-13 12:58:41 +01:00
parent 7d8330b9be
commit b9652aa6cc
4 changed files with 66 additions and 67 deletions

View File

@ -33,7 +33,7 @@
#include "io.h" #include "io.h"
#include "ndppd.h" #include "ndppd.h"
#include "proxy.h" #include "proxy.h"
#include "rtnl.h" #include "rt.h"
#ifndef NDPPD_CONFIG_PATH #ifndef NDPPD_CONFIG_PATH
# define NDPPD_CONFIG_PATH "../ndppd.conf" # define NDPPD_CONFIG_PATH "../ndppd.conf"
@ -123,7 +123,7 @@ static bool ndL_daemonize()
static void ndL_exit() static void ndL_exit()
{ {
nd_iface_cleanup(); nd_iface_cleanup();
nd_rtnl_cleanup(); nd_rt_cleanup();
nd_alloc_cleanup(); nd_alloc_cleanup();
} }
@ -199,25 +199,25 @@ int main(int argc, char *argv[])
if (!nd_proxy_startup()) if (!nd_proxy_startup())
return -1; return -1;
if (!nd_rtnl_open()) if (!nd_rt_open())
return -1; return -1;
if (nd_opt_daemonize && !ndL_daemonize()) if (nd_opt_daemonize && !ndL_daemonize())
return -1; return -1;
nd_rtnl_query_routes(); nd_rt_query_routes();
bool query_addresses = false; bool query_addresses = false;
while (1) while (1)
{ {
if (nd_current_time >= nd_rtnl_dump_timeout) if (nd_current_time >= nd_rt_dump_timeout)
nd_rtnl_dump_timeout = 0; nd_rt_dump_timeout = 0;
if (!query_addresses && !nd_rtnl_dump_timeout) if (!query_addresses && !nd_rt_dump_timeout)
{ {
query_addresses = true; query_addresses = true;
nd_rtnl_query_addresses(); nd_rt_query_addresses();
} }
if (!nd_io_poll()) if (!nd_io_poll())

View File

@ -23,7 +23,7 @@
#include "iface.h" #include "iface.h"
#include "ndppd.h" #include "ndppd.h"
#include "proxy.h" #include "proxy.h"
#include "rtnl.h" #include "rt.h"
#include "rule.h" #include "rule.h"
#include "session.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. */ /* 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) if (!route || route->oif == proxy->iface->index)
{ {

View File

@ -33,17 +33,17 @@
#include "addr.h" #include "addr.h"
#include "io.h" #include "io.h"
#include "ndppd.h" #include "ndppd.h"
#include "rtnl.h" #include "rt.h"
static nd_io_t *ndL_io; static nd_io_t *ndL_io;
static nd_rtnl_route_t *ndL_routes, *ndL_free_routes; static nd_rt_route_t *ndL_routes, *ndL_free_routes;
static nd_rtnl_addr_t *ndL_addrs, *ndL_free_addrs; 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) 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)) if ((route = ndL_free_routes))
ND_LL_DELETE(ndL_free_routes, route, next); ND_LL_DELETE(ndL_free_routes, route, next);
else else
route = ND_ALLOC(nd_rtnl_route_t); route = ND_ALLOC(nd_rt_route_t);
route->addr = *dst; route->addr = *dst;
route->pflen = pflen; 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. * 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) 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_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) 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 else
ndL_routes = route->next; 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); 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) 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)) if ((rt_addr = ndL_free_addrs))
ND_LL_DELETE(ndL_free_addrs, rt_addr, next); ND_LL_DELETE(ndL_free_addrs, rt_addr, next);
else 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); 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->iif = index;
rt_addr->addr = *addr; 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) 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) 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) if (prev)
prev->next = rt_addr->next; 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__ #ifdef __linux__
static void ndL_handle_newaddr(struct ifaddrmsg *msg, int length) 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) if (!addr)
return; 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) 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) if (!addr)
return; 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) 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) if (!dst || !oif)
return; 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) 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) if (!dst || !oif)
return; 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) 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) if (hdr->nlmsg_type == NLMSG_DONE)
{ {
nd_rtnl_dump_timeout = 0; nd_rt_dump_timeout = 0;
break; break;
} }
if (hdr->nlmsg_type == NLMSG_ERROR) if (hdr->nlmsg_type == NLMSG_ERROR)
{ {
struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(hdr); 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; 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; nd_addr_t *dst = &((struct sockaddr_in6 *)rtas[RTAX_DST])->sin6_addr;
#ifdef __FreeBSD__ # ifdef __FreeBSD__
int tableid = 0; int tableid = 0;
#else # else
int tableid = hdr->rtm_tableid; int tableid = hdr->rtm_tableid;
#endif # endif
if (hdr->rtm_type == RTM_GET || hdr->rtm_type == RTM_ADD) 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) 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) 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; nd_addr_t *ifa = &((struct sockaddr_in6 *)rtas[RTAX_IFA])->sin6_addr;
if (hdr->ifam_type == RTM_NEWADDR) 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) 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 typedef struct
@ -406,7 +405,7 @@ static void ndL_io_handler(__attribute__((unused)) nd_io_t *unused1, __attribute
#endif #endif
bool nd_rtnl_open() bool nd_rt_open()
{ {
if (ndL_io != NULL) if (ndL_io != NULL)
return true; return true;
@ -443,16 +442,16 @@ bool nd_rtnl_open()
return true; return true;
} }
void nd_rtnl_cleanup() void nd_rt_cleanup()
{ {
if (ndL_io) if (ndL_io)
nd_io_close(ndL_io); nd_io_close(ndL_io);
} }
bool nd_rtnl_query_routes() bool nd_rt_query_routes()
{ {
#ifdef __linux__ #ifdef __linux__
if (nd_rtnl_dump_timeout) if (nd_rt_dump_timeout)
return false; return false;
struct struct
@ -475,7 +474,7 @@ bool nd_rtnl_query_routes()
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK; 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)); nd_io_send(ndL_io, (struct sockaddr *)&addr, sizeof(addr), &req, sizeof(req));
return true; return true;
@ -484,10 +483,10 @@ bool nd_rtnl_query_routes()
#endif #endif
} }
bool nd_rtnl_query_addresses() bool nd_rt_query_addresses()
{ {
#ifdef __linux__ #ifdef __linux__
if (nd_rtnl_dump_timeout) if (nd_rt_dump_timeout)
return false; return false;
struct struct
@ -509,7 +508,7 @@ bool nd_rtnl_query_addresses()
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK; 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)); nd_io_send(ndL_io, (struct sockaddr *)&addr, sizeof(addr), &req, sizeof(req));
return true; return true;
@ -518,7 +517,7 @@ bool nd_rtnl_query_addresses()
#endif #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) ND_LL_FOREACH(ndL_routes, route, next)
{ {

View File

@ -16,17 +16,17 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with ndppd. If not, see <https://www.gnu.org/licenses/>. * along with ndppd. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef NDPPD_RTNL_H #ifndef NDPPD_RT_H
#define NDPPD_RTNL_H #define NDPPD_RT_H
#include "ndppd.h" #include "ndppd.h"
typedef struct nd_rtnl_route nd_rtnl_route_t; typedef struct nd_rt_route nd_rt_route_t;
typedef struct nd_rtnl_addr nd_rtnl_addr_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; nd_addr_t addr;
unsigned int oif; unsigned int oif;
int pflen; int pflen;
@ -34,20 +34,20 @@ struct nd_rtnl_route
int metrics; int metrics;
}; };
struct nd_rtnl_addr struct nd_rt_addr
{ {
nd_rtnl_addr_t *next; nd_rt_addr_t *next;
unsigned int iif; unsigned int iif;
nd_addr_t addr; nd_addr_t addr;
int pflen; int pflen;
}; };
extern long nd_rtnl_dump_timeout; extern long nd_rt_dump_timeout;
bool nd_rtnl_open(); bool nd_rt_open();
void nd_rtnl_cleanup(); void nd_rt_cleanup();
bool nd_rtnl_query_addresses(); bool nd_rt_query_addresses();
bool nd_rtnl_query_routes(); bool nd_rt_query_routes();
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);
#endif /* NDPPD_RTNL_H */ #endif /*NDPPD_RT_H*/