[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250917122018.40ee1cbe@hermes.local>
Date: Wed, 17 Sep 2025 12:20:18 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: Alasdair McWilliam <alasdair@...illiam.dev>
Cc: David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org, Daniel
Borkmann <daniel@...earbox.net>
Subject: Re: [PATCH iproute2-next] ip: geneve: Add support for
IFLA_GENEVE_PORT_RANGE
On Wed, 17 Sep 2025 17:24:49 +0100
Alasdair McWilliam <alasdair@...illiam.dev> wrote:
> @@ -142,6 +143,22 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
> (uval & ~LABEL_MAX_MASK))
> invarg("invalid flowlabel", *argv);
> label = htonl(uval);
> + } else if (!matches(*argv, "port")
> + || !matches(*argv, "srcport")) {
> + struct ifla_geneve_port_range range = { 0, 0 };
> +
Do not use matches(), it leads to confusion because of duplicate prefixes.
It is only allowed in legacy iproute parts. I.e no new additions.
> + if (tb[IFLA_GENEVE_PORT_RANGE]) {
> + const struct ifla_geneve_port_range *r
> + = RTA_DATA(tb[IFLA_GENEVE_PORT_RANGE]);
> + if (is_json_context()) {
> + open_json_object("port_range");
> + print_uint(PRINT_JSON, "low", NULL, ntohs(r->low));
> + print_uint(PRINT_JSON, "high", NULL, ntohs(r->high));
> + close_json_object();
> + } else {
> + fprintf(f, "srcport %u %u ", ntohs(r->low), ntohs(r->high));
> + }
Do not use fprintf directly instead use multiple calls to print_uint like:
open_json_object("port_range");
print_uint(PRINT_ANY, "low", "srcport %u", ntohs(r->low));
print_uint(PRINT_ANY, "high", " %u ", ntohs(r->high));
close_json_object();
Avoid having json specific code with is_json_context() if possible.
It leads to untested code paths.
Powered by blists - more mailing lists