netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC net-next] rocker: by default accept untagged packets
@ 2015-05-26  0:55 Simon Horman
  2015-05-26  7:28 ` Scott Feldman
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Horman @ 2015-05-26  0:55 UTC (permalink / raw)
  To: Scott Feldman, Jiri Pirko, David Miller; +Cc: netdev, Simon Horman

This will occur anyway if the 8021q module is loaded as it will
call rocker_port_vlan_rx_add_vid for vlan 0. This code is here
to handle the case where the 8021q module is not loaded.

This patch also handles the case where the 8021q is unloaded
removing all VLANs from all ports.

This change should not affect bridging, although the rules are
harmlessly installed anyway. This is in keeping with the behaviour
for VLANs when the 8021q modules is loaded.

To aid implementation of the above provide a helper
and use it to replace some existing code.

Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 drivers/net/ethernet/rocker/rocker.c | 51 +++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/rocker/rocker.c b/drivers/net/ethernet/rocker/rocker.c
index 36f7edfc3c7a..bc00e0abd8b6 100644
--- a/drivers/net/ethernet/rocker/rocker.c
+++ b/drivers/net/ethernet/rocker/rocker.c
@@ -3720,6 +3720,19 @@ static int rocker_port_router_mac(struct rocker_port *rocker_port,
 	return err;
 }
 
+static int rocker_port_vlan_rx_vid(struct rocker_port *rocker_port,
+				   enum switchdev_trans trans, int flag,
+				   u16 vid)
+{
+	int err;
+
+	err = rocker_port_vlan(rocker_port, trans, flag, vid);
+	if (err)
+		return err;
+
+	return rocker_port_router_mac(rocker_port, trans, flag, htons(vid));
+}
+
 static int rocker_port_fwding(struct rocker_port *rocker_port,
 			      enum switchdev_trans trans)
 {
@@ -4009,6 +4022,16 @@ static int rocker_port_open(struct net_device *dev)
 		goto err_request_rx_irq;
 	}
 
+	/* By default accept untagged vlan packets.
+	 *
+	 * This will occur anyway if the 8021q module is loaded as it will
+	 * call rocker_port_vlan_rx_add_vid for vlan 0. This code is here
+	 * to handle the case where the 8021q module is not loaded.
+	 */
+	err = rocker_port_vlan_rx_vid(rocker_port, SWITCHDEV_TRANS_NONE, 0, 0);
+	if (err)
+		goto err_fwd_enable;
+
 	err = rocker_port_fwd_enable(rocker_port, SWITCHDEV_TRANS_NONE);
 	if (err)
 		goto err_fwd_enable;
@@ -4187,29 +4210,33 @@ static int rocker_port_vlan_rx_add_vid(struct net_device *dev,
 				       __be16 proto, u16 vid)
 {
 	struct rocker_port *rocker_port = netdev_priv(dev);
-	int err;
-
-	err = rocker_port_vlan(rocker_port, SWITCHDEV_TRANS_NONE, 0, vid);
-	if (err)
-		return err;
 
-	return rocker_port_router_mac(rocker_port, SWITCHDEV_TRANS_NONE,
-				      0, htons(vid));
+	return rocker_port_vlan_rx_vid(rocker_port, SWITCHDEV_TRANS_NONE,
+				       0, vid);
 }
 
 static int rocker_port_vlan_rx_kill_vid(struct net_device *dev,
 					__be16 proto, u16 vid)
 {
 	struct rocker_port *rocker_port = netdev_priv(dev);
-	int err;
+	int err, i;
 
-	err = rocker_port_router_mac(rocker_port, SWITCHDEV_TRANS_NONE,
-				     ROCKER_OP_FLAG_REMOVE, htons(vid));
+	err = rocker_port_vlan_rx_vid(rocker_port, SWITCHDEV_TRANS_NONE,
+				      ROCKER_OP_FLAG_REMOVE, vid);
 	if (err)
 		return err;
 
-	return rocker_port_vlan(rocker_port, SWITCHDEV_TRANS_NONE,
-				ROCKER_OP_FLAG_REMOVE, vid);
+	/* If no vlans are set then the last one has been removed;
+	 * restore the default behaviour of accepting untagged packets.
+	 *
+	 * This may occur if the 8021q module is unloaded.
+	 */
+	for (i = 0; i < ROCKER_VLAN_BITMAP_LEN; i++)
+		if (rocker_port->vlan_bitmap[i])
+			return 0;
+	return rocker_port_vlan_rx_vid(rocker_port, SWITCHDEV_TRANS_NONE,
+				       0, 0);
+
 }
 
 static int rocker_port_get_phys_port_name(struct net_device *dev,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-27  7:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-26  0:55 [PATCH/RFC net-next] rocker: by default accept untagged packets Simon Horman
2015-05-26  7:28 ` Scott Feldman
2015-05-26  9:04   ` Scott Feldman
2015-05-27  1:07     ` Simon Horman
2015-05-27  7:34       ` Scott Feldman
2015-05-27  7:42         ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).