diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2016-01-03 23:09:20 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2016-01-03 23:09:20 +0300 |
commit | 0ba262d4bf906b8fd6b724264c69933309bedd74 (patch) | |
tree | 62506d4e1b62a2237d57390ee751c58fb22ee5d4 /accel-pppd/libnetlink/iputils.c | |
parent | 849840d80532276e5ce51db8a0762559ea3be860 (diff) | |
download | accel-ppp-0ba262d4bf906b8fd6b724264c69933309bedd74.tar.gz accel-ppp-0ba262d4bf906b8fd6b724264c69933309bedd74.zip |
iputils: improved iproute_add and iproute_del functions
Diffstat (limited to 'accel-pppd/libnetlink/iputils.c')
-rw-r--r-- | accel-pppd/libnetlink/iputils.c | 14 |
1 files changed, 8 insertions, 6 deletions
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; |