netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: jiri@resnulli.us, nikolay@cumulusnetworks.com,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH v2 rfc 5/8] net: dsa: switch: handle host mdb add/remove
Date: Wed,  6 Sep 2017 01:35:07 +0200	[thread overview]
Message-ID: <1504654510-31004-6-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1504654510-31004-1-git-send-email-andrew@lunn.ch>

When receiving notifications of the host mdb add/remove, add/remove an
mdb to the CPU port, so that traffic flows from a port to the CPU port
and hence to the host.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/switch.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 60 insertions(+), 12 deletions(-)

diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index e6c06aa349a6..326680039c52 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -108,22 +108,14 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
 				     info->vid);
 }
 
-static int dsa_switch_mdb_add(struct dsa_switch *ds,
-			      struct dsa_notifier_mdb_info *info)
+static int dsa_switch_mdb_add_bitmap(struct dsa_switch *ds,
+				     struct dsa_notifier_mdb_info *info,
+				     const struct switchdev_obj_port_mdb *mdb,
+				     unsigned long *group)
 {
-	const struct switchdev_obj_port_mdb *mdb = info->mdb;
 	struct switchdev_trans *trans = info->trans;
-	DECLARE_BITMAP(group, ds->num_ports);
 	int port, err;
 
-	/* Build a mask of Multicast group members */
-	bitmap_zero(group, ds->num_ports);
-	if (ds->index == info->sw_index)
-		set_bit(info->port, group);
-	for (port = 0; port < ds->num_ports; port++)
-		if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
-			set_bit(port, group);
-
 	if (switchdev_trans_ph_prepare(trans)) {
 		if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
 			return -EOPNOTSUPP;
@@ -141,6 +133,40 @@ static int dsa_switch_mdb_add(struct dsa_switch *ds,
 	return 0;
 }
 
+static int dsa_switch_mdb_add(struct dsa_switch *ds,
+			      struct dsa_notifier_mdb_info *info)
+{
+	const struct switchdev_obj_port_mdb *mdb = info->mdb;
+	DECLARE_BITMAP(group, ds->num_ports);
+	int port;
+
+	/* Build a mask of Multicast group members */
+	bitmap_zero(group, ds->num_ports);
+	if (ds->index == info->sw_index)
+		set_bit(info->port, group);
+	for (port = 0; port < ds->num_ports; port++)
+		if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
+			set_bit(port, group);
+
+	return dsa_switch_mdb_add_bitmap(ds, info, mdb, group);
+}
+
+static int dsa_switch_host_mdb_add(struct dsa_switch *ds,
+				   struct dsa_notifier_mdb_info *info)
+{
+	const struct switchdev_obj_port_mdb *mdb = info->mdb;
+	DECLARE_BITMAP(group, ds->num_ports);
+	int port;
+
+	/* Build a mask of Multicast group members */
+	bitmap_zero(group, ds->num_ports);
+	for (port = 0; port < ds->num_ports; port++)
+		if (dsa_is_cpu_port(ds, port))
+			set_bit(port, group);
+
+	return dsa_switch_mdb_add_bitmap(ds, info, mdb, group);
+}
+
 static int dsa_switch_mdb_del(struct dsa_switch *ds,
 			      struct dsa_notifier_mdb_info *info)
 {
@@ -155,6 +181,22 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds,
 	return 0;
 }
 
+static int dsa_switch_host_mdb_del(struct dsa_switch *ds,
+				   struct dsa_notifier_mdb_info *info)
+{
+	const struct switchdev_obj_port_mdb *mdb = info->mdb;
+	int port;
+
+	if (!ds->ops->port_mdb_del)
+		return -EOPNOTSUPP;
+
+	for (port = 0; port < ds->num_ports; port++)
+		if (dsa_is_cpu_port(ds, port))
+			ds->ops->port_mdb_del(ds, port, mdb);
+
+	return 0;
+}
+
 static int dsa_switch_vlan_add(struct dsa_switch *ds,
 			       struct dsa_notifier_vlan_info *info)
 {
@@ -230,6 +272,12 @@ static int dsa_switch_event(struct notifier_block *nb,
 	case DSA_NOTIFIER_MDB_DEL:
 		err = dsa_switch_mdb_del(ds, info);
 		break;
+	case DSA_NOTIFIER_HOST_MDB_ADD:
+		err = dsa_switch_host_mdb_add(ds, info);
+		break;
+	case DSA_NOTIFIER_HOST_MDB_DEL:
+		err = dsa_switch_host_mdb_del(ds, info);
+		break;
 	case DSA_NOTIFIER_VLAN_ADD:
 		err = dsa_switch_vlan_add(ds, info);
 		break;
-- 
2.14.1

  parent reply	other threads:[~2017-09-05 23:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05 23:35 [PATCH v2 rfc 0/8] IGMP snooping for local traffic Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 1/8] net: bridge: Rename mglist to host_joined Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 2/8] net: bridge: Send notification when host join/leaves a group Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 3/8] net: bridge: Add/del switchdev object on host join/leave Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 4/8] net: dsa: slave: Handle switchdev host mdb add/del Andrew Lunn
2017-09-06 15:37   ` Vivien Didelot
2017-09-05 23:35 ` Andrew Lunn [this message]
2017-09-05 23:35 ` [PATCH v2 rfc 6/8] net: dsa: switch: Don't add CPU port to an mdb by default Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 7/8] net: dsa: set offload_fwd_mark on received packets Andrew Lunn
2017-09-05 23:35 ` [PATCH v2 rfc 8/8] net: dsa: Fix SWITCHDEV_ATTR_ID_PORT_PARENT_ID Andrew Lunn
2017-09-06 14:46   ` Vivien Didelot
2017-09-06 15:08     ` Andrew Lunn
2017-09-06 16:09       ` Florian Fainelli
2017-09-06 16:29         ` Andrew Lunn
2017-09-06  0:11 ` [PATCH v2 rfc 0/8] IGMP snooping for local traffic Stephen Hemminger
2017-09-06  9:52   ` Nikolay Aleksandrov
2017-09-06  0:47 ` Andrew Lunn
2017-09-06 13:56   ` Vivien Didelot
2017-09-06 14:16     ` Andrew Lunn
2017-09-06 14:27   ` John Crispin
2017-09-06 14:46   ` Matthias May
2017-09-06 15:16     ` Andrew Lunn
2017-09-06 15:27   ` Stephen Hemminger
2017-09-06 15:49   ` Woojung.Huh
2017-09-06 15:54   ` Roopa Prabhu
2017-09-06 16:06     ` Florian Fainelli
2017-09-06 16:42       ` Andrew Lunn
2017-09-06 19:54         ` Florian Fainelli
2017-09-06 23:44           ` Woojung.Huh
2017-09-07  0:43             ` Andrew Lunn
2017-09-07  0:47           ` Andrew Lunn
2017-09-06 14:29 ` Vivien Didelot
2017-09-06 15:25 ` Vivien Didelot
2017-09-06 17:01   ` Andrew Lunn
2017-09-06 18:29     ` Vivien Didelot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504654510-31004-6-git-send-email-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=vivien.didelot@savoirfairelinux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).