From 0ba262d4bf906b8fd6b724264c69933309bedd74 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Sun, 3 Jan 2016 23:09:20 +0300 Subject: iputils: improved iproute_add and iproute_del functions --- accel-pppd/libnetlink/iputils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'accel-pppd/libnetlink/iputils.c') diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c index 8118ce6..e9b8285 100644 --- a/accel-pppd/libnetlink/iputils.c +++ b/accel-pppd/libnetlink/iputils.c @@ -366,7 +366,7 @@ int __export ipaddr_del(int ifindex, in_addr_t addr, int mask) return 0; } -int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto) +int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto, int mask) { struct ipaddr_req { struct nlmsghdr n; @@ -390,7 +390,7 @@ int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw req.i.rtm_scope = ifindex ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE; req.i.rtm_protocol = proto; req.i.rtm_type = RTN_UNICAST; - req.i.rtm_dst_len = 32; + req.i.rtm_dst_len = mask; if (ifindex) addattr32(&req.n, sizeof(req), RTA_OIF, ifindex); @@ -406,7 +406,7 @@ int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw return 0; } -int __export iproute_del(int ifindex, in_addr_t dst, int proto) +int __export iproute_del(int ifindex, in_addr_t dst, int proto, int mask) { struct ipaddr_req { struct nlmsghdr n; @@ -427,13 +427,15 @@ int __export iproute_del(int ifindex, in_addr_t dst, int proto) req.n.nlmsg_type = RTM_DELROUTE; req.i.rtm_family = AF_INET; req.i.rtm_table = RT_TABLE_MAIN; - req.i.rtm_scope = RT_SCOPE_LINK; + req.i.rtm_scope = ifindex ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE; req.i.rtm_protocol = proto; req.i.rtm_type = RTN_UNICAST; - req.i.rtm_dst_len = 32; + req.i.rtm_dst_len = mask; addattr32(&req.n, sizeof(req), RTA_DST, dst); - addattr32(&req.n, sizeof(req), RTA_OIF, ifindex); + + if (ifindex) + addattr32(&req.n, sizeof(req), RTA_OIF, ifindex); if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; -- cgit v1.2.3