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