netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, stephen@networkplumber.org, roopa@nvidia.com,
	Nikolay Aleksandrov <razor@blackwall.org>
Subject: [PATCH iproute2-next 01/10] bridge: fdb: add new flush command
Date: Wed,  8 Jun 2022 15:29:12 +0300	[thread overview]
Message-ID: <20220608122921.3962382-2-razor@blackwall.org> (raw)
In-Reply-To: <20220608122921.3962382-1-razor@blackwall.org>

Add support for fdb bulk delete (aka flush) command. Currently it only
supports the self and master flags with the same semantics as fdb
add/del. The device is a mandatory argument.

Example:
$ bridge fdb flush dev br0
This will delete *all* fdb entries in br0's fdb table.

$ bridge fdb flush dev swp1 master
This will delete all fdb entries pointing to swp1.

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
---
 bridge/fdb.c      | 58 ++++++++++++++++++++++++++++++++++++++++++++++-
 man/man8/bridge.8 | 29 ++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 8912f092ca15..ac9f7af64336 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -44,7 +44,8 @@ static void usage(void)
 		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ]\n"
 		"              [ state STATE ] [ dynamic ] ]\n"
 		"       bridge fdb get [ to ] LLADDR [ br BRDEV ] { brport | dev } DEV\n"
-		"              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n");
+		"              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n"
+		"       bridge fdb flush dev DEV [ self ] [ master ]\n");
 	exit(-1);
 }
 
@@ -666,6 +667,59 @@ static int fdb_get(int argc, char **argv)
 	return 0;
 }
 
+static int fdb_flush(int argc, char **argv)
+{
+	struct {
+		struct nlmsghdr	n;
+		struct ndmsg		ndm;
+		char			buf[256];
+	} req = {
+		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
+		.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_BULK,
+		.n.nlmsg_type = RTM_DELNEIGH,
+		.ndm.ndm_family = PF_BRIDGE,
+	};
+	unsigned short ndm_flags = 0;
+	char *d = NULL;
+
+	while (argc > 0) {
+		if (strcmp(*argv, "dev") == 0) {
+			NEXT_ARG();
+			d = *argv;
+		} else if (strcmp(*argv, "master") == 0) {
+			ndm_flags |= NTF_MASTER;
+		} else if (strcmp(*argv, "self") == 0) {
+			ndm_flags |= NTF_SELF;
+		} else {
+			if (strcmp(*argv, "help") == 0)
+				NEXT_ARG();
+		}
+		argc--; argv++;
+	}
+
+	if (d == NULL) {
+		fprintf(stderr, "Device is a required argument.\n");
+		return -1;
+	}
+
+	req.ndm.ndm_ifindex = ll_name_to_index(d);
+	if (req.ndm.ndm_ifindex == 0) {
+		fprintf(stderr, "Cannot find bridge device \"%s\"\n", d);
+		return -1;
+	}
+
+	/* if self and master were not specified assume self */
+	if (!(ndm_flags & (NTF_SELF | NTF_MASTER)))
+		ndm_flags |= NTF_SELF;
+
+	req.ndm.ndm_flags = ndm_flags;
+
+	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+		return -1;
+
+	return 0;
+}
+
 int do_fdb(int argc, char **argv)
 {
 	ll_init_map(&rth);
@@ -685,6 +739,8 @@ int do_fdb(int argc, char **argv)
 		    matches(*argv, "lst") == 0 ||
 		    matches(*argv, "list") == 0)
 			return fdb_show(argc-1, argv+1);
+		if (strcmp(*argv, "flush") == 0)
+			return fdb_flush(argc-1, argv+1);
 		if (matches(*argv, "help") == 0)
 			usage();
 	} else
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index d8923d2eb076..bfda9f7ecd7b 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -112,6 +112,12 @@ bridge \- show / manipulate bridge addresses and devices
 .IR VNI " ] ["
 .BR self " ] [ " master " ] [ " dynamic " ]"
 
+.ti -8
+.BR "bridge fdb flush"
+.B dev
+.IR DEV " [ "
+.BR self " ] [ " master " ]"
+
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
 .B dev
@@ -782,6 +788,29 @@ the bridge to which this address is associated.
 .TP
 .B master
 - the address is associated with master devices fdb. Usually software (default).
+
+.SS bridge fdb flush - flush bridge forwarding table entries.
+
+flush the matching bridge forwarding table entries.
+
+.TP
+.BI dev " DEV"
+the target device for the operation. If the device is a bridge port and "master"
+is set then the operation will be fulfilled by its master device's driver and
+all entries pointing to that port will be deleted.
+
+.TP
+.B self
+the operation is fulfilled directly by the driver for the specified network
+device. If the network device belongs to a master like a bridge, then the
+bridge is bypassed and not notified of this operation. The "bridge fdb flush"
+command can also be used on the bridge device itself. The flag is set by default if
+"master" is not specified.
+
+.TP
+.B master
+if the specified network device is a port that belongs to a master device
+such as a bridge, the operation is fulfilled by the master device's driver.
 .sp
 
 .SH bridge mdb - multicast group database management
-- 
2.35.1


  reply	other threads:[~2022-06-08 12:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 12:29 [PATCH iproute2-next 00/10] bridge: fdb: add extended flush support Nikolay Aleksandrov
2022-06-08 12:29 ` Nikolay Aleksandrov [this message]
2022-06-08 12:29 ` [PATCH iproute2-next 02/10] bridge: fdb: add flush vlan matching Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 03/10] bridge: fdb: add flush port matching Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 04/10] bridge: fdb: add flush [no]permanent entry matching Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 05/10] bridge: fdb: add flush [no]static " Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 06/10] bridge: fdb: add flush [no]dynamic " Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 07/10] bridge: fdb: add flush [no]added_by_user " Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 08/10] bridge: fdb: add flush [no]extern_learn " Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 09/10] bridge: fdb: add flush [no]sticky " Nikolay Aleksandrov
2022-06-08 12:29 ` [PATCH iproute2-next 10/10] bridge: fdb: add flush [no]offloaded " Nikolay Aleksandrov
2022-06-10 15:10 ` [PATCH iproute2-next 00/10] bridge: fdb: add extended flush support patchwork-bot+netdevbpf

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=20220608122921.3962382-2-razor@blackwall.org \
    --to=razor@blackwall.org \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@nvidia.com \
    --cc=stephen@networkplumber.org \
    /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).