Skip to contentSkip to conversation

bridge: fdb: add support for sticky flag

PATCH Applied Nikolay Aleksandrov 3 participants 4 messages Sep 27, 2018 – Sep 29, 2018

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

PATCH 1/1 bridge: fdb: add support for sticky flag

Add support for the new sticky flag that can be set on fdbs and update the man page.

---
 bridge/fdb.c      | 9 +++++++--
 man/man8/bridge.8 | 6 +++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
bridge/fdb.c +7 -2
index 4dbc894ceab9..828fdab264cb 100644
@@ -37,8 +37,8 @@ static void usage(void)
 	fprintf(stderr,
 		"Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
 		"              [ self ] [ master ] [ use ] [ router ] [ extern_learn ]\n"
-		"              [ local | static | dynamic ] [ dst IPADDR ] [ vlan VID ]\n"
-		"              [ port PORT] [ vni VNI ] [ via DEV ]\n"
+		"              [ sticky ] [ local | static | dynamic ] [ dst IPADDR ]\n"
+		"              [ vlan VID ] [ port PORT] [ vni VNI ] [ via DEV ]\n"
 		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n");
 	exit(-1);
 }
@@ -101,6 +101,9 @@ static void fdb_print_flags(FILE *fp, unsigned int flags)
 	if (flags & NTF_MASTER)
 		print_string(PRINT_ANY, NULL, "%s ", "master");
 
+	if (flags & NTF_STICKY)
+		print_string(PRINT_ANY, NULL, "%s ", "sticky");
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -414,6 +417,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
 			req.ndm.ndm_flags |= NTF_USE;
 		} else if (matches(*argv, "extern_learn") == 0) {
 			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
+		} else if (matches(*argv, "sticky") == 0) {
+			req.ndm.ndm_flags |= NTF_STICKY;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();
man/man8/bridge.8 +5 -1
index 53cd3d0a3d93..c0415bc646df 100644
@@ -63,7 +63,7 @@ bridge \- show / manipulate bridge addresses and devices
 .B dev
 .IR DEV " { "
 .BR local " | " static " | " dynamic " } [ "
-.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ " extern_learn " ] [ "
+.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ " extern_learn " ] [ " sticky " ] [ "
 .B dst
 .IR IPADDR " ] [ "
 .B vni
@@ -448,6 +448,10 @@ indicate to the kernel that an entry was hardware or user-space
 controller learnt dynamic entry. Kernel will not age such an entry.
 .sp
 
+.B sticky
+- this entry will not change its port due to learning.
+.sp
+
 .in -8
 The next command line parameters apply only
 when the specified device
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 selftests: forwarding: test for bridge sticky flag

This test adds an fdb entry with the sticky flag and sends traffic from a different port with the same mac as a source address expecting the entry to not change ports if the flag is operating correctly.

---
 .../selftests/net/forwarding/bridge_sticky_fdb.sh  | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/bridge_sticky_fdb.sh
tools/testing/selftests/net/forwarding/bridge_sticky_fdb.sh new file +69 -0
new file mode 100755
index 000000000000..1f8ef0eff862
@@ -0,0 +1,69 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ALL_TESTS="sticky"
+NUM_NETIFS=4
+TEST_MAC=de:ad:be:ef:13:37
+source lib.sh
+
+switch_create()
+{
+	ip link add dev br0 type bridge
+
+	ip link set dev $swp1 master br0
+	ip link set dev $swp2 master br0
+
+	ip link set dev br0 up
+	ip link set dev $h1 up
+	ip link set dev $swp1 up
+	ip link set dev $h2 up
+	ip link set dev $swp2 up
+}
+
+switch_destroy()
+{
+	ip link set dev $swp2 down
+	ip link set dev $h2 down
+	ip link set dev $swp1 down
+	ip link set dev $h1 down
+
+	ip link del dev br0
+}
+
+setup_prepare()
+{
+	h1=${NETIFS[p1]}
+	swp1=${NETIFS[p2]}
+	h2=${NETIFS[p3]}
+	swp2=${NETIFS[p4]}
+
+	switch_create
+}
+
+cleanup()
+{
+	pre_cleanup
+	switch_destroy
+}
+
+sticky()
+{
+	bridge fdb add $TEST_MAC dev $swp1 master static sticky
+	check_err $? "Could not add fdb entry"
+	bridge fdb del $TEST_MAC dev $swp1 vlan 1 master static sticky
+	$MZ $h2 -c 1 -a $TEST_MAC -t arp "request" -q
+	bridge -j fdb show br br0 brport $swp1\
+		| jq -e ".[] | select(.mac == \"$TEST_MAC\")" &> /dev/null
+	check_err $? "Did not find FDB record when should"
+
+	log_test "Sticky fdb entry"
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
Signature · 1 line
2.11.0
maintainer Applied
#2 lore raw

Re: [PATCH net-next] selftests: forwarding: test for bridge sticky flag

From: Nikolay Aleksandrov <[email protected]>
Date: Thu, 27 Sep 2018 16:35:13 +0300

Quoted 5 lines

This test adds an fdb entry with the sticky flag and sends traffic from a different port with the same mac as a source address expecting the entry to not change ports if the flag is operating correctly.

Applied, thanks.