Skip to contentSkip to conversation

bridge: link: enable MacAuth/MAB feature

PATCH In review Hans Schultz 4 participants 12 messages Sep 29, 2022 – Oct 3, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bridge: link: enable MacAuth/MAB feature

The MAB feature can be enabled on a locked port with the command:
bridge link set dev <DEV> mab on

---
 bridge/fdb.c                   | 17 +++++++++++++++--
 bridge/link.c                  | 21 ++++++++++++++++++---
 include/uapi/linux/if_link.h   |  1 +
 include/uapi/linux/neighbour.h |  7 ++++++-
 ip/iplink_bridge_slave.c       | 16 +++++++++++++---
 man/man8/bridge.8              | 10 ++++++++++
 man/man8/ip-link.8.in          |  8 ++++++++
 7 files changed, 71 insertions(+), 9 deletions(-)
bridge/fdb.c +15 -2
index 5f71bde0..0fbe9bd3 100644
@@ -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, __u8 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]);
 
@@ -266,7 +273,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])
@@ -414,6 +421,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 	char *endptr;
 	short vid = -1;
 	__u32 nhid = 0;
+	__u32 ext_flags = 0;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -527,6 +535,11 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 	if (dst_ok)
 		addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen);
 
+	if (ext_flags &&
+	    addattr_l(&req.n, sizeof(req), NDA_FLAGS_EXT, &ext_flags,
+		      sizeof(ext_flags)) < 0)
+		return -1;
+
 	if (vid >= 0)
 		addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
 	if (nhid > 0)
bridge/link.c +18 -3
index 3810fa04..dd69d7c3 100644
@@ -181,9 +181,14 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
 		if (prtb[IFLA_BRPORT_ISOLATED])
 			print_on_off(PRINT_ANY, "isolated", "isolated %s ",
 				     rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
-		if (prtb[IFLA_BRPORT_LOCKED])
-			print_on_off(PRINT_ANY, "locked", "locked %s ",
-				     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+		if (prtb[IFLA_BRPORT_LOCKED]) {
+			if (prtb[IFLA_BRPORT_MAB] && rta_getattr_u8(prtb[IFLA_BRPORT_MAB]))
+				print_on_off(PRINT_ANY, "locked mab", "locked mab %s ",
+					     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+			else
+				print_on_off(PRINT_ANY, "locked", "locked %s ",
+					     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+		}
 	} else
 		print_stp_state(rta_getattr_u8(attr));
 }
@@ -281,6 +286,7 @@ static void usage(void)
 		"                               [ vlan_tunnel {on | off} ]\n"
 		"                               [ isolated {on | off} ]\n"
 		"                               [ locked {on | off} ]\n"
+		"                               [ mab {on | off} ]\n"
 		"                               [ hwmode {vepa | veb} ]\n"
 		"                               [ backup_port DEVICE ] [ nobackup_port ]\n"
 		"                               [ self ] [ master ]\n"
@@ -312,6 +318,7 @@ static int brlink_modify(int argc, char **argv)
 	__s8 bcast_flood = -1;
 	__s8 mcast_to_unicast = -1;
 	__s8 locked = -1;
+	__s8 macauth = -1;
 	__s8 isolated = -1;
 	__s8 hairpin = -1;
 	__s8 bpdu_guard = -1;
@@ -437,6 +444,11 @@ static int brlink_modify(int argc, char **argv)
 			locked = parse_on_off("locked", *argv, &ret);
 			if (ret)
 				return ret;
+		} else if (strcmp(*argv, "mab") == 0) {
+			NEXT_ARG();
+			macauth = parse_on_off("mab", *argv, &ret);
+			if (ret)
+				return ret;
 		} else if (strcmp(*argv, "backup_port") == 0) {
 			NEXT_ARG();
 			backup_port_idx = ll_name_to_index(*argv);
@@ -520,6 +532,9 @@ static int brlink_modify(int argc, char **argv)
 	if (locked >= 0)
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_LOCKED, locked);
 
+	if (macauth >= 0)
+		addattr8(&req.n, sizeof(req), IFLA_BRPORT_MAB, macauth);
+
 	if (backup_port_idx != -1)
 		addattr32(&req.n, sizeof(req), IFLA_BRPORT_BACKUP_PORT,
 			  backup_port_idx);
include/uapi/linux/if_link.h +1 -0
index 7494cffb..58a002de 100644
@@ -559,6 +559,7 @@ enum {
 	IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT,
 	IFLA_BRPORT_MCAST_EHT_HOSTS_CNT,
 	IFLA_BRPORT_LOCKED,
+	IFLA_BRPORT_MAB,
 	__IFLA_BRPORT_MAX
 };
 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
include/uapi/linux/neighbour.h +6 -1
index a998bf76..4dda051b 100644
@@ -52,7 +52,8 @@ enum {
 #define NTF_STICKY	(1 << 6)
 #define NTF_ROUTER	(1 << 7)
 /* Extended flags under NDA_FLAGS_EXT: */
-#define NTF_EXT_MANAGED	(1 << 0)
+#define NTF_EXT_MANAGED		(1 << 0)
+#define NTF_EXT_LOCKED		(1 << 1)
 
 /*
  *	Neighbor Cache Entry States.
@@ -86,6 +87,10 @@ enum {
  * NTF_EXT_MANAGED flagged neigbor entries are managed by the kernel on behalf
  * of a user space control plane, and automatically refreshed so that (if
  * possible) they remain in NUD_REACHABLE state.
+ *
+ * NTF_EXT_LOCKED flagged FDB entries are placeholder entries used with the
+ * locked port feature, that ensures that an entry exists while at the same
+ * time dropping packets on ingress with src MAC and VID matching the entry.
  */
 
 struct nda_cacheinfo {
ip/iplink_bridge_slave.c +13 -3
index 98d17213..0c0894eb 100644
@@ -44,6 +44,7 @@ static void print_explain(FILE *f)
 		"			[ vlan_tunnel {on | off} ]\n"
 		"			[ isolated {on | off} ]\n"
 		"			[ locked {on | off} ]\n"
+		"                       [ mab {on | off} ]\n"
 		"			[ backup_port DEVICE ] [ nobackup_port ]\n"
 	);
 }
@@ -284,9 +285,14 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
 		print_on_off(PRINT_ANY, "isolated", "isolated %s ",
 			     rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED]));
 
