[ovs-dev,v2,09/11] dpctl: Refactor opt_dpif_open().

Message ID 1533170156-769-10-git-send-email-yihung.wei@gmail.com
State Changes Requested
Headers show
Series
  • conntrack zone limitation
Related show

Commit Message

Yi-Hung Wei Aug. 2, 2018, 12:35 a.m.
Make opt_dpif_open() to support mulitple optional arguments.  It will
be useful for the following patches.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 lib/dpctl.c | 85 ++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 44 insertions(+), 41 deletions(-)

Comments

Darrell Ball Aug. 2, 2018, 4:53 a.m. | #1
Thanks for the patch Yi-hung

This patch does not seem to fit with this series somehow; it seems more related
to flushing conntrack by zone and tuple ?

I had a generic change in my queue. I think it is more straightforward, since it
keeps opt_dpif_open() simple and improves the error handling and also simplifies
dpctl_flush_conntrack() and any potential similar functions. 

https://patchwork.ozlabs.org/patch/952580/




On 8/1/18, 5:45 PM, "ovs-dev-bounces@openvswitch.org on behalf of Yi-Hung Wei" <ovs-dev-bounces@openvswitch.org on behalf of yihung.wei@gmail.com> wrote:

    Make opt_dpif_open() to support mulitple optional arguments.  It will
    be useful for the following patches.
    
    Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
    ---
     lib/dpctl.c | 85 ++++++++++++++++++++++++++++++++-----------------------------
     1 file changed, 44 insertions(+), 41 deletions(-)
    
    diff --git a/lib/dpctl.c b/lib/dpctl.c
    index 4f1e443f2662..35733774b331 100644
    --- a/lib/dpctl.c
    +++ b/lib/dpctl.c
    @@ -191,14 +191,40 @@ parsed_dpif_open(const char *arg_, bool create, struct dpif **dpifp)
      *
      * 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 current setup, assuming only one exists.
    + * For commands with multiple optional arguments, we try to use the first
    + * argument as the dpif name. If it is failed, then we fallback to
    + * retrieve it form the current setup.
    + * On success stores the opened dpif in '*dpifp', and the next arugment
    + * to be parsed in '*indexp'.  */
     static int
     opt_dpif_open(int argc, const char *argv[], struct dpctl_params *dpctl_p,
    -              uint8_t max_args, struct dpif **dpifp)
    +              uint8_t max_args, struct dpif **dpifp, bool multi_opt,
    +              int *indexp)
     {
    +    char *dpname;
         int error = 0;
    -    char *dpname = argc >= max_args ? xstrdup(argv[1]) : get_one_dp(dpctl_p);
    +
    +    if (indexp) {
    +        *indexp = 1;
    +    }
    +
    +    if (multi_opt && argc > 1) {
    +        error = parsed_dpif_open(argv[1], false, dpifp);
    +        if (!error) {
    +            if (indexp) {
    +                *indexp = 2;
    +            }
    +            return 0;
    +        } else if (argc == max_args) {
    +            dpctl_error(dpctl_p, error, "invalid datapath");
    +            return error;
    +        }
    +        dpname = get_one_dp(dpctl_p);
    +    } else {
    +        dpname = argc >= max_args ? xstrdup(argv[1]) : get_one_dp(dpctl_p);
    +    }
    +
         if (!dpname) {
             error = EINVAL;
             dpctl_error(dpctl_p, error, "datapath not found");
    @@ -863,7 +889,7 @@ dpctl_dump_flows(int argc, const char *argv[], struct dpctl_params *dpctl_p)
             }
         }
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (error) {
             goto out_free;
         }
    @@ -990,7 +1016,7 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags,
         struct simap port_names;
         int n, error;
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1092,7 +1118,7 @@ dpctl_get_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
         struct ds ds;
         int n, error;
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1141,7 +1167,7 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
         struct simap port_names;
         int n, error;
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1210,7 +1236,7 @@ dpctl_del_flows(int argc, const char *argv[], struct dpctl_params *dpctl_p)
     {
         struct dpif *dpif;
     
    -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1271,7 +1297,7 @@ dpctl_dump_conntrack(int argc, const char *argv[],
             argc--;
         }
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1313,34 +1339,11 @@ dpctl_flush_conntrack(int argc, const char *argv[],
         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;
    -        }
    +    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, true, &i);
    +    if (error) {
    +        return error;
         }
     
         /* Parse zone */
    @@ -1412,7 +1415,7 @@ dpctl_ct_stats_show(int argc, const char *argv[],
             }
         }
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1537,7 +1540,7 @@ dpctl_ct_bkts(int argc, const char *argv[],
             }
         }
     
    -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (error) {
             return error;
         }
    @@ -1617,7 +1620,7 @@ dpctl_ct_set_maxconns(int argc, const char *argv[],
                           struct dpctl_params *dpctl_p)
     {
         struct dpif *dpif;
    -    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
    +    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
         if (!error) {
             uint32_t maxconns;
             if (ovs_scan(argv[argc - 1], "%"SCNu32, &maxconns)) {
    @@ -1643,7 +1646,7 @@ dpctl_ct_get_maxconns(int argc, const char *argv[],
                         struct dpctl_params *dpctl_p)
     {
         struct dpif *dpif;
    -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (!error) {
             uint32_t maxconns;
             error = ct_dpif_get_maxconns(dpif, &maxconns);
    @@ -1664,7 +1667,7 @@ dpctl_ct_get_nconns(int argc, const char *argv[],
                         struct dpctl_params *dpctl_p)
     {
         struct dpif *dpif;
    -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
    +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
         if (!error) {
             uint32_t nconns;
             error = ct_dpif_get_nconns(dpif, &nconns);
    -- 
    2.7.4
    
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Cdball%40vmware.com%7C842c99b58e864589120208d5f8113452%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636687675158408873&amp;sdata=SwCWGPm9Eb3TI%2Fj3I9kNkYzQ5Rwy%2FbxXO3P1LZdX0As%3D&amp;reserved=0
Darrell Ball Aug. 2, 2018, 5:56 a.m. | #2
On Wed, Aug 1, 2018 at 9:53 PM, Darrell Ball <dball@vmware.com> wrote:

> Thanks for the patch Yi-hung
>
> This patch does not seem to fit with this series somehow; it seems more
> related
> to flushing conntrack by zone and tuple ?
>

My apologies; after I reached the details of patch 10, I see why you wanted
to add
patch 9 as part of the series.



>
> I had a generic change in my queue. I think it is more straightforward,
> since it
> keeps opt_dpif_open() simple and improves the error handling and also
> simplifies
> dpctl_flush_conntrack() and any potential similar functions.
>
> https://patchwork.ozlabs.org/patch/952580/
>
>
>
>
> On 8/1/18, 5:45 PM, "ovs-dev-bounces@openvswitch.org on behalf of Yi-Hung
> Wei" <ovs-dev-bounces@openvswitch.org on behalf of yihung.wei@gmail.com>
> wrote:
>
>     Make opt_dpif_open() to support mulitple optional arguments.  It will
>     be useful for the following patches.
>
>     Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
>     ---
>      lib/dpctl.c | 85 ++++++++++++++++++++++++++++++
> ++-----------------------------
>      1 file changed, 44 insertions(+), 41 deletions(-)
>
>     diff --git a/lib/dpctl.c b/lib/dpctl.c
>     index 4f1e443f2662..35733774b331 100644
>     --- a/lib/dpctl.c
>     +++ b/lib/dpctl.c
>     @@ -191,14 +191,40 @@ parsed_dpif_open(const char *arg_, bool create,
> struct dpif **dpifp)
>       *
>       * 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 current setup, assuming only one exists.
>     + * For commands with multiple optional arguments, we try to use the
> first
>     + * argument as the dpif name. If it is failed, then we fallback to
>     + * retrieve it form the current setup.
>     + * On success stores the opened dpif in '*dpifp', and the next
> arugment
>     + * to be parsed in '*indexp'.  */
>      static int
>      opt_dpif_open(int argc, const char *argv[], struct dpctl_params
> *dpctl_p,
>     -              uint8_t max_args, struct dpif **dpifp)
>     +              uint8_t max_args, struct dpif **dpifp, bool multi_opt,
>     +              int *indexp)
>      {
>     +    char *dpname;
>          int error = 0;
>     -    char *dpname = argc >= max_args ? xstrdup(argv[1]) :
> get_one_dp(dpctl_p);
>     +
>     +    if (indexp) {
>     +        *indexp = 1;
>     +    }
>     +
>     +    if (multi_opt && argc > 1) {
>     +        error = parsed_dpif_open(argv[1], false, dpifp);
>     +        if (!error) {
>     +            if (indexp) {
>     +                *indexp = 2;
>     +            }
>     +            return 0;
>     +        } else if (argc == max_args) {
>     +            dpctl_error(dpctl_p, error, "invalid datapath");
>     +            return error;
>     +        }
>     +        dpname = get_one_dp(dpctl_p);
>     +    } else {
>     +        dpname = argc >= max_args ? xstrdup(argv[1]) :
> get_one_dp(dpctl_p);
>     +    }
>     +
>          if (!dpname) {
>              error = EINVAL;
>              dpctl_error(dpctl_p, error, "datapath not found");
>     @@ -863,7 +889,7 @@ dpctl_dump_flows(int argc, const char *argv[],
> struct dpctl_params *dpctl_p)
>              }
>          }
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
>          if (error) {
>              goto out_free;
>          }
>     @@ -990,7 +1016,7 @@ dpctl_put_flow(int argc, const char *argv[], enum
> dpif_flow_put_flags flags,
>          struct simap port_names;
>          int n, error;
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1092,7 +1118,7 @@ dpctl_get_flow(int argc, const char *argv[],
> struct dpctl_params *dpctl_p)
>          struct ds ds;
>          int n, error;
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1141,7 +1167,7 @@ dpctl_del_flow(int argc, const char *argv[],
> struct dpctl_params *dpctl_p)
>          struct simap port_names;
>          int n, error;
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1210,7 +1236,7 @@ dpctl_del_flows(int argc, const char *argv[],
> struct dpctl_params *dpctl_p)
>      {
>          struct dpif *dpif;
>
>     -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false,
> NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1271,7 +1297,7 @@ dpctl_dump_conntrack(int argc, const char
> *argv[],
>              argc--;
>          }
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1313,34 +1339,11 @@ dpctl_flush_conntrack(int argc, const char
> *argv[],
>          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;
>     -        }
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, true, &i);
>     +    if (error) {
>     +        return error;
>          }
>
>          /* Parse zone */
>     @@ -1412,7 +1415,7 @@ dpctl_ct_stats_show(int argc, const char *argv[],
>              }
>          }
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1537,7 +1540,7 @@ dpctl_ct_bkts(int argc, const char *argv[],
>              }
>          }
>
>     -    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
>          if (error) {
>              return error;
>          }
>     @@ -1617,7 +1620,7 @@ dpctl_ct_set_maxconns(int argc, const char
> *argv[],
>                            struct dpctl_params *dpctl_p)
>      {
>          struct dpif *dpif;
>     -    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
>     +    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false,
> NULL);
>          if (!error) {
>              uint32_t maxconns;
>              if (ovs_scan(argv[argc - 1], "%"SCNu32, &maxconns)) {
>     @@ -1643,7 +1646,7 @@ dpctl_ct_get_maxconns(int argc, const char
> *argv[],
>                          struct dpctl_params *dpctl_p)
>      {
>          struct dpif *dpif;
>     -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false,
> NULL);
>          if (!error) {
>              uint32_t maxconns;
>              error = ct_dpif_get_maxconns(dpif, &maxconns);
>     @@ -1664,7 +1667,7 @@ dpctl_ct_get_nconns(int argc, const char *argv[],
>                          struct dpctl_params *dpctl_p)
>      {
>          struct dpif *dpif;
>     -    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
>     +    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false,
> NULL);
>          if (!error) {
>              uint32_t nconns;
>              error = ct_dpif_get_nconns(dpif, &nconns);
>     --
>     2.7.4
>
>     _______________________________________________
>     dev mailing list
>     dev@openvswitch.org
>     https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.
> openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=
> 02%7C01%7Cdball%40vmware.com%7C842c99b58e864589120208d5f8113452%
> 7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636687675158408873&amp;
> sdata=SwCWGPm9Eb3TI%2Fj3I9kNkYzQ5Rwy%2FbxXO3P1LZdX0As%3D&amp;reserved=0
>
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

Patch

diff --git a/lib/dpctl.c b/lib/dpctl.c
index 4f1e443f2662..35733774b331 100644
--- a/lib/dpctl.c
+++ b/lib/dpctl.c
@@ -191,14 +191,40 @@  parsed_dpif_open(const char *arg_, bool create, struct dpif **dpifp)
  *
  * 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 current setup, assuming only one exists.
+ * For commands with multiple optional arguments, we try to use the first
+ * argument as the dpif name. If it is failed, then we fallback to
+ * retrieve it form the current setup.
+ * On success stores the opened dpif in '*dpifp', and the next arugment
+ * to be parsed in '*indexp'.  */
 static int
 opt_dpif_open(int argc, const char *argv[], struct dpctl_params *dpctl_p,
-              uint8_t max_args, struct dpif **dpifp)
+              uint8_t max_args, struct dpif **dpifp, bool multi_opt,
+              int *indexp)
 {
+    char *dpname;
     int error = 0;
-    char *dpname = argc >= max_args ? xstrdup(argv[1]) : get_one_dp(dpctl_p);
+
+    if (indexp) {
+        *indexp = 1;
+    }
+
+    if (multi_opt && argc > 1) {
+        error = parsed_dpif_open(argv[1], false, dpifp);
+        if (!error) {
+            if (indexp) {
+                *indexp = 2;
+            }
+            return 0;
+        } else if (argc == max_args) {
+            dpctl_error(dpctl_p, error, "invalid datapath");
+            return error;
+        }
+        dpname = get_one_dp(dpctl_p);
+    } else {
+        dpname = argc >= max_args ? xstrdup(argv[1]) : get_one_dp(dpctl_p);
+    }
+
     if (!dpname) {
         error = EINVAL;
         dpctl_error(dpctl_p, error, "datapath not found");
@@ -863,7 +889,7 @@  dpctl_dump_flows(int argc, const char *argv[], struct dpctl_params *dpctl_p)
         }
     }
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (error) {
         goto out_free;
     }
@@ -990,7 +1016,7 @@  dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags,
     struct simap port_names;
     int n, error;
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1092,7 +1118,7 @@  dpctl_get_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
     struct ds ds;
     int n, error;
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1141,7 +1167,7 @@  dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
     struct simap port_names;
     int n, error;
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1210,7 +1236,7 @@  dpctl_del_flows(int argc, const char *argv[], struct dpctl_params *dpctl_p)
 {
     struct dpif *dpif;
 
-    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1271,7 +1297,7 @@  dpctl_dump_conntrack(int argc, const char *argv[],
         argc--;
     }
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1313,34 +1339,11 @@  dpctl_flush_conntrack(int argc, const char *argv[],
     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;
-        }
+    error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif, true, &i);
+    if (error) {
+        return error;
     }
 
     /* Parse zone */
@@ -1412,7 +1415,7 @@  dpctl_ct_stats_show(int argc, const char *argv[],
         }
     }
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1537,7 +1540,7 @@  dpctl_ct_bkts(int argc, const char *argv[],
         }
     }
 
-    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (error) {
         return error;
     }
@@ -1617,7 +1620,7 @@  dpctl_ct_set_maxconns(int argc, const char *argv[],
                       struct dpctl_params *dpctl_p)
 {
     struct dpif *dpif;
-    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif);
+    int error = opt_dpif_open(argc, argv, dpctl_p, 3, &dpif, false, NULL);
     if (!error) {
         uint32_t maxconns;
         if (ovs_scan(argv[argc - 1], "%"SCNu32, &maxconns)) {
@@ -1643,7 +1646,7 @@  dpctl_ct_get_maxconns(int argc, const char *argv[],
                     struct dpctl_params *dpctl_p)
 {
     struct dpif *dpif;
-    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (!error) {
         uint32_t maxconns;
         error = ct_dpif_get_maxconns(dpif, &maxconns);
@@ -1664,7 +1667,7 @@  dpctl_ct_get_nconns(int argc, const char *argv[],
                     struct dpctl_params *dpctl_p)
 {
     struct dpif *dpif;
-    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+    int error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif, false, NULL);
     if (!error) {
         uint32_t nconns;
         error = ct_dpif_get_nconns(dpif, &nconns);