Skip to contentSkip to conversation

seg6local: accept lblen and nflen in either order

PATCH New Dave Seddon 1 participant 1 message Nov 24

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

PATCH 1/1 seg6local: accept lblen and nflen in either order

The man page lists lblen and nflen as flavors attributes in no fixed order, but ip only accepts lblen first:

ip -6 route add 2001:db8:2::/64 dev lo encap seg6local action End \
flavors next-csid nflen 16 lblen 32
Error: either "to" is duplicate, or "lblen" is garbage.

Parse them in a loop.

Fixes 04a6b456bf74 ("seg6: add support for flavors in SRv6 End* behaviors")
Assisted-by Claude:claude-fable-5-2

---
This applies on top of "seg6local: fix crash when next-csid ends the command", as discussed in that thread.

 ip/iproute_lwtunnel.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)
ip/iproute_lwtunnel.c +22 -19
index 53004b5f..3a6bf7c0 100644
@@ -1433,27 +1433,30 @@ static int seg6local_parse_flavors(struct rtattr *rta, size_t len,
 		return ret;
 
 	if (flavors & (1 << SEG6_LOCAL_FLV_OP_NEXT_CSID)) {
-		NEXT_ARG_FWD();
-		if (argc > 0 && strcmp(*argv, "lblen") == 0) {
-			NEXT_ARG();
-			if (lbl_ok++)
-				duparg2("lblen", *argv);
-			if (get_u8(&lbl, *argv, 0))
-				invarg("\"locator-block length\" value is invalid\n", *argv);
-			ret = rta_addattr8(rta, len, SEG6_LOCAL_FLV_LCBLOCK_BITS, lbl);
-			NEXT_ARG_FWD();
-		}
-
-		if (argc > 0 && strcmp(*argv, "nflen") == 0) {
-			NEXT_ARG();
-			if (nfl_ok++)
-				duparg2("nflen", *argv);
-			if (get_u8(&nfl, *argv, 0))
-				invarg("\"locator-node function length\" value is invalid\n", *argv);
-			ret = rta_addattr8(rta, len, SEG6_LOCAL_FLV_LCNODE_FN_BITS, nfl);
+		while (NEXT_ARG_OK()) {
 			NEXT_ARG_FWD();
+			if (strcmp(*argv, "lblen") == 0) {
+				NEXT_ARG();
+				if (lbl_ok++)
+					duparg2("lblen", *argv);
+				if (get_u8(&lbl, *argv, 0))
+					invarg("\"locator-block length\" value is invalid\n",
+					       *argv);
+				ret = rta_addattr8(rta, len, SEG6_LOCAL_FLV_LCBLOCK_BITS, lbl);
+			} else if (strcmp(*argv, "nflen") == 0) {
+				NEXT_ARG();
+				if (nfl_ok++)
+					duparg2("nflen", *argv);
+				if (get_u8(&nfl, *argv, 0))
+					invarg("\"locator-node function length\" value is invalid\n",
+					       *argv);
+				ret = rta_addattr8(rta, len,
+						   SEG6_LOCAL_FLV_LCNODE_FN_BITS, nfl);
+			} else {
+				PREV_ARG();
+				break;
+			}
 		}
-		PREV_ARG();
 	}
 
 	rta_nest_end(rta, nest);
Signature · 1 line
2.56.0