bridge: netlink: add support for default_pvid
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Sun, 4 Oct 2015 12:23:47 +0000 (14:23 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 4 Oct 2015 23:46:07 +0000 (16:46 -0700)
Add IFLA_BR_VLAN_DEFAULT_PVID to allow setting/getting bridge's
default_pvid via netlink.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/if_link.h
net/bridge/br_netlink.c
net/bridge/br_private.h
net/bridge/br_vlan.c

index 0200bed6e5d67b54a5719b1b270fe58013531512..c5b15bfeabe2196d0bd92a01e1356a6ab3a038e2 100644 (file)
@@ -262,6 +262,7 @@ enum {
        IFLA_BR_NF_CALL_IPTABLES,
        IFLA_BR_NF_CALL_IP6TABLES,
        IFLA_BR_NF_CALL_ARPTABLES,
+       IFLA_BR_VLAN_DEFAULT_PVID,
        __IFLA_BR_MAX,
 };
 
index fd37caf02b51a89ecc5e557e61328b7d5e6e26b1..70efe2edde2bf77d25f3a585fdcce0ea51748cf1 100644 (file)
@@ -784,6 +784,7 @@ static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
        [IFLA_BR_NF_CALL_IPTABLES] = { .type = NLA_U8 },
        [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NLA_U8 },
        [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NLA_U8 },
+       [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NLA_U16 },
 };
 
 static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
@@ -847,6 +848,14 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
                if (err)
                        return err;
        }
+
+       if (data[IFLA_BR_VLAN_DEFAULT_PVID]) {
+               __u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]);
+
+               err = __br_vlan_set_default_pvid(br, defpvid);
+               if (err)
+                       return err;
+       }
 #endif
 
        if (data[IFLA_BR_GROUP_FWD_MASK]) {
@@ -1007,6 +1016,7 @@ static size_t br_get_size(const struct net_device *brdev)
               nla_total_size(sizeof(u8)) +     /* IFLA_BR_VLAN_FILTERING */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
               nla_total_size(sizeof(__be16)) + /* IFLA_BR_VLAN_PROTOCOL */
+              nla_total_size(sizeof(u16)) +    /* IFLA_BR_VLAN_DEFAULT_PVID */
 #endif
               nla_total_size(sizeof(u16)) +    /* IFLA_BR_GROUP_FWD_MASK */
               nla_total_size(sizeof(struct ifla_bridge_id)) +   /* IFLA_BR_ROOT_ID */
@@ -1094,7 +1104,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
                return -EMSGSIZE;
 
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
-       if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto))
+       if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) ||
+           nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid))
                return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
index 1ff6a0faef3f0626cfa7073a9f66f39c91de68bf..09d3ecbcb4f02046430788e4c885aa49acbeb219 100644 (file)
@@ -690,6 +690,7 @@ int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
 int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
 int br_vlan_init(struct net_bridge *br);
 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
+int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
 void nbp_vlan_flush(struct net_bridge_port *port);
index b879111582f0d6aaf9531c1713eadae5aa0541fa..eae07ee9bfe00c9661f7e227e72d083ca3dcbc19 100644 (file)
@@ -727,7 +727,7 @@ static void br_vlan_disable_default_pvid(struct net_bridge *br)
        br->default_pvid = 0;
 }
 
-static int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
+int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
 {
        const struct net_bridge_vlan *pvent;
        struct net_bridge_port *p;
@@ -735,6 +735,11 @@ static int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
        int err = 0;
        unsigned long *changed;
 
+       if (!pvid) {
+               br_vlan_disable_default_pvid(br);
+               return 0;
+       }
+
        changed = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
                          GFP_KERNEL);
        if (!changed)
@@ -825,12 +830,7 @@ int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
                err = -EPERM;
                goto unlock;
        }
-
-       if (!pvid)
-               br_vlan_disable_default_pvid(br);
-       else
-               err = __br_vlan_set_default_pvid(br, pvid);
-
+       err = __br_vlan_set_default_pvid(br, pvid);
 unlock:
        rtnl_unlock();
        return err;