lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <e55dec9ff62227636a4782bda3cfa7e063e614f0.1748382868.git.stfomichev@gmail.com>
Date: Tue, 27 May 2025 14:55:06 -0700
From: Stanislav Fomichev <stfomichev@...il.com>
To: netdev@...r.kernel.org
Cc: dsahern@...il.com,
	Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH iproute2-next] ip: support setting multiple features

Commit a043bea75002 ("ip route: add support for TCP usec TS") added
support for tcp_usec_ts but the existing code was not adjusted
to handle multiple features in the same invocation:

$ ip route add .. dev .. features tcp_usec_ts ecn
Error: either "to" is duplicate, or "ecn" is garbage.

The code exits the while loop as soon as it encounters any feature,
make it more flexible. Tested with the following:

$ ip route add .. dev .. features tcp_usec_ts ecn
$ ip route add .. dev .. features tcp_usec_ts ecn quickack 1

Cc: Stephen Hemminger <stephen@...workplumber.org>
Fixes: a043bea75002 ("ip route: add support for TCP usec TS")
Signed-off-by: Stanislav Fomichev <stfomichev@...il.com>
---
v2: separate logic into separate function (Stephen)
---
 ip/iproute.c | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 0e2c171f4b8e..c2538894da63 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1134,6 +1134,27 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
 	return 0;
 }

+static unsigned int parse_features(int *argcp, char ***argvp)
+{
+	unsigned int features = 0;
+	char **argv = *argvp;
+	int argc = *argcp;
+
+	while (++argv, --argc > 0) {
+		if (strcmp(*argv, "ecn") == 0) {
+			features |= RTAX_FEATURE_ECN;
+		} else if (strcmp(*argv, "tcp_usec_ts") == 0) {
+			features |= RTAX_FEATURE_TCP_USEC_TS;
+		} else {
+			break;
+		}
+	}
+
+	*argcp = argc;
+	*argvp = argv;
+	return features;
+}
+
 static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 {
 	struct {
@@ -1374,17 +1395,14 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 		} else if (matches(*argv, "features") == 0) {
 			unsigned int features = 0;

-			while (argc > 0) {
-				NEXT_ARG();
+			features = parse_features(&argc, &argv);
+			if (!features)
+				invarg("\"features\" value not valid\n", *argv);

-				if (strcmp(*argv, "ecn") == 0)
-					features |= RTAX_FEATURE_ECN;
-				else if (strcmp(*argv, "tcp_usec_ts") == 0)
-					features |= RTAX_FEATURE_TCP_USEC_TS;
-				else
-					invarg("\"features\" value not valid\n", *argv);
-				break;
-			}
+			/* parse_features stops at the first feature it can't
+			 * parse, rewind one argument back.
+			 */
+			PREV_ARG();

 			rta_addattr32(mxrta, sizeof(mxbuf),
 				      RTAX_FEATURES, features);
--
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