From patchwork Sat Nov 14 22:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905879 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 8FB3BC5519F for ; Sat, 14 Nov 2020 22:54:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F138824102 for ; Sat, 14 Nov 2020 22:54:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="IrcqDivV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbgKNWyc (ORCPT ); Sat, 14 Nov 2020 17:54:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbgKNWyb (ORCPT ); Sat, 14 Nov 2020 17:54:31 -0500 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59E29C0613D1 for ; Sat, 14 Nov 2020 14:54:31 -0800 (PST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (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-101.mailbox.org (Postfix) with ESMTPS id 4CYVyX3ZyszQjgg; Sat, 14 Nov 2020 23:54:28 +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=1605394466; 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=dUS9jOOAuzSoUyy/xwxRj5MFhtbHRbp7RM71rXERF2I=; b=IrcqDivV4IWznSQpr8b/JlwnhVE58deuJY2J9+Y4tkZyC1knfwkYsIbc39f+ov0UxVLi4z R0QjpBzHfHy0p8LnQgS0BCEDmC+C3zNrffXKc2l6wouxSEdRJEJpNCAC3goyTjuZ72jL4u 5CpL1G9gmwWCcbcS8kx6PQHz0N7tOJDtdLal6eqmzRoQIwirr9GlBnum4Nr6BWlFS69lO+ WTvNdA9XFqnTfANwrzC3dhmL1ujhvsKElFl9iKh5HmTW3xq6ni7b50PbJsP4Vnhq3X0sLu VTEFhRVh8j9v1toBZuucACigcxm+s46Tb5RcGf8TiDDCluWlbLuX+ZLLYUlc2A== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id cFlkO0XL31jK; Sat, 14 Nov 2020 23:54:25 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 1/7] bridge: link: Port over to parse_on_off() Date: Sat, 14 Nov 2020 23:53:55 +0100 Message-Id: <97d607c78f923b30a09f11d008b4fcda742c02d4.1605393324.git.me@pmachata.org> In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.36 / 15.00 / 15.00 X-Rspamd-Queue-Id: 812E31825 X-Rspamd-UID: 92a9b1 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Convert bridge/link.c from a custom on_off parser to the new global one. Signed-off-by: Petr Machata --- bridge/link.c | 79 ++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/bridge/link.c b/bridge/link.c index 3bc7af209b8b..fa6eda849b32 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -275,22 +275,6 @@ static void usage(void) exit(-1); } -static bool on_off(char *arg, __s8 *attr, char *val) -{ - if (strcmp(val, "on") == 0) - *attr = 1; - else if (strcmp(val, "off") == 0) - *attr = 0; - else { - fprintf(stderr, - "Error: argument of \"%s\" must be \"on\" or \"off\"\n", - arg); - return false; - } - - return true; -} - static int brlink_modify(int argc, char **argv) { struct { @@ -323,6 +307,7 @@ static int brlink_modify(int argc, char **argv) __s16 mode = -1; __u16 flags = 0; struct rtattr *nest; + int ret; while (argc > 0) { if (strcmp(*argv, "dev") == 0) { @@ -330,40 +315,49 @@ static int brlink_modify(int argc, char **argv) d = *argv; } else if (strcmp(*argv, "guard") == 0) { NEXT_ARG(); - if (!on_off("guard", &bpdu_guard, *argv)) - return -1; + bpdu_guard = parse_on_off("guard", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "hairpin") == 0) { NEXT_ARG(); - if (!on_off("hairpin", &hairpin, *argv)) - return -1; + hairpin = parse_on_off("hairpin", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "fastleave") == 0) { NEXT_ARG(); - if (!on_off("fastleave", &fast_leave, *argv)) - return -1; + fast_leave = parse_on_off("fastleave", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "root_block") == 0) { NEXT_ARG(); - if (!on_off("root_block", &root_block, *argv)) - return -1; + root_block = parse_on_off("root_block", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "learning") == 0) { NEXT_ARG(); - if (!on_off("learning", &learning, *argv)) - return -1; + learning = parse_on_off("learning", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "learning_sync") == 0) { NEXT_ARG(); - if (!on_off("learning_sync", &learning_sync, *argv)) - return -1; + learning_sync = parse_on_off("learning_sync", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "flood") == 0) { NEXT_ARG(); - if (!on_off("flood", &flood, *argv)) - return -1; + flood = parse_on_off("flood", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "mcast_flood") == 0) { NEXT_ARG(); - if (!on_off("mcast_flood", &mcast_flood, *argv)) - return -1; + mcast_flood = parse_on_off("mcast_flood", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "mcast_to_unicast") == 0) { NEXT_ARG(); - if (!on_off("mcast_to_unicast", &mcast_to_unicast, *argv)) - return -1; + mcast_to_unicast = parse_on_off("mcast_to_unicast", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "cost") == 0) { NEXT_ARG(); cost = atoi(*argv); @@ -404,18 +398,19 @@ static int brlink_modify(int argc, char **argv) flags |= BRIDGE_FLAGS_MASTER; } else if (strcmp(*argv, "neigh_suppress") == 0) { NEXT_ARG(); - if (!on_off("neigh_suppress", &neigh_suppress, - *argv)) - return -1; + neigh_suppress = parse_on_off("neigh_suppress", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "vlan_tunnel") == 0) { NEXT_ARG(); - if (!on_off("vlan_tunnel", &vlan_tunnel, - *argv)) - return -1; + vlan_tunnel = parse_on_off("vlan_tunnel", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "isolated") == 0) { NEXT_ARG(); - if (!on_off("isolated", &isolated, *argv)) - return -1; + isolated = parse_on_off("isolated", *argv, &ret); + if (ret) + return ret; } else if (strcmp(*argv, "backup_port") == 0) { NEXT_ARG(); backup_port_idx = ll_name_to_index(*argv); From patchwork Sat Nov 14 22:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905883 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 C0094C63697 for ; Sat, 14 Nov 2020 22:54:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A18824102 for ; Sat, 14 Nov 2020 22:54:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="ivSpC3R1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbgKNWyc (ORCPT ); Sat, 14 Nov 2020 17:54:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgKNWyb (ORCPT ); Sat, 14 Nov 2020 17:54:31 -0500 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C56C0613D2 for ; Sat, 14 Nov 2020 14:54:31 -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-101.mailbox.org (Postfix) with ESMTPS id 4CYVyY1GFczQlKG; Sat, 14 Nov 2020 23:54:29 +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=1605394467; 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=+u5u3Lg0CbyjmAxM+CEeypcUZ93rxPfCkV/la1WmHw0=; b=ivSpC3R1psv8jBmvoGPQ7ZQf1UsdzCzVXjLmdN7yYqFcWN5LLkMvPb8ygdf0QYWMiidykp KFDQFheF6J6rVX/OksgBSs4oIW5H8WKVPLj3+vito66bRi8nnueISkMMagX3Gp10D4gq/F 4WAmVPqcfnuYO4eSV6GQmGicUK5bO9xlQkH9m3AyLMnx/SaoQcySnFdoVXD4wacZ00TJn5 QfW/T//+U9er5m4yo4KnpopM0om5Hje8mohfNagtJLb46yI9J3RQlHhK/AlJhqgEnkTMgO oabECd9djRxr3/18Ba7XL1qhSyw5z1YiGXfuxT8eaIP9ecgocmxPvi0HUlW68A== Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id xNRU-9kNYod4; Sat, 14 Nov 2020 23:54:25 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 2/7] bridge: link: Convert to use print_on_off() Date: Sat, 14 Nov 2020 23:53:56 +0100 Message-Id: <60fb244156972652b22b3b5809a25b38c7502b39.1605393324.git.me@pmachata.org> In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.09 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2FB0D17E7 X-Rspamd-UID: acc96c 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 --- bridge/link.c | 56 ++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/bridge/link.c b/bridge/link.c index fa6eda849b32..d88c469db78e 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -78,14 +78,6 @@ static void print_portstate(__u8 state) "state (%d) ", state); } -static void print_onoff(FILE *fp, const char *flag, __u8 val) -{ - if (is_json_context()) - print_bool(PRINT_JSON, flag, NULL, val); - else - fprintf(fp, "%s %s ", flag, val ? "on" : "off"); -} - static void print_hwmode(__u16 mode) { if (mode >= ARRAY_SIZE(hw_mode)) @@ -123,38 +115,38 @@ static void print_protinfo(FILE *fp, struct rtattr *attr) fprintf(fp, "%s ", _SL_); if (prtb[IFLA_BRPORT_MODE]) - print_onoff(fp, "hairpin", - rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); + print_on_off(PRINT_ANY, "hairpin", "hairpin %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); if (prtb[IFLA_BRPORT_GUARD]) - print_onoff(fp, "guard", - rta_getattr_u8(prtb[IFLA_BRPORT_GUARD])); + print_on_off(PRINT_ANY, "guard", "guard %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_GUARD])); if (prtb[IFLA_BRPORT_PROTECT]) - print_onoff(fp, "root_block", - rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT])); + print_on_off(PRINT_ANY, "root_block", "root_block %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT])); if (prtb[IFLA_BRPORT_FAST_LEAVE]) - print_onoff(fp, "fastleave", - rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); + print_on_off(PRINT_ANY, "fastleave", "fastleave %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); if (prtb[IFLA_BRPORT_LEARNING]) - print_onoff(fp, "learning", - rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING])); + print_on_off(PRINT_ANY, "learning", "learning %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING])); if (prtb[IFLA_BRPORT_LEARNING_SYNC]) - print_onoff(fp, "learning_sync", - rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC])); + print_on_off(PRINT_ANY, "learning_sync", "learning_sync %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC])); if (prtb[IFLA_BRPORT_UNICAST_FLOOD]) - print_onoff(fp, "flood", - rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD])); + print_on_off(PRINT_ANY, "flood", "flood %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD])); if (prtb[IFLA_BRPORT_MCAST_FLOOD]) - print_onoff(fp, "mcast_flood", - rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD])); + print_on_off(PRINT_ANY, "mcast_flood", "mcast_flood %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD])); if (prtb[IFLA_BRPORT_MCAST_TO_UCAST]) - print_onoff(fp, "mcast_to_unicast", - rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_TO_UCAST])); + print_on_off(PRINT_ANY, "mcast_to_unicast", "mcast_to_unicast %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_TO_UCAST])); if (prtb[IFLA_BRPORT_NEIGH_SUPPRESS]) - print_onoff(fp, "neigh_suppress", - rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS])); + print_on_off(PRINT_ANY, "neigh_suppress", "neigh_suppress %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS])); if (prtb[IFLA_BRPORT_VLAN_TUNNEL]) - print_onoff(fp, "vlan_tunnel", - rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL])); + print_on_off(PRINT_ANY, "vlan_tunnel", "vlan_tunnel %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL])); if (prtb[IFLA_BRPORT_BACKUP_PORT]) { int ifidx; @@ -166,8 +158,8 @@ static void print_protinfo(FILE *fp, struct rtattr *attr) } if (prtb[IFLA_BRPORT_ISOLATED]) - print_onoff(fp, "isolated", - rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED])); + print_on_off(PRINT_ANY, "isolated", "isolated %s ", + rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED])); } else print_portstate(rta_getattr_u8(attr)); } From patchwork Sat Nov 14 22:53:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905885 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 B84C5C63699 for ; Sat, 14 Nov 2020 22:54:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 798D524170 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="eqqfE3FN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726357AbgKNWyd (ORCPT ); Sat, 14 Nov 2020 17:54:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbgKNWyc (ORCPT ); Sat, 14 Nov 2020 17:54:32 -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 1EE60C0613D2 for ; Sat, 14 Nov 2020 14:54:32 -0800 (PST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (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 4CYVyY3TK2zQkKG; Sat, 14 Nov 2020 23:54:29 +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=1605394467; 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=O1BS2wlJd+j4COExWE0BCzIjS6OYumVtlSK9jSU49P4=; b=eqqfE3FN/PvKPfx5qh+nV1PMvli2Zr6QCZwqhsRuUhLFQijztTG4QEOTfqExqRid9jxn6K rHe0ZOcuoYgnOgcYLbHg6YuddEUOr/02fjJ3KQuD59jhYpfbu4gtDsT+4Hn08jPmuX+wBT TLaG9nJUQIskgtAT3+lLLmRTM2T8vpiLYtyesqXM/uZ2SkM/ggbZtfSBEVZaGjL/PYrRKn fkRQxkW51WfZ1ojYGq8NoCq+up8aOXm9THM2JC+QJ9bjpFIfWGI6/6Is9c3ER2AY0XlNSx /TwtFdX4HsSRl3Y/7OVNsfL20HLOcBmOQdmQdFFy1X++ygGYo/v15h3MyPoPiQ== 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 vT4cFwxNwo34; Sat, 14 Nov 2020 23:54:26 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off() Date: Sat, 14 Nov 2020 23:53:57 +0100 Message-Id: <972a28d826eb677c3884aed70f893e7d257b1328.1605393324.git.me@pmachata.org> In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.36 / 15.00 / 15.00 X-Rspamd-Queue-Id: 74F5017DD X-Rspamd-UID: 8a6274 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Invoke parse_on_off() instead of rolling a custom function. Signed-off-by: Petr Machata --- ip/iplink.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index d6b766de1fcf..f5766c39507b 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -352,6 +352,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, int len, argc = *argcp; char **argv = *argvp; struct rtattr *vfinfo; + int ret; tivt.min_tx_rate = -1; tivt.max_tx_rate = -1; @@ -464,12 +465,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_spoofchk ivs; NEXT_ARG(); - if (matches(*argv, "on") == 0) - ivs.setting = 1; - else if (matches(*argv, "off") == 0) - ivs.setting = 0; - else - return on_off("spoofchk", *argv); + ivs.setting = parse_on_off("spoofchk", *argv, &ret); + if (ret) + return ret; ivs.vf = vf; addattr_l(&req->n, sizeof(*req), IFLA_VF_SPOOFCHK, &ivs, sizeof(ivs)); @@ -478,12 +476,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_rss_query_en ivs; NEXT_ARG(); - if (matches(*argv, "on") == 0) - ivs.setting = 1; - else if (matches(*argv, "off") == 0) - ivs.setting = 0; - else - return on_off("query_rss", *argv); + ivs.setting = parse_on_off("query_rss", *argv, &ret); + if (ret) + return ret; ivs.vf = vf; addattr_l(&req->n, sizeof(*req), IFLA_VF_RSS_QUERY_EN, &ivs, sizeof(ivs)); @@ -492,12 +487,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_trust ivt; NEXT_ARG(); - if (matches(*argv, "on") == 0) - ivt.setting = 1; - else if (matches(*argv, "off") == 0) - ivt.setting = 0; - else - invarg("Invalid \"trust\" value\n", *argv); + ivt.setting = parse_on_off("trust", *argv, &ret); + if (ret) + return ret; ivt.vf = vf; addattr_l(&req->n, sizeof(*req), IFLA_VF_TRUST, &ivt, sizeof(ivt)); @@ -595,6 +587,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) int index = 0; int group = -1; int addr_len = 0; + int err; ret = argc; @@ -738,12 +731,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) int carrier; NEXT_ARG(); - if (strcmp(*argv, "on") == 0) - carrier = 1; - else if (strcmp(*argv, "off") == 0) - carrier = 0; - else - return on_off("carrier", *argv); + carrier = parse_on_off("carrier", *argv, &err); + if (err) + return err; addattr8(&req->n, sizeof(*req), IFLA_CARRIER, carrier); } else if (strcmp(*argv, "vf") == 0) { @@ -896,12 +886,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) unsigned int proto_down; NEXT_ARG(); - if (strcmp(*argv, "on") == 0) - proto_down = 1; - else if (strcmp(*argv, "off") == 0) - proto_down = 0; - else - return on_off("protodown", *argv); + proto_down = parse_on_off("protodown", *argv, &err); + if (err) + return err; addattr8(&req->n, sizeof(*req), IFLA_PROTO_DOWN, proto_down); } else if (strcmp(*argv, "protodown_reason") == 0) { From patchwork Sat Nov 14 22:53:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905877 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 4B990C5519F for ; Sat, 14 Nov 2020 22:54:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2F372415A for ; Sat, 14 Nov 2020 22:54:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="klb+247s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbgKNWye (ORCPT ); Sat, 14 Nov 2020 17:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgKNWyc (ORCPT ); Sat, 14 Nov 2020 17:54:32 -0500 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050::465:201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC80AC0617A6 for ; Sat, 14 Nov 2020 14:54:32 -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-201.mailbox.org (Postfix) with ESMTPS id 4CYVyZ0RWvzQlWB; 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=1605394468; 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=A567HYBTP4riCgYWHUPr/7lhUfri1B3/kpTiv7QPqqE=; b=klb+247sSQx1ve97efp5MdHJ/0jW/cX2nWfnfpqq7kGWnmAYGHL513w8XvPMH8VWIgDU45 lbfQ6vz7upyFyewMLvriFhvq2WUkhcuZdeHbZ8ctcLm4cVPCl0/CMEgAGgwc/vTG+3Uchz /B0wlMFtAhVKnsvfSyuN87SwVYhJth/dCz5SlGfZZ7hNVEoJ8sEFlwdXjQIkqXEfndm8vQ 9GWchnWVbXryUPNdlin4nBLY9CEgUEgq1a28Zvww3FgfjEq6YDG6vw+V1On6PLJ/UKYnHN FKfAeK+8eKc84CnSRZ5eIZvfbQGq2cUq2iBdDBqgiiTwQweHKZE+iwrs0dbWLQ== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id CQ6gGUKqXW7m; Sat, 14 Nov 2020 23:54:26 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 4/7] ip: iplink_bridge_slave: Port over to parse_on_off() Date: Sat, 14 Nov 2020 23:53:58 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.33 / 15.00 / 15.00 X-Rspamd-Queue-Id: 0D23314AF X-Rspamd-UID: f18bcd Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Invoke parse_on_off() from bridge_slave_parse_on_off() instead of hand-rolling one. Exit on failure, because the invarg that was ivoked here before would. Signed-off-by: Petr Machata --- ip/iplink_bridge_slave.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index 79a1d2f5f5b8..f7f6da0c79b7 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -297,15 +297,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, static void bridge_slave_parse_on_off(char *arg_name, char *arg_val, struct nlmsghdr *n, int type) { - __u8 val; - - if (strcmp(arg_val, "on") == 0) - val = 1; - else if (strcmp(arg_val, "off") == 0) - val = 0; - else - invarg("should be \"on\" or \"off\"", arg_name); + int ret; + __u8 val = parse_on_off(arg_name, arg_val, &ret); + if (ret) + exit(1); addattr8(n, 1024, type, val); } From patchwork Sat Nov 14 22:53:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905875 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 B24F4C63777 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 2565E24178 for ; Sat, 14 Nov 2020 22:54:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="n2A6Mwkm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726395AbgKNWye (ORCPT ); Sat, 14 Nov 2020 17:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgKNWyc (ORCPT ); Sat, 14 Nov 2020 17:54:32 -0500 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B36C0613D1 for ; Sat, 14 Nov 2020 14:54:31 -0800 (PST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (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-101.mailbox.org (Postfix) with ESMTPS id 4CYVyZ3cl3zQlKL; 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=1605394468; 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=psnMnySTzs3xL0FKfZSgeFXvwcu+gO0Vdoiema7tXgg=; b=n2A6MwkmfUDyZRDBkl10174Jqj2vqRF6bwuZZi3+pqevFBXHkz8bkoW2RkXuwSKemcT+t6 aUg7eYrSU35coXDJjtDJ6nj2ITd1bM8MMzu6ZR0stxJd68pZADWd8vf9jKgXq9j6NO4m0q 7TDnaLfjxwLftvxsLQ/9EoVWGOnO3/2TZvZZIjrQnDsQ7JKzRWRv3i1hLWytBNAn8DbCGq vtY+aC0BawJAj/hBUZbaRyz57VyhHsrxX7yVPR/rXIgon3hcyQA7X6hmWaZg2SlG0DsTUx zQNNfeYmdV6D17ByPlw2Pc5Qs1uVEOnkgeCUICFA6A2FsWrLm/GzPvnFsxd5Kw== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id JBlAl97vwhRm; Sat, 14 Nov 2020 23:54:27 +0100 (CET) From: Petr Machata To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org Cc: Petr Machata Subject: [PATCH iproute2-next 5/7] ip: iplink_bridge_slave: Convert to use print_on_off() Date: Sat, 14 Nov 2020 23:53:59 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.06 / 15.00 / 15.00 X-Rspamd-Queue-Id: 7D61C17EB X-Rspamd-UID: 37d9f7 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. Note that _print_onoff() has an extra parameter for a JSON-specific flag name. However that argument is not used, and never was. Therefore when moving over to print_on_off(), drop this argument. Signed-off-by: Petr Machata --- ip/iplink_bridge_slave.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index f7f6da0c79b7..717875864b18 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -76,14 +76,6 @@ static void print_portstate(FILE *f, __u8 state) print_int(PRINT_ANY, "state_index", "state (%d) ", state); } -static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val) -{ - if (is_json_context()) - print_bool(PRINT_JSON, flag, NULL, val); - else - fprintf(f, "%s %s ", flag, val ? "on" : "off"); -} - static void _print_timer(FILE *f, const char *attr, struct rtattr *timer) { struct timeval tv; @@ -145,27 +137,27 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, rta_getattr_u32(tb[IFLA_BRPORT_COST])); if (tb[IFLA_BRPORT_MODE]) - _print_onoff(f, "mode", "hairpin", + print_on_off(PRINT_ANY, "hairpin", "hairpin %s ", rta_getattr_u8(tb[IFLA_BRPORT_MODE])); if (tb[IFLA_BRPORT_GUARD]) - _print_onoff(f, "guard", "guard", + print_on_off(PRINT_ANY, "guard", "guard %s ", rta_getattr_u8(tb[IFLA_BRPORT_GUARD])); if (tb[IFLA_BRPORT_PROTECT]) - _print_onoff(f, "protect", "root_block", + print_on_off(PRINT_ANY, "root_block", "root_block %s ", rta_getattr_u8(tb[IFLA_BRPORT_PROTECT])); if (tb[IFLA_BRPORT_FAST_LEAVE]) - _print_onoff(f, "fast_leave", "fastleave", + print_on_off(PRINT_ANY, "fastleave", "fastleave %s ", rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE])); if (tb[IFLA_BRPORT_LEARNING]) - _print_onoff(f, "learning", "learning", + print_on_off(PRINT_ANY, "learning", "learning %s ", rta_getattr_u8(tb[IFLA_BRPORT_LEARNING])); if (tb[IFLA_BRPORT_UNICAST_FLOOD]) - _print_onoff(f, "unicast_flood", "flood", + print_on_off(PRINT_ANY, "flood", "flood %s ", rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD])); if (tb[IFLA_BRPORT_ID]) @@ -233,11 +225,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING])); if (tb[IFLA_BRPORT_PROXYARP]) - _print_onoff(f, "proxyarp", "proxy_arp", + print_on_off(PRINT_ANY, "proxy_arp", "proxy_arp %s ", rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP])); if (tb[IFLA_BRPORT_PROXYARP_WIFI]) - _print_onoff(f, "proxyarp_wifi", "proxy_arp_wifi", + print_on_off(PRINT_ANY, "proxy_arp_wifi", "proxy_arp_wifi %s ", rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI])); if (tb[IFLA_BRPORT_MULTICAST_ROUTER]) @@ -255,15 +247,15 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]) ? "on" : "off"); if (tb[IFLA_BRPORT_MCAST_FLOOD]) - _print_onoff(f, "mcast_flood", "mcast_flood", + print_on_off(PRINT_ANY, "mcast_flood", "mcast_flood %s ", rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD])); if (tb[IFLA_BRPORT_MCAST_TO_UCAST]) - _print_onoff(f, "mcast_to_unicast", "mcast_to_unicast", + print_on_off(PRINT_ANY, "mcast_to_unicast", "mcast_to_unicast %s ", rta_getattr_u8(tb[IFLA_BRPORT_MCAST_TO_UCAST])); if (tb[IFLA_BRPORT_NEIGH_SUPPRESS]) - _print_onoff(f, "neigh_suppress", "neigh_suppress", + print_on_off(PRINT_ANY, "neigh_suppress", "neigh_suppress %s ", rta_getattr_u8(tb[IFLA_BRPORT_NEIGH_SUPPRESS])); if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) { @@ -279,11 +271,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, } if (tb[IFLA_BRPORT_VLAN_TUNNEL]) - _print_onoff(f, "vlan_tunnel", "vlan_tunnel", + print_on_off(PRINT_ANY, "vlan_tunnel", "vlan_tunnel %s ", rta_getattr_u8(tb[IFLA_BRPORT_VLAN_TUNNEL])); if (tb[IFLA_BRPORT_ISOLATED]) - _print_onoff(f, "isolated", "isolated", + print_on_off(PRINT_ANY, "isolated", "isolated %s ", rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED])); if (tb[IFLA_BRPORT_BACKUP_PORT]) { 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); From patchwork Sat Nov 14 22:54:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 11905887 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=-7.0 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, UNWANTED_LANGUAGE_BODY,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 76F31C56202 for ; Sat, 14 Nov 2020 22:54:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40E352415A for ; Sat, 14 Nov 2020 22:54:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pmachata.org header.i=@pmachata.org header.b="VMrJlSjj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726416AbgKNWyh (ORCPT ); Sat, 14 Nov 2020 17:54:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbgKNWye (ORCPT ); Sat, 14 Nov 2020 17:54:34 -0500 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E536AC0613D1 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-101.mailbox.org (Postfix) with ESMTPS id 4CYVyb4WmKzQjgg; Sat, 14 Nov 2020 23:54:31 +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=uqlQ23kdqZpfS+l2+AIpmp0Q53aI9litOdsPbB21G8A=; b=VMrJlSjjkI+WlTj2I9a+BUT8s0aQho4UEkE7uCpEzn3ChdYGZjbJilR+PuLZcj0R/HDP/L 2YDM0pPlizTz1JYKOs2mZP8NWNkMCsFQt38Y/iPu1xW1CiQU3bDcFWbP2+OU6QHbMXlFxX CVhTtcfd5erap5YMDMs+tuGlFuOgaXUUZJdTjPqh3gWRrIn1qmrrShLKHWPnnetbeLusQa MFwotMoa/p6T5i6gnrQFuBUdlMA1k0JI3oOIU9UM5KEA5iL2iU9AFaGCww5786Rv/tnhBr rJsvWUlDt3LvFqqtVRW/CrBRlSX0hqLUziwEvS1nJfyN2744iXCn+5clpiPXtA== Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id LBHIUtYpVeQU; 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 7/7] ip: iptuntap: Convert to use print_on_off() Date: Sat, 14 Nov 2020 23:54:01 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.08 / 15.00 / 15.00 X-Rspamd-Queue-Id: A345317E7 X-Rspamd-UID: 204a0b 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/iptuntap.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ip/iptuntap.c b/ip/iptuntap.c index 82e384998b1c..e9cc7c0f5f70 100644 --- a/ip/iptuntap.c +++ b/ip/iptuntap.c @@ -541,14 +541,6 @@ static void print_mq(FILE *f, struct rtattr *tb[]) } } -static void print_onoff(FILE *f, const char *flag, __u8 val) -{ - if (is_json_context()) - print_bool(PRINT_JSON, flag, NULL, !!val); - else - fprintf(f, "%s %s ", flag, val ? "on" : "off"); -} - static void print_type(FILE *f, __u8 type) { SPRINT_BUF(buf); @@ -573,17 +565,19 @@ static void tun_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) print_type(f, rta_getattr_u8(tb[IFLA_TUN_TYPE])); if (tb[IFLA_TUN_PI]) - print_onoff(f, "pi", rta_getattr_u8(tb[IFLA_TUN_PI])); + print_on_off(PRINT_ANY, "pi", "pi %s ", + rta_getattr_u8(tb[IFLA_TUN_PI])); if (tb[IFLA_TUN_VNET_HDR]) { - print_onoff(f, "vnet_hdr", - rta_getattr_u8(tb[IFLA_TUN_VNET_HDR])); + print_on_off(PRINT_ANY, "vnet_hdr", "vnet_hdr %s ", + rta_getattr_u8(tb[IFLA_TUN_VNET_HDR])); } print_mq(f, tb); if (tb[IFLA_TUN_PERSIST]) - print_onoff(f, "persist", rta_getattr_u8(tb[IFLA_TUN_PERSIST])); + print_on_off(PRINT_ANY, "persist", "persist %s ", + rta_getattr_u8(tb[IFLA_TUN_PERSIST])); if (tb[IFLA_TUN_OWNER]) print_owner(f, rta_getattr_u32(tb[IFLA_TUN_OWNER]));