From patchwork Sat Nov 14 22:54:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905881 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3177FC56202 for ; Sat, 14 Nov 2020 22:54:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA5482415A for ; Sat, 14 Nov 2020 22:54:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="znuRZJkf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726382AbgKNWye (ORCPT ); Sat, 14 Nov 2020 17:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbgKNWyd (ORCPT ); Sat, 14 Nov 2020 17:54:33 -0500 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A31C0617A7 for ; Sat, 14 Nov 2020 14:54:33 -0800 (PST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4CYVyZ6n4SzQl1t; Sat, 14 Nov 2020 23:54:30 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pmachata.org; s=MBO0001; t=1605394469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zi8jG1Y9NOLgXzA1rQA/blRS5lcPOzUMR9gZLpM6Yxw=; b=znuRZJkfpZxfI4Ny7fGHXmvprdKuzrNXopikPjbEygzg1MzZecTskDL+g49zb6D6S1q2DY 0xs/LuYflY1vqVgrPtpq9KyHLBwCnuULxHvgEgl1ULqAak3TH5ZwgKyYllLIT5oBupFUs5 N39D2+Jahr0dL9EmW1s98Fksid3Yo/CmPfZnlXZeWDjIfgE51LlBPGxhsCv4Lch3TDl7+7 tHia7Ta6Ww+Pujh1IClRvVHEibe9YQGxbEN4lgcTrHCnNdPs6CaMUNo7aw5D3iEJd4gH7e 3Mg8ABTLpeeN9XUsu9Lx6cddr04YT2BWlaDbOGZ2nux2y1oNjateeFBTB/3DsA== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id E3Y-khGL2H-u; Sat, 14 Nov 2020 23:54:28 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 6/7] ip: ipnetconf: Convert to use print_on_off() Date: Sat, 14 Nov 2020 23:54:00 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.07 / 15.00 / 15.00 X-Rspamd-Queue-Id: 034991825 X-Rspamd-UID: 369208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Instead of rolling a custom on-off printer, use the one added to utils.c. Signed-off-by: Petr Machata --- ip/ipnetconf.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c index 0e946ca34b4a..bb0ebe12da93 100644 --- a/ip/ipnetconf.c +++ b/ip/ipnetconf.c @@ -41,14 +41,6 @@ static void usage(void) exit(-1); } -static void print_onoff(FILE *fp, const char *flag, __u32 val) -{ - if (is_json_context()) - print_bool(PRINT_JSON, flag, NULL, val); - else - fprintf(fp, "%s %s ", flag, val ? "on" : "off"); -} - static struct rtattr *netconf_rta(struct netconfmsg *ncm) { return (struct rtattr *)((char *)ncm @@ -117,8 +109,8 @@ int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg) } if (tb[NETCONFA_FORWARDING]) - print_onoff(fp, "forwarding", - rta_getattr_u32(tb[NETCONFA_FORWARDING])); + print_on_off(PRINT_ANY, "forwarding", "forwarding %s ", + rta_getattr_u32(tb[NETCONFA_FORWARDING])); if (tb[NETCONFA_RP_FILTER]) { __u32 rp_filter = rta_getattr_u32(tb[NETCONFA_RP_FILTER]); @@ -133,19 +125,21 @@ int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg) } if (tb[NETCONFA_MC_FORWARDING]) - print_onoff(fp, "mc_forwarding", - rta_getattr_u32(tb[NETCONFA_MC_FORWARDING])); + print_on_off(PRINT_ANY, "mc_forwarding", "mc_forwarding %s ", + rta_getattr_u32(tb[NETCONFA_MC_FORWARDING])); if (tb[NETCONFA_PROXY_NEIGH]) - print_onoff(fp, "proxy_neigh", - rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH])); + print_on_off(PRINT_ANY, "proxy_neigh", "proxy_neigh %s ", + rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH])); if (tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]) - print_onoff(fp, "ignore_routes_with_linkdown", - rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN])); + print_on_off(PRINT_ANY, "ignore_routes_with_linkdown", + "ignore_routes_with_linkdown %s ", + rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN])); if (tb[NETCONFA_INPUT]) - print_onoff(fp, "input", rta_getattr_u32(tb[NETCONFA_INPUT])); + print_on_off(PRINT_ANY, "input", "input %s ", + rta_getattr_u32(tb[NETCONFA_INPUT])); close_json_object(); print_string(PRINT_FP, NULL, "\n", NULL);