bridge: netlink: add group_addr support
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Sun, 4 Oct 2015 12:23:35 +0000 (14:23 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 4 Oct 2015 23:45:59 +0000 (16:45 -0700)
Add IFLA_BR_GROUP_ADDR attribute to allow setting and retrieving the
group_addr 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

index a1e33282ab9d528b14fdd402409436205f35c394..eaeaac17dfdd1b1ff3b2532e1371bdb7dfbf58d2 100644 (file)
@@ -243,6 +243,7 @@ enum {
        IFLA_BR_TCN_TIMER,
        IFLA_BR_TOPOLOGY_CHANGE_TIMER,
        IFLA_BR_GC_TIMER,
+       IFLA_BR_GROUP_ADDR,
        __IFLA_BR_MAX,
 };
 
index 755bfe0ab4043420a6612af314bba25eb3592237..a05a4306d42d9901128c7a369a9f1b53822de8b6 100644 (file)
@@ -765,6 +765,8 @@ static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
        [IFLA_BR_VLAN_FILTERING] = { .type = NLA_U8 },
        [IFLA_BR_VLAN_PROTOCOL] = { .type = NLA_U16 },
        [IFLA_BR_GROUP_FWD_MASK] = { .type = NLA_U16 },
+       [IFLA_BR_GROUP_ADDR] = { .type = NLA_BINARY,
+                                .len  = ETH_ALEN },
 };
 
 static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
@@ -838,6 +840,25 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
                br->group_fwd_mask = fwd_mask;
        }
 
+       if (data[IFLA_BR_GROUP_ADDR]) {
+               u8 new_addr[ETH_ALEN];
+
+               if (nla_len(data[IFLA_BR_GROUP_ADDR]) != ETH_ALEN)
+                       return -EINVAL;
+               memcpy(new_addr, nla_data(data[IFLA_BR_GROUP_ADDR]), ETH_ALEN);
+               if (!is_link_local_ether_addr(new_addr))
+                       return -EINVAL;
+               if (new_addr[5] == 1 ||         /* 802.3x Pause address */
+                   new_addr[5] == 2 ||         /* 802.3ad Slow protocols */
+                   new_addr[5] == 3)           /* 802.1X PAE address */
+                       return -EINVAL;
+               spin_lock_bh(&br->lock);
+               memcpy(br->group_addr, new_addr, sizeof(br->group_addr));
+               spin_unlock_bh(&br->lock);
+               br->group_addr_set = true;
+               br_recalculate_fwd_mask(br);
+       }
+
        return 0;
 }
 
@@ -864,6 +885,7 @@ static size_t br_get_size(const struct net_device *brdev)
               nla_total_size(sizeof(u64)) +    /* IFLA_BR_TCN_TIMER */
               nla_total_size(sizeof(u64)) +    /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */
               nla_total_size(sizeof(u64)) +    /* IFLA_BR_GC_TIMER */
+              nla_total_size(ETH_ALEN) +       /* IFLA_BR_GROUP_ADDR */
               0;
 }
 
@@ -911,7 +933,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
            nla_put_u64(skb, IFLA_BR_TCN_TIMER, tcn_timer) ||
            nla_put_u64(skb, IFLA_BR_TOPOLOGY_CHANGE_TIMER,
                        topology_change_timer) ||
-           nla_put_u64(skb, IFLA_BR_GC_TIMER, gc_timer))
+           nla_put_u64(skb, IFLA_BR_GC_TIMER, gc_timer) ||
+           nla_put(skb, IFLA_BR_GROUP_ADDR, ETH_ALEN, br->group_addr))
                return -EMSGSIZE;
 
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING