From patchwork Thu May 25 16:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 13255463 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 087A81D2A2 for ; Thu, 25 May 2023 16:59:27 +0000 (UTC) Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC6C5135 for ; Thu, 25 May 2023 09:59:26 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5289ce6be53so919463a12.0 for ; Thu, 25 May 2023 09:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685033966; x=1687625966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aaevM9BfQQ0Et7TptAOei2iDqnn44+cVy5H+Vqe/tqg=; b=hVzCPPJRzOgdTY3YNfnhVyoG9L/G+lJ4S6MgCiZekNv6olo84/fGKM+tfEJM1poQV0 hcTZDx+UjHBpe0lHodLk4zTsxorGu/QrRgu5tywVK2ej75dFEv0utNm+UuZDMtbMBpji 2nshCmTqwYO+phhTCfm8o+E4SSEZCW2cB8nS/iEwjRIlCj/y4sfkCIY6vK/Mwc1Ri0Xl MJPOk7pWwTIifNfvS3CA4PjDTeVISUF7fbwmOBi22NKzXurFyS9Yn97R8nA1fUe89prB QEeeRnIaNjY7Kjh3WNVDAeahuOLaTlx65Yn3D5RXA/QuKhjFIeO1ALlVY960/KDS0oNm vycg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685033966; x=1687625966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aaevM9BfQQ0Et7TptAOei2iDqnn44+cVy5H+Vqe/tqg=; b=UFIolU2yyKkmSpP/vMMXf0rS04En70nxnZQjLT4WcXA1nssDpjEkdbVkaPyHWhokqA px86zNFvB22KGO3S+eCHi1vIhZELLOFOIk9QmcEu5dahOC3hxZmZMta1/afgyr0B+nnB WQp7s07DW0zphEpzcOt89nPDpB7hfZaDdcuNezFJ0C+lOKKXaC1GdbQ5ASBIH8uYF0Xy G5DnTVcQQZEaaAVTkOiMBo1RN5fPWpduaKI/Q61Z+G3v9xhWKYRXvILQbGtWapxcSWBx LjENpsnh9qzDbKEQ2FEjxSCpmrr7LSt9G78DrIuSIY83xHuh58RkgxoT2z1AEvrJG4Aq 1aNA== X-Gm-Message-State: AC+VfDy+sBVT7D26zjO0iVUXjKFWnhc9JifpzTTM7YLTS3Nslkrt7tTZ z1HtclnkmTVrpSRbc2IHxKE+AecG/4yRg7coxyjkog== X-Google-Smtp-Source: ACHHUZ6TX7LiQ9dsGf8FykMMngZQ8zn5rFgbrkYNCjGgVrpOMFMCylF2Kx+iVVeYkNgm405A4zLRxw== X-Received: by 2002:a17:902:d483:b0:1ac:788c:872a with SMTP id c3-20020a170902d48300b001ac788c872amr3143235plg.1.1685033966123; Thu, 25 May 2023 09:59:26 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id w3-20020a170902e88300b00194d14d8e54sm1662111plg.96.2023.05.25.09.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 09:59:25 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2 v3 1/2] vxlan: use print_nll for gbp and gpe Date: Thu, 25 May 2023 09:59:21 -0700 Message-Id: <20230525165922.9711-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525165922.9711-1-stephen@networkplumber.org> References: <20230525165922.9711-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com The Gbp and Gpe are presence, not booleans so use print_null() for them Signed-off-by: Stephen Hemminger --- ip/iplink_vxlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index c7e0e1c47606..cb6745c74507 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -650,9 +650,9 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true); if (tb[IFLA_VXLAN_GBP]) - print_bool(PRINT_ANY, "gbp", "gbp ", true); + print_null(PRINT_ANY, "gbp", "gbp ", NULL); if (tb[IFLA_VXLAN_GPE]) - print_bool(PRINT_ANY, "gpe", "gpe ", true); + print_null(PRINT_ANY, "gpe", "gpe ", NULL); } static void vxlan_print_help(struct link_util *lu, int argc, char **argv, From patchwork Thu May 25 16:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 13255464 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90CBF1D2C0 for ; Thu, 25 May 2023 16:59:29 +0000 (UTC) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8EC3189 for ; Thu, 25 May 2023 09:59:27 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64a9335a8e7so918152b3a.0 for ; Thu, 25 May 2023 09:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685033967; x=1687625967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wof52/YKL35hK6QvZIAtDZ2DrWAp9pXzuSFhNkcDxck=; b=iz8aMflFP5X9AbwT7XrNfwWVvCsfLqScfPf0B4uLByr/ivMlyvyK15Jg+3CLRWsYxN H+8O6SNafhVwm23Y6kyUFd3F7JcA6lprxNyKKLyS6D7wFAvZAH4B+py1nk4UYJwvtD5U wQ64hE8f6MgK7YSTGgAZ1g+rGAxvrUhTT78I8BOiqNia8baez5KVv9ZWUJo8LzEo5mQk 70z3/IoKkouCGh3aS3I+ybIzqHIcwVPvQA7pegIoMktAbGB2bL/kRc1xQvc7ABzvyF5E CHVy0QzECPMVMasbVN1b1gPDuP6dTcFBuZR30KNHxFeJKNiZa24xReqbS5k7Y6ywp44i wpWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685033967; x=1687625967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wof52/YKL35hK6QvZIAtDZ2DrWAp9pXzuSFhNkcDxck=; b=IYI+xm/Gk6pDPkajlVfpxSVIt/+hE3ZJYEio8N+4fkAVNXWqKFgVxK5BZrImRBPrQm GnbTqk2SOgWyzKorhPczHZCxgADlkg+SUjUQLJVKNCn/29BSeJ+MOOHnUNjfZvEawK9O otOdTBhUkIcIqF/4MZYLowp23wso8uf+zZqHV7SElahqUq9IB1RoH9VjoryFYha6GpX3 ptU0cS2dlFxncMZVTPHg5xljlVSdsjTC/HQJvIASF/ft4r/qEMNy6dDyq3IFLBkhEUUV xWlafeMx7hntcj25KXo1VUBssBA1Zp+Kj1/FbaSlJGnPGbpIeGylWmEwanUGbb6U9DIU CGiw== X-Gm-Message-State: AC+VfDx+Glt0qsWPWMuDuJlnfv57GOFoDHngvY7UyqPLJWo2Au7aA+j5 MzmDvMIX+5qwRBC60Jmze9LInQi2E1f6D1kRLAxdvw== X-Google-Smtp-Source: ACHHUZ77loWcCZkypvSQHZ/bypC/0qeJsZUke4Dzv7I9vwtBEJEwHI6ynok7m8f1/vGMsXgW7BZJ3w== X-Received: by 2002:a17:902:e5ce:b0:1a9:4cd5:e7e0 with SMTP id u14-20020a170902e5ce00b001a94cd5e7e0mr3037609plf.17.1685033967008; Thu, 25 May 2023 09:59:27 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id w3-20020a170902e88300b00194d14d8e54sm1662111plg.96.2023.05.25.09.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 09:59:26 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2 v3 2/2] vxlan: make option printing more consistent Date: Thu, 25 May 2023 09:59:22 -0700 Message-Id: <20230525165922.9711-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525165922.9711-1-stephen@networkplumber.org> References: <20230525165922.9711-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com Add new helper function print_bool_opt() which prints with no prefix and use it for vxlan options. If the option matches the expected default value, it is not printed if in non JSON mode unless the details setting is repeated. Signed-off-by: Stephen Hemminger --- include/json_print.h | 9 +++++ ip/iplink_vxlan.c | 91 +++++++++----------------------------------- lib/json_print.c | 19 +++++++++ 3 files changed, 46 insertions(+), 73 deletions(-) diff --git a/include/json_print.h b/include/json_print.h index 91b34571ceb0..49d3cc14789c 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -101,6 +101,15 @@ static inline int print_rate(bool use_iec, enum output_type t, return print_color_rate(use_iec, t, COLOR_NONE, key, fmt, rate); } +int print_color_bool_opt(enum output_type type, enum color_attr color, + const char *key, bool value, bool show); + +static inline int print_bool_opt(enum output_type type, + const char *key, bool value, bool show) +{ + return print_color_bool_opt(type, COLOR_NONE, key, value, show); +} + /* A backdoor to the size formatter. Please use print_size() instead. */ char *sprint_size(__u32 sz, char *buf); diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index cb6745c74507..3a7f8375b5c5 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -427,15 +427,15 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (!tb) return; - if (tb[IFLA_VXLAN_COLLECT_METADATA] && - rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) { - print_bool(PRINT_ANY, "external", "external ", true); +#define PRINT_VXLAN_OPTION(attr, opt, expect) \ + if (tb[attr]) { \ + __u8 opt = rta_getattr_u8(tb[attr]); \ + print_bool_opt(PRINT_ANY, #opt, opt, \ + opt != expect || show_details > 1); \ } - if (tb[IFLA_VXLAN_VNIFILTER] && - rta_getattr_u8(tb[IFLA_VXLAN_VNIFILTER])) { - print_bool(PRINT_ANY, "vnifilter", "vnifilter", true); - } + PRINT_VXLAN_OPTION(IFLA_VXLAN_COLLECT_METADATA, external, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_VNIFILTER, vnifilter, false); if (tb[IFLA_VXLAN_ID] && RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) >= sizeof(__u32)) { @@ -529,25 +529,11 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) "dstport %u ", rta_getattr_be16(tb[IFLA_VXLAN_PORT])); - if (tb[IFLA_VXLAN_LEARNING]) { - __u8 learning = rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]); - - print_bool(PRINT_JSON, "learning", NULL, learning); - if (!learning) - print_bool(PRINT_FP, NULL, "nolearning ", true); - } - - if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY])) - print_bool(PRINT_ANY, "proxy", "proxy ", true); - - if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC])) - print_bool(PRINT_ANY, "rsc", "rsc ", true); - - if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS])) - print_bool(PRINT_ANY, "l2miss", "l2miss ", true); - - if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS])) - print_bool(PRINT_ANY, "l3miss", "l3miss ", true); + PRINT_VXLAN_OPTION(IFLA_VXLAN_LEARNING, learning, true); + PRINT_VXLAN_OPTION(IFLA_VXLAN_PROXY, proxy, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_RSC, rsc, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_L2MISS, l2miss, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_L3MISS, l3miss, false); if (tb[IFLA_VXLAN_TOS]) tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]); @@ -601,58 +587,17 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0)) print_uint(PRINT_ANY, "limit", "maxaddr %u ", maxaddr); - if (tb[IFLA_VXLAN_UDP_CSUM]) { - __u8 udp_csum = rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]); - - if (is_json_context()) { - print_bool(PRINT_ANY, "udp_csum", NULL, udp_csum); - } else { - if (!udp_csum) - fputs("no", f); - fputs("udpcsum ", f); - } - } - - if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]) { - __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]); - - if (is_json_context()) { - print_bool(PRINT_ANY, - "udp_zero_csum6_tx", NULL, csum6); - } else { - if (!csum6) - fputs("no", f); - fputs("udp6zerocsumtx ", f); - } - } - - if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) { - __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]); - - if (is_json_context()) { - print_bool(PRINT_ANY, - "udp_zero_csum6_rx", - NULL, - csum6); - } else { - if (!csum6) - fputs("no", f); - fputs("udp6zerocsumrx ", f); - } - } - - if (tb[IFLA_VXLAN_REMCSUM_TX] && - rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX])) - print_bool(PRINT_ANY, "remcsum_tx", "remcsumtx ", true); - - if (tb[IFLA_VXLAN_REMCSUM_RX] && - rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX])) - print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true); + PRINT_VXLAN_OPTION(IFLA_VXLAN_UDP_CSUM, udp_csum, true); + PRINT_VXLAN_OPTION(IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp_zero_csum6_tx, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp_zero_csum6_rx, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_REMCSUM_TX, remcsum_tx, false); + PRINT_VXLAN_OPTION(IFLA_VXLAN_REMCSUM_RX, remcsum_rx, false); if (tb[IFLA_VXLAN_GBP]) print_null(PRINT_ANY, "gbp", "gbp ", NULL); if (tb[IFLA_VXLAN_GPE]) print_null(PRINT_ANY, "gpe", "gpe ", NULL); +#undef PRINT_VXLAN_OPTION } static void vxlan_print_help(struct link_util *lu, int argc, char **argv, diff --git a/lib/json_print.c b/lib/json_print.c index d7ee76b10de8..602de027ca27 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -215,6 +215,25 @@ int print_color_bool(enum output_type type, value ? "true" : "false"); } +/* In JSON mode, acts like print_color_bool. + * Otherwise, will print key with prefix of "no" if false. + * The show flag is used to suppres printing in non-JSON mode + */ +int print_color_bool_opt(enum output_type type, + enum color_attr color, + const char *key, + bool value, bool show) +{ + int ret = 0; + + if (_IS_JSON_CONTEXT(type)) + jsonw_bool_field(_jw, key, value); + else if (_IS_FP_CONTEXT(type) && show) + ret = color_fprintf(stdout, color, "%s%s ", + value ? "" : "no", key); + return ret; +} + int print_color_on_off(enum output_type type, enum color_attr color, const char *key,