-	if (tb[IFLA_BRPORT_LOCKED])
-		print_on_off(PRINT_ANY, "locked", "locked %s ",
-			     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+	if (tb[IFLA_BRPORT_LOCKED]) {
+		if (tb[IFLA_BRPORT_MAB] && rta_getattr_u8(tb[IFLA_BRPORT_MAB]))
+			print_on_off(PRINT_ANY, "locked mab", "locked mab %s ",
+				     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+		else
+			print_on_off(PRINT_ANY, "locked", "locked %s ",
+				     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+	}
 
 	if (tb[IFLA_BRPORT_BACKUP_PORT]) {
 		int backup_p = rta_getattr_u32(tb[IFLA_BRPORT_BACKUP_PORT]);
@@ -411,6 +417,10 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv,
 			NEXT_ARG();
 			bridge_slave_parse_on_off("locked", *argv, n,
 						  IFLA_BRPORT_LOCKED);
+		} else if (matches(*argv, "mab") == 0) {
+			NEXT_ARG();
+			bridge_slave_parse_on_off("mab", *argv, n,
+						  IFLA_BRPORT_MAB);
 		} else if (matches(*argv, "backup_port") == 0) {
 			int ifindex;
 
man/man8/bridge.8 +10 -0
index d4df772e..40250477 100644
@@ -54,6 +54,7 @@ bridge \- show / manipulate bridge addresses and devices
 .BR vlan_tunnel " { " on " | " off " } ] [ "
 .BR isolated " { " on " | " off " } ] [ "
 .BR locked " { " on " | " off " } ] [ "
+.BR mab " { " on " | " off " } ] [ "
 .B backup_port
 .IR  DEVICE " ] ["
 .BR nobackup_port " ] [ "
@@ -580,6 +581,15 @@ The common use is that hosts are allowed access through authentication
 with the IEEE 802.1X protocol or based on whitelists or like setups.
 By default this flag is off.
 
+.TP
+.RB "mab on " or " mab off "
+Enables or disables the MAB/MacAuth feature. This feature can only be
+activated on a port that is in locked mode, and when enabled it extends the
+locked port feature so that MAC address can get access through a locked
+port based on acceptlists, thus it is a much simpler procedure for a
+device to become authorized than f.ex. the 802.1X protocol, and is used
+for devices that are not capable of password or crypto based authorization
+methods.
 
 .TP
 .BI backup_port " DEVICE"
man/man8/ip-link.8.in +8 -0
index fc9d62fc..187ca7ca 100644
@@ -2454,6 +2454,9 @@ the following additional arguments are supported:
 .BR isolated " { " on " | " off " }"
 ] [
 .BR locked " { " on " | " off " }"
+] [
+.BR mab " { " on " | " off " }"
+] [
 .BR backup_port " DEVICE"
 ] [
 .BR nobackup_port " ]"
@@ -2560,6 +2563,11 @@ default this flag is off.
 behind the port cannot communicate through the port unless a FDB entry
 representing the host is in the FDB. By default this flag is off.
 
+.BR mab " { " on " | " off " }"
+- enables or disables the MAB/MacAuth feature on a locked port. It is
+thus possible for a device to gain authorization on a locked port based
+on acceptlists.
+
 .BI backup_port " DEVICE"
 - if the port loses carrier all traffic will be redirected to the
 configured backup port
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 bridge: fdb: enable FDB blackhole feature

Block traffic to a specific host with the command:
bridge fdb add <MAC> vlan <vid> dev br0 blackhole

The blackhole FDB entries can be added, deleted and replaced with ordinary FDB entries.

---
 bridge/fdb.c                   | 7 ++++++-
 include/uapi/linux/neighbour.h | 4 ++++
 man/man8/bridge.8              | 6 ++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
bridge/fdb.c +6 -1
index 0fbe9bd3..2160f1c2 100644
@@ -38,7 +38,7 @@ static void usage(void)
 	fprintf(stderr,
 		"Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
 		"              [ self ] [ master ] [ use ] [ router ] [ extern_learn ]\n"
-		"              [ sticky ] [ local | static | dynamic ] [ vlan VID ]\n"
+		"              [ sticky ] [ local | static | dynamic ] [blackhole] [ vlan VID ]\n"
 		"              { [ dst IPADDR ] [ port PORT] [ vni VNI ] | [ nhid NHID ] }\n"
 		"	       [ via DEV ] [ src_vni VNI ]\n"
 		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ]\n"
@@ -116,6 +116,9 @@ static void fdb_print_flags(FILE *fp, unsigned int flags, __u8 ext_flags)
 	if (flags & NTF_STICKY)
 		print_string(PRINT_ANY, NULL, "%s ", "sticky");
 
+	if (ext_flags & NTF_EXT_BLACKHOLE)
+		print_string(PRINT_ANY, NULL, "%s ", "blackhole");
+
 	if (ext_flags & NTF_EXT_LOCKED)
 		print_string(PRINT_ANY, NULL, "%s ", "locked");
 
@@ -493,6 +496,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
 		} else if (matches(*argv, "sticky") == 0) {
 			req.ndm.ndm_flags |= NTF_STICKY;
+		} else if (matches(*argv, "blackhole") == 0) {
+			ext_flags |= NTF_EXT_BLACKHOLE;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();
include/uapi/linux/neighbour.h +4 -0
index 4dda051b..cc7d540e 100644
@@ -54,6 +54,7 @@ enum {
 /* Extended flags under NDA_FLAGS_EXT: */
 #define NTF_EXT_MANAGED		(1 << 0)
 #define NTF_EXT_LOCKED		(1 << 1)
+#define NTF_EXT_BLACKHOLE	(1 << 2)
 
 /*
  *	Neighbor Cache Entry States.
@@ -91,6 +92,9 @@ enum {
  * NTF_EXT_LOCKED flagged FDB entries are placeholder entries used with the
  * locked port feature, that ensures that an entry exists while at the same
  * time dropping packets on ingress with src MAC and VID matching the entry.
+ *
+ * NTF_EXT_BLACKHOLE flagged FDB entries ensure that no forwarding is allowed
+ * from any port to the destination MAC, VID pair associated with it.
  */
 
 struct nda_cacheinfo {
man/man8/bridge.8 +6 -0
index 40250477..af2e7db2 100644
@@ -699,6 +699,12 @@ controller learnt dynamic entry. Kernel will not age such an entry.
 - this entry will not change its port due to learning.
 .sp
 
+.B blackhole
+- this is an entry that denies all forwarding from any port to a destination
+matching the entry. It can be added by userspace, but the flag is mostly set
+from a hardware driver.
+.sp
+
 .in -8
 The next command line parameters apply only
 when the specified device
Signature · 1 line
2.34.1
#2 lore raw

Re: [Bridge] [PATCH iproute2-next 2/2] bridge: fdb: enable FDB blackhole feature

bridge/fdb.c static int fdb_modify(int cmd, int flags, int argc, char **argv) · line 503

Quoted 10 lines · On Thu, 29 Sep 2022 17:21:37 +0200 Hans Schultz <[email protected]>…
bridge/fdb.c +2 -0
@@ -493,6 +496,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
 		} else if (matches(*argv, "sticky") == 0) {
 			req.ndm.ndm_flags |= NTF_STICKY;
+		} else if (matches(*argv, "blackhole") == 0) {
+			ext_flags |= NTF_EXT_BLACKHOLE;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();

The parsing of flags is weird here, most of the flags are compared with strcmp() but some use matches().. I should have used strcmp() all the time; but at the time did not realize what kind of confusion matches() can cause.

#3 lore raw

Re: [Bridge] [PATCH iproute2-next 2/2] bridge: fdb: enable FDB blackhole feature

Quoted 4 lines · Stephen Hemminger
Quoted 1 line · On Thu, 29 Sep 2022 17:21:37 +0200 Hans Schultz <[email protected]>…
Quoted 14 lines
Quoted 10 lines
bridge/fdb.c +2 -0
@@ -493,6 +496,8 @@ static int fdb_modify(int cmd, int flags, int 
 argc, char **argv)
 			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
 		} else if (matches(*argv, "sticky") == 0) {
 			req.ndm.ndm_flags |= NTF_STICKY;
+		} else if (matches(*argv, "blackhole") == 0) {
+			ext_flags |= NTF_EXT_BLACKHOLE;
 		} else {
 			if (strcmp(*argv, "to") == 0)

NEXT_ARG();

The parsing of flags is weird here, most of the flags are compared with strcmp() but some use matches().. I should have used strcmp() all the time; but at the time did not realize what kind of confusion matches() can cause.

Maybe just change all of them then, and then how about using strncmp() and maybe also strnlen() instead?

maintainer
#4 lore raw

Re: [PATCH iproute2-next 2/2] bridge: fdb: enable FDB blackhole feature

In reply to Hans Schultz
Quoted 2 lines · Hans Schultz

Block traffic to a specific host with the command:
bridge fdb add <MAC> vlan <vid> dev br0 blackhole

Please add an example with regular and JSON output.

Quoted 16 lines

The blackhole FDB entries can be added, deleted and replaced with ordinary FDB entries.

---
 bridge/fdb.c                   | 7 ++++++-
 include/uapi/linux/neighbour.h | 4 ++++
 man/man8/bridge.8              | 6 ++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
bridge/fdb.c +0 -0
index 0fbe9bd3..2160f1c2 100644

bridge/fdb.c static void usage(void) · line 41

Quoted 5 lines
bridge/fdb.c +1 -1
@@ -38,7 +38,7 @@ static void usage(void)
 	fprintf(stderr,
 		"Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
 		"              [ self ] [ master ] [ use ] [ router ] [ extern_learn ]\n"
-		"              [ sticky ] [ local | static | dynamic ] [ vlan VID ]\n"
+		"              [ sticky ] [ local | static | dynamic ] [blackhole] [ vlan VID ]\n"

[ blackhole ]

Quoted 49 lines
bridge/fdb.c +5 -0
 		"              { [ dst IPADDR ] [ port PORT] [ vni VNI ] | [ nhid NHID ] }\n"
 		"	       [ via DEV ] [ src_vni VNI ]\n"
 		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ]\n"
@@ -116,6 +116,9 @@ static void fdb_print_flags(FILE *fp, unsigned int flags, __u8 ext_flags)
 	if (flags & NTF_STICKY)
 		print_string(PRINT_ANY, NULL, "%s ", "sticky");
 
+	if (ext_flags & NTF_EXT_BLACKHOLE)
+		print_string(PRINT_ANY, NULL, "%s ", "blackhole");
+
 	if (ext_flags & NTF_EXT_LOCKED)
 		print_string(PRINT_ANY, NULL, "%s ", "locked");
 
@@ -493,6 +496,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
 		} else if (matches(*argv, "sticky") == 0) {
 			req.ndm.ndm_flags |= NTF_STICKY;
+		} else if (matches(*argv, "blackhole") == 0) {
+			ext_flags |= NTF_EXT_BLACKHOLE;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();
include/uapi/linux/neighbour.h +4 -0
index 4dda051b..cc7d540e 100644
@@ -54,6 +54,7 @@ enum {
 /* Extended flags under NDA_FLAGS_EXT: */
 #define NTF_EXT_MANAGED		(1 << 0)
 #define NTF_EXT_LOCKED		(1 << 1)
+#define NTF_EXT_BLACKHOLE	(1 << 2)
 
 /*
  *	Neighbor Cache Entry States.
@@ -91,6 +92,9 @@ enum {
  * NTF_EXT_LOCKED flagged FDB entries are placeholder entries used with the
  * locked port feature, that ensures that an entry exists while at the same
  * time dropping packets on ingress with src MAC and VID matching the entry.
+ *
+ * NTF_EXT_BLACKHOLE flagged FDB entries ensure that no forwarding is allowed
+ * from any port to the destination MAC, VID pair associated with it.
  */
 
 struct nda_cacheinfo {
man/man8/bridge.8 +0 -0
index 40250477..af2e7db2 100644

man/man8/bridge.8 controller learnt dynamic entry. Kernel will not age such an entry. · line 700

Quoted 2 lines
man/man8/bridge.8 +0 -0
@@ -699,6 +699,12 @@ controller learnt dynamic entry. Kernel will not age such an entry.
 - this entry will not change its port due to learning.
 .sp

Need to patch the "SYNOPSIS" section as well

man/man8/bridge.8 controller learnt dynamic entry. Kernel will not age such an entry. · line 705

Quoted 5 lines
man/man8/bridge.8 +4 -0
+.B blackhole
+- this is an entry that denies all forwarding from any port to a destination
+matching the entry. It can be added by userspace, but the flag is mostly set
+from a hardware driver.

I'm not sure the last sentence belongs in the man page. We have no way of knowing if it is true and it can change with time.

How about:

"this entry will silently discard all matching packets. The entry must be added as a local permanent entry."

Quoted 8 lines
man/man8/bridge.8 +2 -0
+.sp
+
 .in -8
 The next command line parameters apply only
 when the specified device
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH iproute2-next 2/2] bridge: fdb: enable FDB blackhole feature

Quoted 9 lines · Ido Schimmel

I'm not sure the last sentence belongs in the man page. We have no way of knowing if it is true and it can change with time.

How about:

"this entry will silently discard all matching packets. The entry must be added as a local permanent entry."

Fine with me...

#6 lore raw

Re: [PATCH iproute2-next 2/2] bridge: fdb: enable FDB blackhole feature

In reply to Ido Schimmel
Quoted 3 lines · Ido Schimmel

Need to patch the "SYNOPSIS" section as well

Does this look right to you for the addition to the "SYNOPSIS"?...

bridge fdb { add | del } LLADR dev BRDEV [ self ] [ local ] [ blackhole ]

maintainer
#7 lore raw
In reply to Hans Schultz
Quoted 2 lines · Hans Schultz

The MAB feature can be enabled on a locked port with the command:
bridge link set dev <DEV> mab on

Please provide regular and JSON output in the commit message.

Quoted 7 lines
---
 bridge/fdb.c                   | 17 +++++++++++++++--
 bridge/link.c                  | 21 ++++++++++++++++++---
 include/uapi/linux/if_link.h   |  1 +
 include/uapi/linux/neighbour.h |  7 ++++++-

IIRC, in the past David asked to either not send the uAPI files or send them as a first patch which he then uses as a hint to sync the files himself.

Quoted 19 lines
 ip/iplink_bridge_slave.c       | 16 +++++++++++++---
 man/man8/bridge.8              | 10 ++++++++++
 man/man8/ip-link.8.in          |  8 ++++++++
 7 files changed, 71 insertions(+), 9 deletions(-)
bridge/fdb.c +1 -1
index 5f71bde0..0fbe9bd3 100644
@@ -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, __u8 ext_flags)
 {
 	open_json_array(PRINT_JSON,
 			is_json_context() ?  "flags" : "");

bridge/fdb.c static void fdb_print_flags(FILE *fp, unsigned int flags) · line 123

Quoted 8 lines
bridge/fdb.c +3 -0
@@ -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);
 }

This is a separate change. Make one patch for the MAB option and another for the new "locked" FDB flag.

Quoted 37 lines
bridge/fdb.c +6 -1
@@ -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]);
 
@@ -266,7 +273,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])
@@ -414,6 +421,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 	char *endptr;
 	short vid = -1;
 	__u32 nhid = 0;
+	__u32 ext_flags = 0;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {

bridge/fdb.c static int fdb_modify(int cmd, int flags, int argc, char **argv) · line 542

Quoted 8 lines
bridge/fdb.c +5 -0
@@ -527,6 +535,11 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 	if (dst_ok)
 		addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen);
 
+	if (ext_flags &&
+	    addattr_l(&req.n, sizeof(req), NDA_FLAGS_EXT, &ext_flags,
+		      sizeof(ext_flags)) < 0)
+		return -1;
+

I believe this belongs with the "blackhole" patch.

Quoted 12 lines
bridge/fdb.c +0 -0
 	if (vid >= 0)
 		addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
 	if (nhid > 0)
bridge/link.c +0 -1
index 3810fa04..dd69d7c3 100644
@@ -181,9 +181,14 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
 		if (prtb[IFLA_BRPORT_ISOLATED])
 			print_on_off(PRINT_ANY, "isolated", "isolated %s ",
 				     rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
-		if (prtb[IFLA_BRPORT_LOCKED])

bridge/link.c static void print_protinfo(FILE *fp, struct rtattr *attr) · line 191

Quoted 10 lines
bridge/link.c +8 -2
-			print_on_off(PRINT_ANY, "locked", "locked %s ",
-				     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+		if (prtb[IFLA_BRPORT_LOCKED]) {
+			if (prtb[IFLA_BRPORT_MAB] && rta_getattr_u8(prtb[IFLA_BRPORT_MAB]))
+				print_on_off(PRINT_ANY, "locked mab", "locked mab %s ",
+					     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+			else
+				print_on_off(PRINT_ANY, "locked", "locked %s ",
+					     rta_getattr_u8(prtb[IFLA_BRPORT_LOCKED]));
+		}

These a separate flags and need to be dumped independently. The fact that MAB can only be enabled when the port is locked is enforced by the kernel.

Quoted 95 lines
bridge/link.c +10 -0
 	} else
 		print_stp_state(rta_getattr_u8(attr));
 }
@@ -281,6 +286,7 @@ static void usage(void)
 		"                               [ vlan_tunnel {on | off} ]\n"
 		"                               [ isolated {on | off} ]\n"
 		"                               [ locked {on | off} ]\n"
+		"                               [ mab {on | off} ]\n"
 		"                               [ hwmode {vepa | veb} ]\n"
 		"                               [ backup_port DEVICE ] [ nobackup_port ]\n"
 		"                               [ self ] [ master ]\n"
@@ -312,6 +318,7 @@ static int brlink_modify(int argc, char **argv)
 	__s8 bcast_flood = -1;
 	__s8 mcast_to_unicast = -1;
 	__s8 locked = -1;
+	__s8 macauth = -1;
 	__s8 isolated = -1;
 	__s8 hairpin = -1;
 	__s8 bpdu_guard = -1;
@@ -437,6 +444,11 @@ static int brlink_modify(int argc, char **argv)
 			locked = parse_on_off("locked", *argv, &ret);
 			if (ret)
 				return ret;
+		} else if (strcmp(*argv, "mab") == 0) {
+			NEXT_ARG();
+			macauth = parse_on_off("mab", *argv, &ret);
+			if (ret)
+				return ret;
 		} else if (strcmp(*argv, "backup_port") == 0) {
 			NEXT_ARG();
 			backup_port_idx = ll_name_to_index(*argv);
@@ -520,6 +532,9 @@ static int brlink_modify(int argc, char **argv)
 	if (locked >= 0)
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_LOCKED, locked);
 
+	if (macauth >= 0)
+		addattr8(&req.n, sizeof(req), IFLA_BRPORT_MAB, macauth);
+
 	if (backup_port_idx != -1)
 		addattr32(&req.n, sizeof(req), IFLA_BRPORT_BACKUP_PORT,
 			  backup_port_idx);
include/uapi/linux/if_link.h +1 -0
index 7494cffb..58a002de 100644
@@ -559,6 +559,7 @@ enum {
 	IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT,
 	IFLA_BRPORT_MCAST_EHT_HOSTS_CNT,
 	IFLA_BRPORT_LOCKED,
+	IFLA_BRPORT_MAB,
 	__IFLA_BRPORT_MAX
 };
 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
include/uapi/linux/neighbour.h +6 -1
index a998bf76..4dda051b 100644
@@ -52,7 +52,8 @@ enum {
 #define NTF_STICKY	(1 << 6)
 #define NTF_ROUTER	(1 << 7)
 /* Extended flags under NDA_FLAGS_EXT: */
-#define NTF_EXT_MANAGED	(1 << 0)
+#define NTF_EXT_MANAGED		(1 << 0)
+#define NTF_EXT_LOCKED		(1 << 1)
 
 /*
  *	Neighbor Cache Entry States.
@@ -86,6 +87,10 @@ enum {
  * NTF_EXT_MANAGED flagged neigbor entries are managed by the kernel on behalf
  * of a user space control plane, and automatically refreshed so that (if
  * possible) they remain in NUD_REACHABLE state.
+ *
+ * NTF_EXT_LOCKED flagged FDB entries are placeholder entries used with the
+ * locked port feature, that ensures that an entry exists while at the same
+ * time dropping packets on ingress with src MAC and VID matching the entry.
  */
 
 struct nda_cacheinfo {
ip/iplink_bridge_slave.c +1 -1
index 98d17213..0c0894eb 100644
@@ -44,6 +44,7 @@ static void print_explain(FILE *f)
 		"			[ vlan_tunnel {on | off} ]\n"
 		"			[ isolated {on | off} ]\n"
 		"			[ locked {on | off} ]\n"
+		"                       [ mab {on | off} ]\n"
 		"			[ backup_port DEVICE ] [ nobackup_port ]\n"
 	);
 }
@@ -284,9 +285,14 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
 		print_on_off(PRINT_ANY, "isolated", "isolated %s ",
 			     rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED]));
 
