2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

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>
This commit is contained in:
Yi-Hung Wei
2017-12-07 10:40:04 -08:00
committed by Justin Pettit
parent 817a76577f
commit c43a133198
9 changed files with 273 additions and 23 deletions

View File

@@ -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;
if (argc > 1 && ovs_scan(argv[argc - 1], "zone=%"SCNu16, &zone)) {
/* 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;
}
}
/* 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;
}
error = parsed_dpif_open(name, false, &dpif);
free(name);
if (error) {
dpctl_error(dpctl_p, error, "opening datapath");
return error;
/* 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 = ct_dpif_flush(dpif, pzone, NULL);
/* 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, 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 },