From decb3de44c59f789e49250c4d2791e4219078b54 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Wed, 18 Nov 2015 18:43:30 +0300 Subject: ipoe: for vlan name pattern implemented %P argument - VID of parent interface --- accel-pppd/libnetlink/iputils.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'accel-pppd/libnetlink/iputils.c') diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c index 480f028f..7dbdf677 100644 --- a/accel-pppd/libnetlink/iputils.c +++ b/accel-pppd/libnetlink/iputils.c @@ -243,6 +243,60 @@ int __export iplink_vlan_del(int ifindex) return 0; } +int __export iplink_vlan_get_vid(int ifindex) +{ + struct iplink_req { + struct nlmsghdr n; + struct ifinfomsg i; + char buf[4096]; + } req; + struct ifinfomsg *ifi; + int len; + struct rtattr *tb[IFLA_MAX + 1]; + + if (!rth) + open_rth(); + + if (!rth) + return -1; + + memset(&req, 0, sizeof(req) - 4096); + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); + req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + req.n.nlmsg_type = RTM_GETLINK; + req.i.ifi_family = AF_PACKET; + req.i.ifi_index = ifindex; + + if (rtnl_talk(rth, &req.n, 0, 0, &req.n, NULL, NULL, 0) < 0) + return -1; + + if (req.n.nlmsg_type != RTM_NEWLINK) + return -1; + + ifi = NLMSG_DATA(&req.n); + + len = req.n.nlmsg_len; + + len -= NLMSG_LENGTH(sizeof(*ifi)); + if (len < 0) + return -1; + + parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); + + if (!tb[IFLA_LINKINFO]) + return 0; + + parse_rtattr_nested(tb, IFLA_MAX, tb[IFLA_LINKINFO]); + + if (strcmp(RTA_DATA(tb[IFLA_INFO_KIND]), "vlan")) + return 0; + + parse_rtattr_nested(tb, IFLA_MAX, tb[IFLA_INFO_DATA]); + return *(uint16_t *)RTA_DATA(tb[IFLA_VLAN_ID]); +} + + int __export ipaddr_add(int ifindex, in_addr_t addr, int mask) { struct ipaddr_req { -- cgit v1.2.3