Skip to content

Commit

Permalink
Remove "owned" routes
Browse files Browse the repository at this point in the history
For now, owned routes are simply routes that have protocol 72 on Linux,
or PROTO3 flag on BSD. This first implementation removes all owned routes
when ndppd starts. #32
  • Loading branch information
DanielAdolfsson committed Dec 14, 2019
1 parent f31f2c1 commit b87c50b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/ndppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,17 @@ int main(int argc, char *argv[])
return -1;

nd_rt_query_routes();

bool query_addresses = false;
bool querying_routes = true;

while (1)
{
if (nd_current_time >= nd_rt_dump_timeout)
nd_rt_dump_timeout = 0;

if (!query_addresses && !nd_rt_dump_timeout)
if (querying_routes && !nd_rt_dump_timeout)
{
query_addresses = true;
querying_routes = false;
nl_rt_remove_owned_routes();
nd_rt_query_addresses();
}

Expand Down
23 changes: 20 additions & 3 deletions src/rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ static nd_io_t *ndL_io;
// All IPV6 routes on the system.
static nd_rt_route_t *ndL_routes;

// All routes that have been created by ndppd.
__attribute__((unused)) static nd_rt_route_t *ndL_owned_routes;

// Freelist.
static nd_rt_route_t *ndL_free_routes;

Expand Down Expand Up @@ -576,6 +573,8 @@ bool nd_rt_add_route(nd_addr_t *dst, unsigned pflen, unsigned oif, unsigned tabl
uint32_t oif;
struct rtattr dst_attr __attribute__((aligned(RTA_ALIGNTO)));
nd_addr_t dst;
//struct rtattr exp_attr __attribute__((aligned(RTA_ALIGNTO)));
//uint32_t exp;
} req;

memset(&req, 0, sizeof(req));
Expand All @@ -589,10 +588,15 @@ bool nd_rt_add_route(nd_addr_t *dst, unsigned pflen, unsigned oif, unsigned tabl
req.oif_attr.rta_type = RTA_OIF;
req.oif_attr.rta_len = RTA_LENGTH(sizeof(req.oif));
req.oif = oif;

req.dst_attr.rta_type = RTA_DST;
req.dst_attr.rta_len = RTA_LENGTH(sizeof(req.dst));
req.dst = *dst;

//req.exp_attr.rta_type = RTA_EXPIRES;
//req.exp_attr.rta_len = RTA_LENGTH(sizeof(req.exp));
//req.exp = 60;

req.hdr.nlmsg_type = RTM_NEWROUTE;
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
req.hdr.nlmsg_len = sizeof(req);
Expand Down Expand Up @@ -620,6 +624,7 @@ bool nd_rt_add_route(nd_addr_t *dst, unsigned pflen, unsigned oif, unsigned tabl
msg.hdr.rtm_msglen = sizeof(msg);
msg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
msg.hdr.rtm_index = oif;

# ifdef __FreeBSD__
(void)table;
# else
Expand Down Expand Up @@ -688,6 +693,7 @@ bool nd_rt_remove_route(nd_addr_t *dst, unsigned pflen, unsigned table)
req.hdr.rtm_pid = getpid();
req.hdr.rtm_msglen = sizeof(req);
req.hdr.rtm_addrs = RTA_DST | RTA_NETMASK;

# ifdef __FreeBSD__
(void)table;
# else
Expand All @@ -702,6 +708,17 @@ bool nd_rt_remove_route(nd_addr_t *dst, unsigned pflen, unsigned table)
req.mask.sin6_len = sizeof(req.mask);
nd_mask_from_pflen(pflen, &req.mask.sin6_addr);

nd_log_info("rt: Removing route %s/%d table %d", nd_aton(dst), pflen, table);

return nd_io_write(ndL_io, &req, sizeof(req)) >= 0;
#endif
}

void nl_rt_remove_owned_routes()
{
ND_LL_FOREACH_S(ndL_routes, route, tmp, next)
{
if (route->owned)
nd_rt_remove_route(&route->dst, route->pflen, route->table);
}
}
1 change: 1 addition & 0 deletions src/rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ bool nd_rt_query_routes();
nd_rt_route_t *nd_rt_find_route(nd_addr_t *addr, unsigned table);
bool nd_rt_add_route(nd_addr_t *dst, unsigned pflen, unsigned oif, unsigned table);
bool nd_rt_remove_route(nd_addr_t *dst, unsigned pflen, unsigned table);
void nl_rt_remove_owned_routes();

#endif // NDPPD_RT_H

0 comments on commit b87c50b

Please sign in to comment.