diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2017-12-25 17:52:37 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2017-12-25 17:52:37 +0300 |
commit | 2369a4f0049e91dc62914693bea104b3fc54f557 (patch) | |
tree | 3874740759eb370027a88da6f95e40091b9bb5a8 /accel-pppd | |
parent | 2e06c8c9278ab283907f3bb9d1fa28c5edb5f1e4 (diff) | |
download | accel-ppp-2369a4f0049e91dc62914693bea104b3fc54f557.tar.gz accel-ppp-2369a4f0049e91dc62914693bea104b3fc54f557.zip |
libnetlink: added ip6addr_add_peer function
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/libnetlink/iputils.c | 34 | ||||
-rw-r--r-- | accel-pppd/libnetlink/iputils.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c index 601b8954..93716330 100644 --- a/accel-pppd/libnetlink/iputils.c +++ b/accel-pppd/libnetlink/iputils.c @@ -639,6 +639,40 @@ int __export ip6addr_add(int ifindex, struct in6_addr *addr, int prefix_len) return r; } +int __export ip6addr_add_peer(int ifindex, struct in6_addr *addr, struct in6_addr *peer) +{ + struct ipaddr_req { + struct nlmsghdr n; + struct ifaddrmsg i; + char buf[4096]; + } req; + struct rtnl_handle *rth = net->rtnl_get(); + int r = 0; + + if (!rth) + return -1; + + memset(&req, 0, sizeof(req) - 4096); + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE; + req.n.nlmsg_type = RTM_NEWADDR; + req.i.ifa_family = AF_INET6; + req.i.ifa_index = ifindex; + req.i.ifa_prefixlen = 128; + req.i.ifa_flags = IFA_F_NODAD; + + addattr_l(&req.n, sizeof(req), IFA_LOCAL, addr, 16); + addattr_l(&req.n, sizeof(req), IFA_ADDRESS, peer, 16); + + if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) + r = -1; + + net->rtnl_put(rth); + + return r; +} + int __export ip6addr_del(int ifindex, struct in6_addr *addr, int prefix_len) { struct ipaddr_req { diff --git a/accel-pppd/libnetlink/iputils.h b/accel-pppd/libnetlink/iputils.h index 9bdc93da..3211cfb7 100644 --- a/accel-pppd/libnetlink/iputils.h +++ b/accel-pppd/libnetlink/iputils.h @@ -25,6 +25,7 @@ in_addr_t iproute_get(in_addr_t dst, in_addr_t *gw); int ip6route_add(int ifindex, struct in6_addr *dst, int prefix_len, int proto); int ip6route_del(int ifindex, struct in6_addr *dst, int prefix_len); int ip6addr_add(int ifindex, struct in6_addr *addr, int prefix_len); +int ip6addr_add_peer(int ifindex, struct in6_addr *addr, struct in6_addr *peer_addr); int ip6addr_del(int ifindex, struct in6_addr *addr, int prefix_len); int iprule_add(uint32_t addr, int table); |