aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Loeliger <jdl@netgate.com>2020-11-03 15:49:10 -0500
committerDave Barach <openvpp@barachs.net>2020-11-10 10:58:54 +0000
commit5f7f47ec7ad642c3938376420ef9530176052cd8 (patch)
tree50db45b900d2f315d7edcfe0394e2d350f378f0c
parent212ec2af92b148cd3747e6ab424c0080d4a62968 (diff)
classify: fix classify filter trace del cli processing
When a 'del' is used to delete a classify table, only the mask is needed to locate the table. Any match vector is unneeded. The tests failed to notice this, but if the test is run by hand in vppctl, it issues a parse error. Fix the test so that it doesn't supply irrelevant data. Fix the CLI processing to read always complete newline terminated line of input instead. This allows unneeded CLI parameters to be ignored. It also necessitated fixing a trace test which had then erroneously split a single CLI command over multiple lines. While in the area, fix a latent bug on table matching where a test for compatible mask vector sizes were not matching impedance properly (byte vs ux32x4). Type: fix Signed-off-by: Jon Loeliger <jdl@netgate.com> Change-Id: I1177ab1dd417f3d11f30eecbaa2b0fb1015c3ab5
-rw-r--r--src/vnet/classify/vnet_classify.c84
-rw-r--r--test/test_pcap.py3
-rw-r--r--test/test_trace_filter.py9
3 files changed, 54 insertions, 42 deletions
diff --git a/src/vnet/classify/vnet_classify.c b/src/vnet/classify/vnet_classify.c
index 0b285acbb96..1e7515e1e12 100644
--- a/src/vnet/classify/vnet_classify.c
+++ b/src/vnet/classify/vnet_classify.c
@@ -1699,27 +1699,34 @@ classify_filter_command_fn (vlib_main_t * vm,
int rv = 0;
vnet_classify_filter_set_t *set = 0;
u32 set_index = ~0;
+ clib_error_t *err = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ unformat_input_t _line_input, *line_input = &_line_input;
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "del"))
+ if (unformat (line_input, "del"))
is_add = 0;
- else if (unformat (input, "pcap %=", &pcap, 1))
+ else if (unformat (line_input, "pcap %=", &pcap, 1))
sw_if_index = 0;
- else if (unformat (input, "trace"))
+ else if (unformat (line_input, "trace"))
pkt_trace = 1;
- else if (unformat (input, "%U",
+ else if (unformat (line_input, "%U",
unformat_vnet_sw_interface, vnm, &sw_if_index))
{
if (sw_if_index == 0)
return clib_error_return (0, "Local interface not supported...");
}
- else if (unformat (input, "buckets %d", &nbuckets))
+ else if (unformat (line_input, "buckets %d", &nbuckets))
;
- else if (unformat (input, "mask %U", unformat_classify_mask,
+ else if (unformat (line_input, "mask %U", unformat_classify_mask,
&mask, &skip, &match))
;
- else if (unformat (input, "memory-size %U", unformat_memory_size,
+ else if (unformat (line_input, "memory-size %U", unformat_memory_size,
&memory_size))
;
else
@@ -1727,27 +1734,32 @@ classify_filter_command_fn (vlib_main_t * vm,
}
if (is_add && mask == 0 && table_index == ~0)
- return clib_error_return (0, "Mask required");
+ err = clib_error_return (0, "Mask required");
- if (is_add && skip == ~0 && table_index == ~0)
- return clib_error_return (0, "skip count required");
+ else if (is_add && skip == ~0 && table_index == ~0)
+ err = clib_error_return (0, "skip count required");
- if (is_add && match == ~0 && table_index == ~0)
- return clib_error_return (0, "match count required");
+ else if (is_add && match == ~0 && table_index == ~0)
+ err = clib_error_return (0, "match count required");
- if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
- return clib_error_return (0, "Must specify trace, pcap or interface...");
+ else if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
+ err = clib_error_return (0, "Must specify trace, pcap or interface...");
- if (pkt_trace && pcap)
- return clib_error_return
+ else if (pkt_trace && pcap)
+ err = clib_error_return
(0, "Packet trace and pcap are mutually exclusive...");
- if (pkt_trace && sw_if_index != ~0)
- return clib_error_return (0, "Packet trace filter is per-system");
+ else if (pkt_trace && sw_if_index != ~0)
+ err = clib_error_return (0, "Packet trace filter is per-system");
- if (!is_add)
+ if (err)
{
+ unformat_free (line_input);
+ return err;
+ }
+ if (!is_add)
+ {
if (pkt_trace)
set_index = vlib_global_main.trace_filter.trace_filter_set_index;
else if (sw_if_index < vec_len (cm->filter_set_by_sw_if_index))
@@ -1756,14 +1768,16 @@ classify_filter_command_fn (vlib_main_t * vm,
if (set_index == ~0)
{
if (pkt_trace)
- return clib_error_return (0,
- "No pkt trace classify filter set...");
- if (sw_if_index == 0)
- return clib_error_return (0, "No pcap classify filter set...");
+ err =
+ clib_error_return (0, "No pkt trace classify filter set...");
+ else if (sw_if_index == 0)
+ err = clib_error_return (0, "No pcap classify filter set...");
else
- return clib_error_return (0, "No classify filter set for %U...",
- format_vnet_sw_if_index_name, vnm,
- sw_if_index);
+ err = clib_error_return (0, "No classify filter set for %U...",
+ format_vnet_sw_if_index_name, vnm,
+ sw_if_index);
+ unformat_free (line_input);
+ return err;
}
set = pool_elt_at_index (cm->filter_sets, set_index);
@@ -1820,7 +1834,7 @@ classify_filter_command_fn (vlib_main_t * vm,
if (t->match_n_vectors != match || t->skip_n_vectors != skip)
continue;
/* Masks aren't congruent, can't use this table */
- if (vec_len (t->mask) != vec_len (mask))
+ if (vec_len (t->mask) * sizeof (u32x4) != vec_len (mask))
continue;
/* Masks aren't bit-for-bit identical, can't use this table */
if (memcmp (t->mask, mask, vec_len (mask)))
@@ -1839,18 +1853,18 @@ classify_filter_command_fn (vlib_main_t * vm,
is_add, del_chain);
vec_free (mask);
- switch (rv)
+ if (rv != 0)
{
- case 0:
- break;
-
- default:
+ unformat_free (line_input);
return clib_error_return (0, "vnet_classify_add_del_table returned %d",
rv);
}
if (is_add == 0)
- return 0;
+ {
+ unformat_free (line_input);
+ return 0;
+ }
/* Remember the table */
vec_add1 (set->table_indices, table_index);
@@ -1889,7 +1903,7 @@ classify_filter_command_fn (vlib_main_t * vm,
found_table:
/* Now try to parse a session */
- if (unformat (input, "match %U", unformat_classify_match,
+ if (unformat (line_input, "match %U", unformat_classify_match,
cm, &match_vector, table_index) == 0)
return 0;
diff --git a/test/test_pcap.py b/test/test_pcap.py
index c3c7a662f04..353ad2178b5 100644
--- a/test/test_pcap.py
+++ b/test/test_pcap.py
@@ -67,8 +67,7 @@ class TestPcap(VppTestCase):
"show cla t",
"pa en",
"pcap trace rx tx off",
- "classify filter pcap del mask l3 ip4 src "
- "match l3 ip4 src 11.22.33.44"]
+ "classify filter pcap del mask l3 ip4 src"]
for cmd in cmds:
r = self.vapi.cli_return_response(cmd)
diff --git a/test/test_trace_filter.py b/test/test_trace_filter.py
index cd93c7463f7..a9f28787eda 100644
--- a/test/test_trace_filter.py
+++ b/test/test_trace_filter.py
@@ -71,7 +71,7 @@ class TestTracefilter(VppTestCase):
" incrementing 286\n"
" }\n"
"}\n",
- "classify filter trace mask l3 ip4 src\n"
+ "classify filter trace mask l3 ip4 src"
" match l3 ip4 src 192.168.1.15",
"trace add pg-input 100 filter",
"pa en classifyme"]
@@ -84,8 +84,7 @@ class TestTracefilter(VppTestCase):
# cleanup
self.cli("pa de classifyme")
- self.cli("classify filter trace del mask l3 ip4 src "
- "match l3 ip4 src 192.168.1.15")
+ self.cli("classify filter trace del mask l3 ip4 src")
# install a classify rule, inject traffic and check for hits
def assert_classify(self, mask, match, packets, n=None):
@@ -100,8 +99,8 @@ class TestTracefilter(VppTestCase):
self.assert_hits(n if n is not None else len(packets))
self.cli("clear trace")
self.cli(
- "classify filter trace del mask hex %s match hex %s" %
- (mask, match))
+ "classify filter trace del mask hex %s" %
+ (mask))
def test_encap(self):
""" Packet Tracer Filter Test with encap """