diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2016-03-18 15:22:55 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2016-03-18 15:22:55 +0300 |
commit | d9e66279652a9e6639d5a82581bcc0fd7d999aff (patch) | |
tree | effa1cd1bb6ca7ac8425ae7a72974f6df546d3b6 /accel-pppd/ctrl/ipoe/ipoe_netlink.c | |
parent | dbebb99e532822ae70a68dd8f6bc27cce52fc47e (diff) | |
download | accel-ppp-d9e66279652a9e6639d5a82581bcc0fd7d999aff.tar.gz accel-ppp-d9e66279652a9e6639d5a82581bcc0fd7d999aff.zip |
ipoe: restored local-net function
local-net is used to filter incomming packets which may start UP session
Diffstat (limited to 'accel-pppd/ctrl/ipoe/ipoe_netlink.c')
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe_netlink.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe_netlink.c b/accel-pppd/ctrl/ipoe/ipoe_netlink.c index 7e61fb84..9372a94c 100644 --- a/accel-pppd/ctrl/ipoe/ipoe_netlink.c +++ b/accel-pppd/ctrl/ipoe/ipoe_netlink.c @@ -98,6 +98,76 @@ void ipoe_nl_del_exclude(uint32_t addr) rtnl_close(&rth); } +int ipoe_nl_add_net(uint32_t addr, int mask) +{ + struct rtnl_handle rth; + struct nlmsghdr *nlh; + struct genlmsghdr *ghdr; + struct { + struct nlmsghdr n; + char buf[1024]; + } req; + int ret = 0; + + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { + log_ppp_error("ipoe: cannot open generic netlink socket\n"); + return -1; + } + + nlh = &req.n; + nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + nlh->nlmsg_type = ipoe_genl_id; + + ghdr = NLMSG_DATA(&req.n); + ghdr->cmd = IPOE_CMD_ADD_NET; + + mask = mask ? ~0 << (32 - mask) : 0; + + addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr); + addattr32(nlh, 1024, IPOE_ATTR_MASK, mask); + + if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) { + log_ppp_error("ipoe: nl_add_net: error talking to kernel\n"); + ret = -1; + } + + rtnl_close(&rth); + + return ret; +} + +void ipoe_nl_del_net(uint32_t addr) +{ + struct rtnl_handle rth; + struct nlmsghdr *nlh; + struct genlmsghdr *ghdr; + struct { + struct nlmsghdr n; + char buf[1024]; + } req; + + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { + log_ppp_error("ipoe: cannot open generic netlink socket\n"); + return; + } + + nlh = &req.n; + nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + nlh->nlmsg_type = ipoe_genl_id; + + ghdr = NLMSG_DATA(&req.n); + ghdr->cmd = IPOE_CMD_DEL_NET; + + addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr); + + if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) + log_ppp_error("ipoe: nl_del_net: error talking to kernel\n"); + + rtnl_close(&rth); +} + void ipoe_nl_add_interface(int ifindex, uint8_t mode) { struct rtnl_handle rth; @@ -544,6 +614,7 @@ static void init(void) triton_context_wakeup(&mc_ctx); ipoe_nl_del_exclude(0); + ipoe_nl_del_net(0); ipoe_nl_delete_interfaces(); } |