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); From patchwork Mon Aug 6 17:55:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrell Ball X-Patchwork-Id: 954081 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="ojZWJLd9"; 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 41klgr4WZSz9rxx for ; Tue, 7 Aug 2018 03:56:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 70126C7F; Mon, 6 Aug 2018 17:55:43 +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 D489FBE6 for ; Mon, 6 Aug 2018 17:55:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 73E7F7C4 for ; Mon, 6 Aug 2018 17:55:41 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id x17-v6so7224179pfh.5 for ; Mon, 06 Aug 2018 10:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ynZ4jPbR5GconJ4NMq03o/eDXyiBwCrIlmbrxuZcVLs=; b=ojZWJLd9CGE8jsZlGPV7o4pnTTGUvrwp5LaROCvGymuukIPhSi/x5a9Dy33YWcs9ps mRyhh4aDuhvmXwxhHwRioPzCUB0t8s/ROI7AQBjVkawuaTQCTUnjAfpfmkdxnUpUI0c+ M0xz5NWVmHMmiwh+B04EjKysS7AenJMtNZO62T37zE6Dxnr1BCQFKzjWFYkHEaSDj3cu buNfE/YRYZS1fGxF9hzZHf/q9+zElWo2fshrfkwsmMjctOpWYiAUEp52lou0Zs0qlXZ1 hTrVbNR2MnL1GCJc2kbMSlD3jAFq96KUIBhE4i6+Y+KclsQHE0pWhJr4qRa6XVR0VDNH fsjg== 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:in-reply-to :references; bh=ynZ4jPbR5GconJ4NMq03o/eDXyiBwCrIlmbrxuZcVLs=; b=okTVdFXKuPeF6RyQHWlgkTIHSJJciAtvnlovBYhFHCa6Yvjo783QiOaA2R0SoYvbZO Ru+Wi/33Rus7Kb4PiDjQ7ro312H35sB+PjDXHhmcF9gm/VYlCUzYTZ4sKfbOS6FI/MTo nG4lafGmycTjNjnGyhCr2I7c0Ni0WMjfqraP1RreEsk6Lo3yCtarmhISmgNp3XZyAHY0 /zdr03Dg0KrffkI+kKXb1zgv1Hu4USuckVcxH8VLvk0jnyrFP1Yzs7kO5DlghzMnJI80 KBA6PUrmjiOv1pS+KWWeHlX9o9JicqwyrCLvHaYnFzVqaOZkvFTigFmdwnvIlFlPOfrt TfbQ== X-Gm-Message-State: AOUpUlF1/l/vD6ANGWMBjglo3LRYfiyQJIf1ODVzd+xUChdzx8SqBZd8 qhla/930xV6z5KbUEOCP05Y= X-Google-Smtp-Source: AAOMgpflvLJukDH6AoRKXeO24lTaetGkjcTscDMXD/6Nfu09DohP7EG+kKDZrnTCNNHFzlLmsB244Q== X-Received: by 2002:a65:46ca:: with SMTP id n10-v6mr15695575pgr.345.1533578141106; Mon, 06 Aug 2018 10:55:41 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Aug 2018 10:55:40 -0700 (PDT) From: Darrell Ball To: dlu998@gmail.com, dev@openvswitch.org Date: Mon, 6 Aug 2018 10:55:27 -0700 Message-Id: <1533578127-115799-2-git-send-email-dlu998@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1533578127-115799-1-git-send-email-dlu998@gmail.com> References: <1533578127-115799-1-git-send-email-dlu998@gmail.com> 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 2/2] dpctl: Make opt_dpif_open() more general. 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 By making opt_dpif_open() more general, it can be used effectively by all potential callers. Also, the error handling is improved by having more specific errors. Signed-off-by: Darrell Ball --- lib/dpctl.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---- tests/system-traffic.at | 8 +++--- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/lib/dpctl.c b/lib/dpctl.c index c600eeb..ebb1603 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -187,18 +187,77 @@ parsed_dpif_open(const char *arg_, bool create, struct dpif **dpifp) return result; } +static bool +dp_exists(const char *queried_dp) +{ + struct sset dpif_names = SSET_INITIALIZER(&dpif_names), + dpif_types = SSET_INITIALIZER(&dpif_types); + int error = 0; + bool found = false; + struct ds ds = DS_EMPTY_INITIALIZER;; + + dp_enumerate_types(&dpif_types); + + const char *type; + SSET_FOR_EACH (type, &dpif_types) { + error = dp_enumerate_names(type, &dpif_names); + if (!error) { + const char *name; + SSET_FOR_EACH (name, &dpif_names) { + struct dpif *dpif; + error = dpif_open(name, type, &dpif); + if (!error) { + dpif_close(dpif); + ds_put_cstr(&ds, type); + ds_put_cstr(&ds, "@"); + ds_put_cstr(&ds, name); + if (!strcmp(queried_dp, ds_cstr(&ds))) { + found = true; + goto out; + } + } + } + } + } + +out: + ds_destroy(&ds); + sset_destroy(&dpif_names); + sset_destroy(&dpif_types); + return found; +} + +static bool +dp_arg_exists(int argc, const char *argv[]) +{ + if (argc > 1 && dp_exists(argv[1])) { + return true; + } + return false; +} + /* Open a dpif with an optional name argument. * - * The datapath name is not a mandatory parameter for this command. If - * it is not specified -- so 'argc' < 'max_args' -- we retrieve it from - * the current setup, assuming only one exists. On success stores the - * opened dpif in '*dpifp'. */ + * The datapath name is not a mandatory parameter for this command. If it is + * not specified, we retrieve it from the current setup, assuming only one + * exists. On success stores the opened dpif in '*dpifp'. */ static int opt_dpif_open(int argc, const char *argv[], struct dpctl_params *dpctl_p, uint8_t max_args, struct dpif **dpifp) { + char *dpname; + if (dp_arg_exists(argc, argv)) { + dpname = xstrdup(argv[1]); + } else if (argc != max_args) { + dpname = get_one_dp(dpctl_p); + } else { + /* If the arguments are the maximum possible number and there is no + * valid datapath argument, then we fall into the case of dpname is + * NULL, since this is an error. */ + dpname = NULL; + } + int error = 0; - char *dpname = argc >= max_args ? xstrdup(argv[1]) : get_one_dp(dpctl_p); if (!dpname) { error = EINVAL; dpctl_error(dpctl_p, error, "datapath not found"); diff --git a/tests/system-traffic.at b/tests/system-traffic.at index cbd9542..d43d2ee 100644 --- a/tests/system-traffic.at +++ b/tests/system-traffic.at @@ -1124,17 +1124,17 @@ ovs-appctl: ovs-vswitchd: server returned an error ]) AT_CHECK([ovs-appctl dpctl/ct-set-maxconns one-bad-dp 10], [2], [], [dnl -ovs-vswitchd: opening datapath (Address family not supported by protocol) +ovs-vswitchd: datapath not found (Invalid argument) ovs-appctl: ovs-vswitchd: server returned an error ]) AT_CHECK([ovs-appctl dpctl/ct-get-maxconns one-bad-dp], [2], [], [dnl -ovs-vswitchd: opening datapath (Address family not supported by protocol) +ovs-vswitchd: datapath not found (Invalid argument) ovs-appctl: ovs-vswitchd: server returned an error ]) AT_CHECK([ovs-appctl dpctl/ct-get-nconns one-bad-dp], [2], [], [dnl -ovs-vswitchd: opening datapath (Address family not supported by protocol) +ovs-vswitchd: datapath not found (Invalid argument) ovs-appctl: ovs-vswitchd: server returned an error ]) @@ -1164,7 +1164,7 @@ AT_CHECK([ovs-appctl dpctl/ct-get-maxconns], [], [dnl 10 ]) -OVS_TRAFFIC_VSWITCHD_STOP(["/could not create datapath one-bad-dp of unknown type system/d"]) +OVS_TRAFFIC_VSWITCHD_STOP AT_CLEANUP AT_SETUP([conntrack - IPv6 ping])