X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=system-linux.c;h=f4721cc8902cb6e8043c05cb350a659027e2eb4a;hp=744742279efc719a2f1e666947b08153de0f89da;hb=59217785704fca27d2c7a19e279d27c384a452cd;hpb=f8981d9933683e1a8314fa86ac610f8e9a22661c diff --git a/system-linux.c b/system-linux.c index 7447422..f4721cc 100644 --- a/system-linux.c +++ b/system-linux.c @@ -3,6 +3,7 @@ * Copyright (C) 2012 Felix Fietkau * Copyright (C) 2013 Jo-Philipp Wich * Copyright (C) 2013 Steven Barth + * Copyright (C) 2014 Gioacchino Mazzurco * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -36,6 +37,7 @@ #include #include #include +#include #ifndef RTN_FAILED_POLICY #define RTN_FAILED_POLICY 12 @@ -802,6 +804,81 @@ int system_vlan_del(struct device *dev) return system_vlan(dev, -1); } +int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg) +{ + struct nl_msg *msg; + struct nlattr *linkinfo, *data; + struct ifinfomsg iim = { .ifi_family = AF_INET }; + int ifindex = system_if_resolve(dev); + int rv; + + if (ifindex == 0) + return -ENOENT; + + msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); + + if (!msg) + return -1; + + nlmsg_append(msg, &iim, sizeof(iim), 0); + nla_put(msg, IFLA_IFNAME, IFNAMSIZ, vlandev->ifname); + nla_put_u32(msg, IFLA_LINK, ifindex); + + if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO))) + goto nla_put_failure; + + nla_put(msg, IFLA_INFO_KIND, strlen("vlan"), "vlan"); + + + if (!(data = nla_nest_start(msg, IFLA_INFO_DATA))) + goto nla_put_failure; + + nla_put_u16(msg, IFLA_VLAN_ID, cfg->vid); + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) + nla_put_u16(msg, IFLA_VLAN_PROTOCOL, htons(cfg->proto)); +#else + if(cfg->proto == VLAN_PROTO_8021AD) + netifd_log_message(L_WARNING, "%s Your kernel is older than linux 3.10.0, 802.1ad is not supported defaulting to 802.1q", vlandev->type->name); +#endif + + nla_nest_end(msg, data); + nla_nest_end(msg, linkinfo); + + rv = system_rtnl_call(msg); + if (rv) + D(SYSTEM, "Error adding vlandev '%s' over '%s': %d\n", vlandev->ifname, dev->ifname, rv); + + return rv; + +nla_put_failure: + nlmsg_free(msg); + return -ENOMEM; +} + +int system_vlandev_del(struct device *vlandev) +{ + struct nl_msg *msg; + struct ifinfomsg iim; + + iim.ifi_family = AF_INET; + iim.ifi_index = 0; + + msg = nlmsg_alloc_simple(RTM_DELLINK, 0); + + if (!msg) + return -1; + + nlmsg_append(msg, &iim, sizeof(iim), 0); + + nla_put(msg, IFLA_INFO_KIND, strlen("vlan"), "vlan"); + nla_put(msg, IFLA_IFNAME, sizeof(vlandev->ifname), vlandev->ifname); + + system_rtnl_call(msg); + + return 0; +} + static void system_if_get_settings(struct device *dev, struct device_settings *s) {