From patchwork Mon Aug 6 17:55:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrell Ball X-Patchwork-Id: 954080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WKIl1tYs"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41klgM3XBrz9rvt for ; Tue, 7 Aug 2018 03:55:42 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A65EDBE1; Mon, 6 Aug 2018 17:55:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id DD4F025A for ; Mon, 6 Aug 2018 17:55:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl0-f48.google.com (mail-pl0-f48.google.com [209.85.160.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 94E4F7C2 for ; Mon, 6 Aug 2018 17:55:39 +0000 (UTC) Received: by mail-pl0-f48.google.com with SMTP id f6-v6so5970892plo.1 for ; Mon, 06 Aug 2018 10:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=ML31Kt3+5w5Lk4cHupInPD4q1Oa9jgXVR65zbeg1kJo=; b=WKIl1tYsuzl+dBD68l475+5YRjWtN/29V1TLxMZT+UuDMi4bp2mrK3O1CSPummLMEo o0euXH+EPugs8kEcvSTgWy5IVeXewMNrPGbIG8NHhIojyEhTMsFSDK1C6bB2svuVa5cI ZAQvn61w3xY9a/22LhPsDA/NZtDmqZfmL4BHEOL3if+VEmBv3nZtpnxMXzPea6NuXWst avVQuzjP3yZ0l+IRC+y2hf/rNnA14mFirWNk7Q91F0eYNrHaWKNwIwSCi43trahOanVr 4L1mJRIy16t75L/OK6bfiXviP44c6HhJbVidGHPrIucRKZJojHK/kjb1YJ+a6GjVL2MU GqkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=ML31Kt3+5w5Lk4cHupInPD4q1Oa9jgXVR65zbeg1kJo=; b=oUMvn3yKRjvtBQQI8SKnVieqORQiMkiztZ5qQcYFIQgmQhQ1Nq9WUSL7ZUemuc2gEC XXB92vnaGi/Qy4IivFciefDRoyA0101LzAgtjqQvWps0+Qi6LFgQva8gT+vqvXZCIkvm RJpXcpzJ83bUirtfpBNgBRwhOnFo4tHoZ0nlm87VD4+5csHRVw2AL/PT/kDKEN1B2w3n Eodbjn9cZxY/EzeF0dj+IkzZ3QqnBJYDRKAQBLWFlxiHes2nxLFZXXoO2EcoG2Nn48to CODmsIIigNOsXUJbX+LH8g52sMpVR6dune3GwbMowFqe4mgvqtAbc2ZIXvpVAT8QHQB+ wCeA== X-Gm-Message-State: AOUpUlElZBfH4n4U6tbN/a5Jd8MxgSLGgYupios3DbJrq9pUcN1YVC4E vh/5juwKY24tSyeFm/GlGRw= X-Google-Smtp-Source: AAOMgpcoo6A5pSRGuLw/Gn5SguQnUH3gsXIg+woROMlpCYSx5Dn2zTrV+36S3Kas9EYMw/xuE4DA0g== X-Received: by 2002:a17:902:18a:: with SMTP id b10-v6mr15046461plb.62.1533578139216; Mon, 06 Aug 2018 10:55:39 -0700 (PDT) Received: from ubuntu.localdomain (c-73-162-236-45.hsd1.ca.comcast.net. [73.162.236.45]) by smtp.gmail.com with ESMTPSA id m26-v6sm30832053pfi.102.2018.08.06.10.55.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Aug 2018 10:55:37 -0700 (PDT) From: Darrell Ball To: dlu998@gmail.com, dev@openvswitch.org Date: Mon, 6 Aug 2018 10:55:26 -0700 Message-Id: <1533578127-115799-1-git-send-email-dlu998@gmail.com> X-Mailer: git-send-email 1.9.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [patch v3 1/2] dpctl: Simplify dpctl_flush_conntrack. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The function dpctl_flush_conntrack() and other such new functions with multiple optional arguments can be simplified by reodering the checks for optional parameters, where the datapath argument is checked for last. Signed-off-by: Darrell Ball --- lib/dpctl.c | 58 ++++++++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/lib/dpctl.c b/lib/dpctl.c index 4f1e443..c600eeb 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -1309,61 +1309,35 @@ static int dpctl_flush_conntrack(int argc, const char *argv[], struct dpctl_params *dpctl_p) { - struct dpif *dpif; + struct dpif *dpif = NULL; struct ct_dpif_tuple tuple, *ptuple = NULL; struct ds ds = DS_EMPTY_INITIALIZER; uint16_t zone, *pzone = NULL; - char *name; - int error, i = 1; - bool got_dpif = false; - - /* Parse datapath name. It is not a mandatory parameter for this command. - * If it is not specified, we retrieve it from the current setup, - * assuming only one exists. */ - if (argc >= 2) { - error = parsed_dpif_open(argv[i], false, &dpif); - if (!error) { - got_dpif = true; - i++; - } else if (argc == 4) { - dpctl_error(dpctl_p, error, "invalid datapath"); - return error; - } - } - if (!got_dpif) { - name = get_one_dp(dpctl_p); - if (!name) { - return EINVAL; - } - error = parsed_dpif_open(name, false, &dpif); - free(name); - if (error) { - dpctl_error(dpctl_p, error, "opening datapath"); - return error; - } + int error; + int args = argc - 1; + + /* Parse ct tuple */ + if (args && ct_dpif_parse_tuple(&tuple, argv[args], &ds)) { + ptuple = &tuple; + args--; } /* Parse zone */ - if (argc > i && ovs_scan(argv[i], "zone=%"SCNu16, &zone)) { + if (args && ovs_scan(argv[args], "zone=%"SCNu16, &zone)) { pzone = &zone; - i++; + args--; } + /* Report error if there are more than one unparsed argument. */ - if (argc - i > 1) { - ds_put_cstr(&ds, "invalid zone"); + if (args > 1) { + ds_put_cstr(&ds, "invalid arguments"); error = EINVAL; goto error; } - /* Parse ct tuple */ - if (argc > i && ct_dpif_parse_tuple(&tuple, argv[i], &ds)) { - ptuple = &tuple; - i++; - } - /* Report error if there is an unparsed argument. */ - if (argc - i) { - error = EINVAL; - goto error; + error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif); + if (error) { + return error; } error = ct_dpif_flush(dpif, pzone, ptuple);