netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2-next] ip: support setting multiple features
@ 2025-05-27 21:55 Stanislav Fomichev
  2025-05-31 16:11 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Stanislav Fomichev @ 2025-05-27 21:55 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, Stephen Hemminger

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@networkplumber.org>
Fixes: a043bea75002 ("ip route: add support for TCP usec TS")
Signed-off-by: Stanislav Fomichev <stfomichev@gmail.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2-next] ip: support setting multiple features
  2025-05-27 21:55 [PATCH iproute2-next] ip: support setting multiple features Stanislav Fomichev
@ 2025-05-31 16:11 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2025-05-31 16:11 UTC (permalink / raw)
  To: Stanislav Fomichev, netdev; +Cc: Stephen Hemminger

On 5/27/25 3:55 PM, Stanislav Fomichev wrote:
> 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@networkplumber.org>
> Fixes: a043bea75002 ("ip route: add support for TCP usec TS")
> Signed-off-by: Stanislav Fomichev <stfomichev@gmail.com>
> ---
> v2: separate logic into separate function (Stephen)
> ---
>  ip/iproute.c | 38 ++++++++++++++++++++++++++++----------
>  1 file changed, 28 insertions(+), 10 deletions(-)
> 

applied to iproute2-next. Thanks



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-31 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27 21:55 [PATCH iproute2-next] ip: support setting multiple features Stanislav Fomichev
2025-05-31 16:11 ` David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).