diff options
author | Yi-Hung Wei <yihung.wei@gmail.com> | 2017-12-07 10:40:04 -0800 |
---|---|---|
committer | Justin Pettit <jpettit@ovn.org> | 2017-12-07 13:50:29 -0800 |
commit | c43a133198667c3e3dbf356968d6c48a547f34ee (patch) | |
tree | 475c78ab432699d605778aa08c37722b935d7b57 /lib/dpctl.c | |
parent | 817a76577fec3f03310d7d3a5a10df01340ee8ad (diff) | |
download | openvswitch-c43a133198667c3e3dbf356968d6c48a547f34ee.tar.gz |
dpctl: Support flush conntrack by conntrack 5-tuple
With this patch, "flush-conntrack" in ovs-dpctl and ovs-appctl accept
a conntrack 5-tuple to delete the conntrack entry specified by the 5-tuple.
For example, user can use the following command to flush a conntrack entry
in zone 5.
$ ovs-dpctl flush-conntrack zone=5 \
'ct_nw_src=10.1.1.2,ct_nw_dst=10.1.1.1,ct_nw_proto=17,ct_tp_src=2,ct_tp_dst=1'
$ ovs-appctl dpctl/flush-conntrack zone=5 \
'ct_nw_src=10.1.1.2,ct_nw_dst=10.1.1.1,ct_nw_proto=17,ct_tp_src=2,ct_tp_dst=1'
VMWare-BZ: #1983178
Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Signed-off-by: Justin Pettit <jpettit@ovn.org>
Diffstat (limited to 'lib/dpctl.c')
-rw-r--r-- | lib/dpctl.c | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/lib/dpctl.c b/lib/dpctl.c index 3abcdf548..a28ded98f 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -1331,30 +1331,73 @@ dpctl_flush_conntrack(int argc, const char *argv[], struct dpctl_params *dpctl_p) { struct dpif *dpif; + struct ct_dpif_tuple tuple, *ptuple = NULL; + struct ds ds = DS_EMPTY_INITIALIZER; uint16_t zone, *pzone = NULL; char *name; - int error; + 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; + } + } - if (argc > 1 && ovs_scan(argv[argc - 1], "zone=%"SCNu16, &zone)) { + /* Parse zone */ + if (argc > i && ovs_scan(argv[i], "zone=%"SCNu16, &zone)) { pzone = &zone; - argc--; + i++; } - /* The datapath name is not a mandatory parameter for this command. - * If it is not specified - so argc < 2 - we retrieve it from the - * current setup, assuming only one exists. */ - name = (argc == 2) ? xstrdup(argv[1]) : get_one_dp(dpctl_p); - if (!name) { - return EINVAL; + /* Report error if there are more than one unparsed argument. */ + if (argc - i > 1) { + ds_put_cstr(&ds, "invalid zone"); + error = EINVAL; + goto error; } - error = parsed_dpif_open(name, false, &dpif); - free(name); - if (error) { - dpctl_error(dpctl_p, error, "opening datapath"); - return 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 = ct_dpif_flush(dpif, pzone, NULL); + error = ct_dpif_flush(dpif, pzone, ptuple); + if (!error) { + dpif_close(dpif); + return 0; + } else { + ds_put_cstr(&ds, "failed to flush conntrack"); + } +error: + dpctl_error(dpctl_p, error, "%s", ds_cstr(&ds)); + ds_destroy(&ds); dpif_close(dpif); return error; } @@ -1902,7 +1945,8 @@ static const struct dpctl_command all_commands[] = { { "del-flow", "[dp] flow", 1, 2, dpctl_del_flow, DP_RW }, { "del-flows", "[dp]", 0, 1, dpctl_del_flows, DP_RW }, { "dump-conntrack", "[dp] [zone=N]", 0, 2, dpctl_dump_conntrack, DP_RO }, - { "flush-conntrack", "[dp] [zone=N]", 0, 2, dpctl_flush_conntrack, DP_RW }, + { "flush-conntrack", "[dp] [zone=N] [ct-tuple]", 0, 3, + dpctl_flush_conntrack, DP_RW }, { "ct-stats-show", "[dp] [zone=N] [verbose]", 0, 3, dpctl_ct_stats_show, DP_RO }, { "ct-bkts", "[dp] [gt=N]", 0, 2, dpctl_ct_bkts, DP_RO }, |