Skip to content

Commit

Permalink
bridge: Add netlink support for vlan_protocol attribute
Browse files Browse the repository at this point in the history
This enables bridge vlan_protocol to be configured through netlink.

When CONFIG_BRIDGE_VLAN_FILTERING is disabled, kernel behaves the
same way as this feature is not implemented.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Toshiaki Makita authored and David S. Miller committed Aug 27, 2015
1 parent 9c9a652 commit d2d427b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/uapi/linux/if_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ enum {
IFLA_BR_STP_STATE,
IFLA_BR_PRIORITY,
IFLA_BR_VLAN_FILTERING,
IFLA_BR_VLAN_PROTOCOL,
__IFLA_BR_MAX,
};

Expand Down
34 changes: 34 additions & 0 deletions net/bridge/br_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,21 @@ static int br_validate(struct nlattr *tb[], struct nlattr *data[])
return -EADDRNOTAVAIL;
}

if (!data)
return 0;

#ifdef CONFIG_BRIDGE_VLAN_FILTERING
if (data[IFLA_BR_VLAN_PROTOCOL]) {
switch (nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL])) {
case htons(ETH_P_8021Q):
case htons(ETH_P_8021AD):
break;
default:
return -EPROTONOSUPPORT;
}
}
#endif

return 0;
}

Expand Down Expand Up @@ -729,6 +744,7 @@ static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
[IFLA_BR_STP_STATE] = { .type = NLA_U32 },
[IFLA_BR_PRIORITY] = { .type = NLA_U16 },
[IFLA_BR_VLAN_FILTERING] = { .type = NLA_U8 },
[IFLA_BR_VLAN_PROTOCOL] = { .type = NLA_U16 },
};

static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
Expand Down Expand Up @@ -784,6 +800,16 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
return err;
}

#ifdef CONFIG_BRIDGE_VLAN_FILTERING
if (data[IFLA_BR_VLAN_PROTOCOL]) {
__be16 vlan_proto = nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL]);

err = __br_vlan_set_proto(br, vlan_proto);
if (err)
return err;
}
#endif

return 0;
}

Expand All @@ -796,6 +822,9 @@ static size_t br_get_size(const struct net_device *brdev)
nla_total_size(sizeof(u32)) + /* IFLA_BR_STP_STATE */
nla_total_size(sizeof(u16)) + /* IFLA_BR_PRIORITY */
nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_FILTERING */
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
nla_total_size(sizeof(__be16)) + /* IFLA_BR_VLAN_PROTOCOL */
#endif
0;
}

Expand All @@ -819,6 +848,11 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
nla_put_u8(skb, IFLA_BR_VLAN_FILTERING, vlan_enabled))
return -EMSGSIZE;

#ifdef CONFIG_BRIDGE_VLAN_FILTERING
if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto))
return -EMSGSIZE;
#endif

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions net/bridge/br_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ bool br_vlan_find(struct net_bridge *br, u16 vid);
void br_recalculate_fwd_mask(struct net_bridge *br);
int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
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);
Expand Down
35 changes: 21 additions & 14 deletions net/bridge/br_vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,16 @@ int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
return 0;
}

int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
int __br_vlan_set_proto(struct net_bridge *br, __be16 proto)
{
int err = 0;
struct net_bridge_port *p;
struct net_port_vlans *pv;
__be16 proto, oldproto;
__be16 oldproto;
u16 vid, errvid;

if (val != ETH_P_8021Q && val != ETH_P_8021AD)
return -EPROTONOSUPPORT;

if (!rtnl_trylock())
return restart_syscall();

proto = htons(val);
if (br->vlan_proto == proto)
goto unlock;
return 0;

/* Add VLANs for the new proto to the device filter. */
list_for_each_entry(p, &br->port_list, list) {
Expand Down Expand Up @@ -539,9 +532,7 @@ int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
vlan_vid_del(p->dev, oldproto, vid);
}

unlock:
rtnl_unlock();
return err;
return 0;

err_filt:
errvid = vid;
Expand All @@ -557,7 +548,23 @@ int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
vlan_vid_del(p->dev, proto, vid);
}

goto unlock;
return err;
}

int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
{
int err;

if (val != ETH_P_8021Q && val != ETH_P_8021AD)
return -EPROTONOSUPPORT;

if (!rtnl_trylock())
return restart_syscall();

err = __br_vlan_set_proto(br, htons(val));
rtnl_unlock();

return err;
}

static bool vlan_default_pvid(struct net_port_vlans *pv, u16 vid)
Expand Down

0 comments on commit d2d427b

Please sign in to comment.