diff options
author | Darrell Ball <dlu998@gmail.com> | 2018-08-06 10:55:26 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2018-08-06 14:47:14 -0700 |
commit | 2f15f8f313366589ae1065b7689d9d2d3bf139e3 (patch) | |
tree | 5591bfe42ffa47c598a301996d9ab5179c810ba5 /lib | |
parent | 1ea9742269fcb959bd27d9aa188d9c6ce32b1ee6 (diff) | |
download | openvswitch-2f15f8f313366589ae1065b7689d9d2d3bf139e3.tar.gz |
dpctl: Simplify dpctl_flush_conntrack.
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 <dlu998@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpctl.c | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/lib/dpctl.c b/lib/dpctl.c index 4f1e443f2..c600eeb94 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); |