* [PATCH iproute2] ip: support setting multiple features
@ 2025-05-06 21:03 Stanislav Fomichev
2025-05-20 19:26 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Stanislav Fomichev @ 2025-05-06 21:03 UTC (permalink / raw)
To: netdev; +Cc: dsahern
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
Fixes: a043bea75002 ("ip route: add support for TCP usec TS")
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
ip/iproute.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/ip/iproute.c b/ip/iproute.c
index 0e2c171f4b8e..a692e7c47110 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1374,16 +1374,23 @@ 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) {
+ while (NEXT_ARG_OK()) {
NEXT_ARG();
- if (strcmp(*argv, "ecn") == 0)
+ if (strcmp(*argv, "ecn") == 0) {
features |= RTAX_FEATURE_ECN;
- else if (strcmp(*argv, "tcp_usec_ts") == 0)
+ } else if (strcmp(*argv, "tcp_usec_ts") == 0) {
features |= RTAX_FEATURE_TCP_USEC_TS;
- else
+ } else {
+ if (features) {
+ /* next arg possibly not a
+ * feature, try to rewind */
+ PREV_ARG();
+ break;
+ }
+
invarg("\"features\" value not valid\n", *argv);
- break;
+ }
}
rta_addattr32(mxrta, sizeof(mxbuf),
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH iproute2] ip: support setting multiple features
2025-05-06 21:03 [PATCH iproute2] ip: support setting multiple features Stanislav Fomichev
@ 2025-05-20 19:26 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2025-05-20 19:26 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: netdev, dsahern
On Tue, 6 May 2025 14:03:40 -0700
Stanislav Fomichev <sdf@fomichev.me> 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
>
> Fixes: a043bea75002 ("ip route: add support for TCP usec TS")
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> ---
> ip/iproute.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/ip/iproute.c b/ip/iproute.c
> index 0e2c171f4b8e..a692e7c47110 100644
> --- a/ip/iproute.c
> +++ b/ip/iproute.c
> @@ -1374,16 +1374,23 @@ 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) {
> + while (NEXT_ARG_OK()) {
> NEXT_ARG();
>
> - if (strcmp(*argv, "ecn") == 0)
> + if (strcmp(*argv, "ecn") == 0) {
> features |= RTAX_FEATURE_ECN;
> - else if (strcmp(*argv, "tcp_usec_ts") == 0)
> + } else if (strcmp(*argv, "tcp_usec_ts") == 0) {
> features |= RTAX_FEATURE_TCP_USEC_TS;
> - else
> + } else {
> + if (features) {
> + /* next arg possibly not a
> + * feature, try to rewind */
> + PREV_ARG();
> + break;
> + }
> +
> invarg("\"features\" value not valid\n", *argv);
> - break;
> + }
> }
>
> rta_addattr32(mxrta, sizeof(mxbuf),
> --
> 2.49.0
>
>
This really needs to be a function and handle them in any order.
Also then the unwind would be cleaner.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-20 19:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 21:03 [PATCH iproute2] ip: support setting multiple features Stanislav Fomichev
2025-05-20 19:26 ` Stephen Hemminger
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).