diff options
author | Nikolay Aleksandrov <razor@blackwall.org> | 2022-06-08 15:29:12 +0300 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2022-06-10 09:00:31 -0600 |
commit | 6e1ca489c5a29826f2a2f1edab01f753650c9cec (patch) | |
tree | 46735b05297575461fda2c77cb2d28a4773bc848 | |
parent | cef46213d5ddbaa507b277878394d6a535dc22cc (diff) | |
download | iproute2-6e1ca489c5a29826f2a2f1edab01f753650c9cec.tar.gz |
bridge: fdb: add new flush command
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>
Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r-- | bridge/fdb.c | 58 | ||||
-rw-r--r-- | man/man8/bridge.8 | 29 |
2 files changed, 86 insertions, 1 deletions
diff --git a/bridge/fdb.c b/bridge/fdb.c index 8912f092c..ac9f7af64 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 d8923d2eb..bfda9f7ec 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -113,6 +113,12 @@ bridge \- show / manipulate bridge addresses and devices .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 .I 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 |