Commit 552406c4 authored by Vlad Yasevich's avatar Vlad Yasevich Committed by David S. Miller

bridge: Add the ability to configure pvid

A user may designate a certain vlan as PVID.  This means that
any ingress frame that does not contain a vlan tag is assigned to
this vlan and any forwarding decisions are made with this vlan in mind.
Signed-off-by: default avatarVlad Yasevich <vyasevic@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 78851988
...@@ -120,6 +120,7 @@ enum { ...@@ -120,6 +120,7 @@ enum {
#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
#define BRIDGE_VLAN_INFO_MASTER (1<<0) /* Operate on Bridge device as well */ #define BRIDGE_VLAN_INFO_MASTER (1<<0) /* Operate on Bridge device as well */
#define BRIDGE_VLAN_INFO_PVID (1<<1) /* VLAN is PVID, ingress untagged */
struct bridge_vlan_info { struct bridge_vlan_info {
u16 flags; u16 flags;
......
...@@ -120,6 +120,7 @@ static int br_fill_ifinfo(struct sk_buff *skb, ...@@ -120,6 +120,7 @@ static int br_fill_ifinfo(struct sk_buff *skb,
const struct net_port_vlans *pv; const struct net_port_vlans *pv;
struct bridge_vlan_info vinfo; struct bridge_vlan_info vinfo;
u16 vid; u16 vid;
u16 pvid;
if (port) if (port)
pv = nbp_get_vlan_info(port); pv = nbp_get_vlan_info(port);
...@@ -133,12 +134,15 @@ static int br_fill_ifinfo(struct sk_buff *skb, ...@@ -133,12 +134,15 @@ static int br_fill_ifinfo(struct sk_buff *skb,
if (!af) if (!af)
goto nla_put_failure; goto nla_put_failure;
pvid = br_get_pvid(pv);
for (vid = find_first_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN); for (vid = find_first_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN);
vid < BR_VLAN_BITMAP_LEN; vid < BR_VLAN_BITMAP_LEN;
vid = find_next_bit(pv->vlan_bitmap, vid = find_next_bit(pv->vlan_bitmap,
BR_VLAN_BITMAP_LEN, vid+1)) { BR_VLAN_BITMAP_LEN, vid+1)) {
vinfo.vid = vid; vinfo.vid = vid;
vinfo.flags = 0; vinfo.flags = 0;
if (vid == pvid)
vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
sizeof(vinfo), &vinfo)) sizeof(vinfo), &vinfo))
goto nla_put_failure; goto nla_put_failure;
...@@ -239,14 +243,15 @@ static int br_afspec(struct net_bridge *br, ...@@ -239,14 +243,15 @@ static int br_afspec(struct net_bridge *br,
switch (cmd) { switch (cmd) {
case RTM_SETLINK: case RTM_SETLINK:
if (p) { if (p) {
err = nbp_vlan_add(p, vinfo->vid); err = nbp_vlan_add(p, vinfo->vid, vinfo->flags);
if (err) if (err)
break; break;
if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER) if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
err = br_vlan_add(p->br, vinfo->vid); err = br_vlan_add(p->br, vinfo->vid,
vinfo->flags);
} else } else
err = br_vlan_add(br, vinfo->vid); err = br_vlan_add(br, vinfo->vid, vinfo->flags);
if (err) if (err)
break; break;
......
...@@ -562,11 +562,11 @@ extern bool br_allowed_egress(struct net_bridge *br, ...@@ -562,11 +562,11 @@ extern bool br_allowed_egress(struct net_bridge *br,
extern struct sk_buff *br_handle_vlan(struct net_bridge *br, extern struct sk_buff *br_handle_vlan(struct net_bridge *br,
const struct net_port_vlans *v, const struct net_port_vlans *v,
struct sk_buff *skb); struct sk_buff *skb);
extern int br_vlan_add(struct net_bridge *br, u16 vid); extern int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
extern int br_vlan_delete(struct net_bridge *br, u16 vid); extern int br_vlan_delete(struct net_bridge *br, u16 vid);
extern void br_vlan_flush(struct net_bridge *br); extern void br_vlan_flush(struct net_bridge *br);
extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid); extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
extern void nbp_vlan_flush(struct net_bridge_port *port); extern void nbp_vlan_flush(struct net_bridge_port *port);
...@@ -633,7 +633,7 @@ static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, ...@@ -633,7 +633,7 @@ static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
return skb; return skb;
} }
static inline int br_vlan_add(struct net_bridge *br, u16 vid) static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -647,7 +647,7 @@ static inline void br_vlan_flush(struct net_bridge *br) ...@@ -647,7 +647,7 @@ static inline void br_vlan_flush(struct net_bridge *br)
{ {
} }
static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid) static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -5,12 +5,33 @@ ...@@ -5,12 +5,33 @@
#include "br_private.h" #include "br_private.h"
static int __vlan_add(struct net_port_vlans *v, u16 vid) static void __vlan_add_pvid(struct net_port_vlans *v, u16 vid)
{
if (v->pvid == vid)
return;
smp_wmb();
v->pvid = vid;
}
static void __vlan_delete_pvid(struct net_port_vlans *v, u16 vid)
{
if (v->pvid != vid)
return;
smp_wmb();
v->pvid = 0;
}
static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
{ {
int err; int err;
if (test_bit(vid, v->vlan_bitmap)) if (test_bit(vid, v->vlan_bitmap)) {
return -EEXIST; if (flags & BRIDGE_VLAN_INFO_PVID)
__vlan_add_pvid(v, vid);
return 0;
}
if (v->port_idx && vid) { if (v->port_idx && vid) {
struct net_device *dev = v->parent.port->dev; struct net_device *dev = v->parent.port->dev;
...@@ -29,6 +50,9 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid) ...@@ -29,6 +50,9 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid)
set_bit(vid, v->vlan_bitmap); set_bit(vid, v->vlan_bitmap);
v->num_vlans++; v->num_vlans++;
if (flags & BRIDGE_VLAN_INFO_PVID)
__vlan_add_pvid(v, vid);
return 0; return 0;
} }
...@@ -37,6 +61,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid) ...@@ -37,6 +61,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
if (!test_bit(vid, v->vlan_bitmap)) if (!test_bit(vid, v->vlan_bitmap))
return -EINVAL; return -EINVAL;
__vlan_delete_pvid(v, vid);
if (v->port_idx && vid) { if (v->port_idx && vid) {
struct net_device *dev = v->parent.port->dev; struct net_device *dev = v->parent.port->dev;
...@@ -58,6 +84,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid) ...@@ -58,6 +84,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
static void __vlan_flush(struct net_port_vlans *v) static void __vlan_flush(struct net_port_vlans *v)
{ {
smp_wmb();
v->pvid = 0;
bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN); bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
if (v->port_idx) if (v->port_idx)
rcu_assign_pointer(v->parent.port->vlan_info, NULL); rcu_assign_pointer(v->parent.port->vlan_info, NULL);
...@@ -185,7 +213,7 @@ bool br_allowed_egress(struct net_bridge *br, ...@@ -185,7 +213,7 @@ bool br_allowed_egress(struct net_bridge *br,
} }
/* Must be protected by RTNL */ /* Must be protected by RTNL */
int br_vlan_add(struct net_bridge *br, u16 vid) int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
{ {
struct net_port_vlans *pv = NULL; struct net_port_vlans *pv = NULL;
int err; int err;
...@@ -194,7 +222,7 @@ int br_vlan_add(struct net_bridge *br, u16 vid) ...@@ -194,7 +222,7 @@ int br_vlan_add(struct net_bridge *br, u16 vid)
pv = rtnl_dereference(br->vlan_info); pv = rtnl_dereference(br->vlan_info);
if (pv) if (pv)
return __vlan_add(pv, vid); return __vlan_add(pv, vid, flags);
/* Create port vlan infomration /* Create port vlan infomration
*/ */
...@@ -203,7 +231,7 @@ int br_vlan_add(struct net_bridge *br, u16 vid) ...@@ -203,7 +231,7 @@ int br_vlan_add(struct net_bridge *br, u16 vid)
return -ENOMEM; return -ENOMEM;
pv->parent.br = br; pv->parent.br = br;
err = __vlan_add(pv, vid); err = __vlan_add(pv, vid, flags);
if (err) if (err)
goto out; goto out;
...@@ -234,7 +262,6 @@ void br_vlan_flush(struct net_bridge *br) ...@@ -234,7 +262,6 @@ void br_vlan_flush(struct net_bridge *br)
struct net_port_vlans *pv; struct net_port_vlans *pv;
ASSERT_RTNL(); ASSERT_RTNL();
pv = rtnl_dereference(br->vlan_info); pv = rtnl_dereference(br->vlan_info);
if (!pv) if (!pv)
return; return;
...@@ -258,7 +285,7 @@ int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) ...@@ -258,7 +285,7 @@ int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
} }
/* Must be protected by RTNL */ /* Must be protected by RTNL */
int nbp_vlan_add(struct net_bridge_port *port, u16 vid) int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
{ {
struct net_port_vlans *pv = NULL; struct net_port_vlans *pv = NULL;
int err; int err;
...@@ -267,7 +294,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid) ...@@ -267,7 +294,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid)
pv = rtnl_dereference(port->vlan_info); pv = rtnl_dereference(port->vlan_info);
if (pv) if (pv)
return __vlan_add(pv, vid); return __vlan_add(pv, vid, flags);
/* Create port vlan infomration /* Create port vlan infomration
*/ */
...@@ -279,7 +306,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid) ...@@ -279,7 +306,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid)
pv->port_idx = port->port_no; pv->port_idx = port->port_no;
pv->parent.port = port; pv->parent.port = port;
err = __vlan_add(pv, vid); err = __vlan_add(pv, vid, flags);
if (err) if (err)
goto clean_up; goto clean_up;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment