diff mbox series

[iproute2-next,2/4] bridge: fdb: Add support for locked FDB entries

Message ID 20221106113957.2725173-3-idosch@nvidia.com (mailing list archive)
State Accepted
Commit fa24597472f38d0336be9765e504c8bc6be35e7f
Delegated to: David Ahern
Headers show
Series bridge: Add MAC Authentication Bypass (MAB) support | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ido Schimmel Nov. 6, 2022, 11:39 a.m. UTC
From: Hans Schultz <netdev@kapio-technology.com>

Print the "locked" FDB flag when it is set in the 'NDA_FLAGS_EXT'
attribute. Example output:

 # bridge fdb get 00:11:22:33:44:55 br br0
 00:11:22:33:44:55 dev swp1 locked master br0

 # bridge -j -p fdb get 00:11:22:33:44:55 br br0
 [ {
         "mac": "00:11:22:33:44:55",
         "ifname": "swp1",
         "flags": [ "locked" ],
         "master": "br0",
         "state": ""
     } ]

Signed-off-by: Hans Schultz <netdev@kapio-technology.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---

Notes:
    Changes made by me:
    * Use '__u32' instead of '__u8' in fdb_print_flags().
    * Reword commit message.

 bridge/fdb.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 775feb1296af..ae8f7b4690f9 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -93,7 +93,7 @@  static int state_a2n(unsigned int *s, const char *arg)
 	return 0;
 }
 
-static void fdb_print_flags(FILE *fp, unsigned int flags)
+static void fdb_print_flags(FILE *fp, unsigned int flags, __u32 ext_flags)
 {
 	open_json_array(PRINT_JSON,
 			is_json_context() ?  "flags" : "");
@@ -116,6 +116,9 @@  static void fdb_print_flags(FILE *fp, unsigned int flags)
 	if (flags & NTF_STICKY)
 		print_string(PRINT_ANY, NULL, "%s ", "sticky");
 
+	if (ext_flags & NTF_EXT_LOCKED)
+		print_string(PRINT_ANY, NULL, "%s ", "locked");
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -144,6 +147,7 @@  int print_fdb(struct nlmsghdr *n, void *arg)
 	struct ndmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[NDA_MAX+1];
+	__u32 ext_flags = 0;
 	__u16 vid = 0;
 
 	if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
@@ -170,6 +174,9 @@  int print_fdb(struct nlmsghdr *n, void *arg)
 	parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
 		     n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
+	if (tb[NDA_FLAGS_EXT])
+		ext_flags = rta_getattr_u32(tb[NDA_FLAGS_EXT]);
+
 	if (tb[NDA_VLAN])
 		vid = rta_getattr_u16(tb[NDA_VLAN]);
 
@@ -268,7 +275,7 @@  int print_fdb(struct nlmsghdr *n, void *arg)
 	if (show_stats && tb[NDA_CACHEINFO])
 		fdb_print_stats(fp, RTA_DATA(tb[NDA_CACHEINFO]));
 
-	fdb_print_flags(fp, r->ndm_flags);
+	fdb_print_flags(fp, r->ndm_flags, ext_flags);
 
 
 	if (tb[NDA_MASTER])