[PATCH v6 2/3] net: switchdev: Add VLAN protocol support for switchdev port
From: hongbo . wang
Date: Wed Sep 16 2020 - 05:46:23 EST
From: "hongbo.wang" <hongbo.wang@xxxxxxx>
Add VLAN protocol support when adding or deleting VLAN for switchdev
port, get current bridge's VLAN protocol and pass it to port driver.
Signed-off-by: hongbo.wang <hongbo.wang@xxxxxxx>
---
net/bridge/br_switchdev.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 015209bf44aa..7712da3e7912 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -146,6 +146,26 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
}
}
+static u16 br_switchdev_get_bridge_vlan_proto(const struct net_device *dev)
+{
+ const struct net_device *br = NULL;
+ u16 vlan_proto = ETH_P_8021Q;
+ struct net_bridge_port *p;
+
+ if (netif_is_bridge_master(dev)) {
+ br = dev;
+ } else {
+ p = br_port_get_rtnl_rcu(dev);
+ if (p)
+ br = p->br->dev;
+ }
+
+ if (br)
+ br_vlan_get_proto(br, &vlan_proto);
+
+ return vlan_proto;
+}
+
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
struct netlink_ext_ack *extack)
{
@@ -157,6 +177,8 @@ int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
.vid_end = vid,
};
+ v.proto = br_switchdev_get_bridge_vlan_proto(dev);
+
return switchdev_port_obj_add(dev, &v.obj, extack);
}
@@ -169,5 +191,7 @@ int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
.vid_end = vid,
};
+ v.proto = br_switchdev_get_bridge_vlan_proto(dev);
+
return switchdev_port_obj_del(dev, &v.obj);
}
--
2.17.1