-	if (tb[IFLA_BRPORT_LOCKED])

ip/iplink_bridge_slave.c static void bridge_slave_print_opt(struct link_util *lu, FILE *f, · line 295

Quoted 10 lines
ip/iplink_bridge_slave.c +8 -2
-		print_on_off(PRINT_ANY, "locked", "locked %s ",
-			     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+	if (tb[IFLA_BRPORT_LOCKED]) {
+		if (tb[IFLA_BRPORT_MAB] && rta_getattr_u8(tb[IFLA_BRPORT_MAB]))
+			print_on_off(PRINT_ANY, "locked mab", "locked mab %s ",
+				     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+		else
+			print_on_off(PRINT_ANY, "locked", "locked %s ",
+				     rta_getattr_u8(tb[IFLA_BRPORT_LOCKED]));
+	}

Same comment as before.

Quoted 27 lines
ip/iplink_bridge_slave.c +4 -0
 	if (tb[IFLA_BRPORT_BACKUP_PORT]) {
 		int backup_p = rta_getattr_u32(tb[IFLA_BRPORT_BACKUP_PORT]);
@@ -411,6 +417,10 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv,
 			NEXT_ARG();
 			bridge_slave_parse_on_off("locked", *argv, n,
 						  IFLA_BRPORT_LOCKED);
+		} else if (matches(*argv, "mab") == 0) {
+			NEXT_ARG();
+			bridge_slave_parse_on_off("mab", *argv, n,
+						  IFLA_BRPORT_MAB);
 		} else if (matches(*argv, "backup_port") == 0) {
 			int ifindex;
 
man/man8/bridge.8 +1 -0
index d4df772e..40250477 100644
@@ -54,6 +54,7 @@ bridge \- show / manipulate bridge addresses and devices
 .BR vlan_tunnel " { " on " | " off " } ] [ "
 .BR isolated " { " on " | " off " } ] [ "
 .BR locked " { " on " | " off " } ] [ "
+.BR mab " { " on " | " off " } ] [ "
 .B backup_port
 .IR  DEVICE " ] ["
 .BR nobackup_port " ] [ "

man/man8/bridge.8 The common use is that hosts are allowed access through authentication · line 587

Quoted 7 lines
man/man8/bridge.8 +4 -0
@@ -580,6 +581,15 @@ The common use is that hosts are allowed access through authentication
 with the IEEE 802.1X protocol or based on whitelists or like setups.
 By default this flag is off.
 
+.TP
+.RB "mab on " or " mab off "
+Enables or disables the MAB/MacAuth feature. This feature can only be
+activated on a port that is in locked mode, and when enabled it extends the

s/activated/enabled/

man/man8/bridge.8 The common use is that hosts are allowed access through authentication · line 588

Quoted 1 line
man/man8/bridge.8 +1 -0
+locked port feature so that MAC address can get access through a locked

s/MAC address/a host/ ?

man/man8/bridge.8 The common use is that hosts are allowed access through authentication · line 592

Quoted 4 lines
man/man8/bridge.8 +4 -0
+port based on acceptlists, thus it is a much simpler procedure for a
+device to become authorized than f.ex. the 802.1X protocol, and is used
+for devices that are not capable of password or crypto based authorization
+methods.

This is a high level description of the option, but it is missing the part that ties it to the "locked" FDB entries.

Speaking of which, the "locked" flag needs to be described in man/man8/bridge.8 (in a different patch)

Quoted 18 lines
man/man8/bridge.8 +0 -0
 .TP
 .BI backup_port " DEVICE"
man/man8/ip-link.8.in +3 -0
index fc9d62fc..187ca7ca 100644
@@ -2454,6 +2454,9 @@ the following additional arguments are supported:
 .BR isolated " { " on " | " off " }"
 ] [
 .BR locked " { " on " | " off " }"
+] [
+.BR mab " { " on " | " off " }"
+] [
 .BR backup_port " DEVICE"
 ] [
 .BR nobackup_port " ]"

man/man8/ip-link.8.in default this flag is off. · line 2569

Quoted 7 lines
man/man8/ip-link.8.in +4 -0
@@ -2560,6 +2563,11 @@ default this flag is off.
 behind the port cannot communicate through the port unless a FDB entry
 representing the host is in the FDB. By default this flag is off.
 
+.BR mab " { " on " | " off " }"
+- enables or disables the MAB/MacAuth feature on a locked port. It is
+thus possible for a device to gain authorization on a locked port based
+on acceptlists.

Why not just copy-paste the previous description?

Quoted 7 lines
man/man8/ip-link.8.in +1 -0
+
 .BI backup_port " DEVICE"
 - if the port loses carrier all traffic will be redirected to the
 configured backup port
Signature · 1 line
2.34.1
#8 lore raw
Quoted 6 lines · Ido Schimmel
Quoted 2 lines · Hans Schultz

The MAB feature can be enabled on a locked port with the command:
bridge link set dev <DEV> mab on

Please provide regular and JSON output in the commit message.

How would the JSON version look like in this example?

maintainer
#9 lore raw
Quoted 9 lines · On Sat, Oct 01, 2022 at 11:32:52PM +0200, [email protected] wrote:
Quoted 6 lines · Ido Schimmel
Quoted 2 lines · Hans Schultz

The MAB feature can be enabled on a locked port with the command:
bridge link set dev <DEV> mab on

Please provide regular and JSON output in the commit message.

How would the JSON version look like in this example?

$ bridge -d link show dev dummy10
558: dummy10: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 master br0 state disabled priority 32 cost 100 
    hairpin off guard off root_block off fastleave off learning on flood on mcast_flood on mcast_to_unicast off neigh_suppress off vlan_tunnel off isolated off
$ bridge -d -j -p link show dev dummy10
[ {
        "ifindex": 558,
        "ifname": "dummy10",
        "flags": [ "BROADCAST","NOARP","UP","LOWER_UP" ],
        "mtu": 1500,
        "master": "br0",
        "state": "disabled",
        "priority": 32,
        "cost": 100,
        "hairpin": false,
        "guard": false,
        "root_block": false,
        "fastleave": false,
        "learning": true,
        "flood": true,
        "mcast_flood": true,
        "mcast_to_unicast": false,
        "neigh_suppress": false,
        "vlan_tunnel": false,
        "isolated": false
    } ]
#10 lore raw
In reply to Ido Schimmel
Quoted 5 lines · Ido Schimmel

IIRC, in the past David asked to either not send the uAPI files or send them as a first patch which he then uses as a hint to sync the files himself.

Does that imply that I make a patch in the beginning for the include/uapi changes wrt the Locked flag and another in the same manner for the Blackhole, or just one patch for both of them as the very first patch?

#11 lore raw
Quoted 10 lines · On Sun, Oct 02, 2022 at 05:20:31PM +0200, [email protected] wrote:
Quoted 5 lines · Ido Schimmel

IIRC, in the past David asked to either not send the uAPI files or send them as a first patch which he then uses as a hint to sync the files himself.

Does that imply that I make a patch in the beginning for the include/uapi changes wrt the Locked flag and another in the same manner for the Blackhole, or just one patch for both of them as the very first patch?

One patch for both as the very first patch. Example:

https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/ad9b63d5c76d9ef045dfed6dc9b5ab946e62e450.1615985531.git.petrm@nvidia.com/

The patch is obviously not needed if the uAPI files were already updated by David.