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) {