aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/classify/vnet_classify.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2021-02-19 16:39:13 +0100
committerBeno�t Ganne <bganne@cisco.com>2021-03-02 10:38:24 +0000
commit8c45e5109522cf9bbc98785283cd4c923f486fe6 (patch)
tree7ccab546f7c83daa72fd9cae5273935fc0f27c28 /src/vnet/classify/vnet_classify.c
parent2c0b6b462b86d4010cf551b545083c3509839cac (diff)
classify: fix multiple filters support
This fix the classify filter if we attach several different filters. This also fix some issues with l3 and l4 parsing. Type: fix Change-Id: I9dc6c55049a3bbc0110d1097b40d9da27633626b Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/classify/vnet_classify.c')
-rw-r--r--src/vnet/classify/vnet_classify.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/vnet/classify/vnet_classify.c b/src/vnet/classify/vnet_classify.c
index 72ab33e9210..d36d93b5f31 100644
--- a/src/vnet/classify/vnet_classify.c
+++ b/src/vnet/classify/vnet_classify.c
@@ -911,7 +911,7 @@ unformat_l4_mask (unformat_input_t * input, va_list * args)
else if (unformat (input, "dst_port"))
dst_port = 0xFFFF;
else
- return 0;
+ break;
}
if (!src_port && !dst_port)
@@ -980,6 +980,7 @@ unformat_ip4_mask (unformat_input_t * input, va_list * args)
break;
}
+ found_something = version + hdr_length;
#define _(a) found_something += a;
foreach_ip4_proto_field;
#undef _
@@ -1886,13 +1887,13 @@ classify_filter_command_fn (vlib_main_t * vm,
break;
}
- if (is_add && mask == 0 && table_index == ~0)
+ if (is_add && mask == 0)
err = clib_error_return (0, "Mask required");
- else if (is_add && skip == ~0 && table_index == ~0)
+ else if (is_add && skip == ~0)
err = clib_error_return (0, "skip count required");
- else if (is_add && match == ~0 && table_index == ~0)
+ else if (is_add && match == ~0)
err = clib_error_return (0, "match count required");
else if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
@@ -1936,20 +1937,30 @@ classify_filter_command_fn (vlib_main_t * vm,
table_index = classify_get_pcap_chain (cm, sw_if_index);
if (table_index != ~0)
- table_index = classify_lookup_chain (table_index, mask, skip, match);
+ {
+ /*
+ * look for a compatible table in the existing chain
+ * - if a compatible table is found, table_index is updated with it
+ * - if not, table_index is updated to ~0 (aka nil) and because of that
+ * we are going to create one (see below). We save the original head
+ * in next_table_index so we can chain it with the newly created
+ * table
+ */
+ next_table_index = table_index;
+ table_index = classify_lookup_chain (table_index, mask, skip, match);
+ }
/*
* When no table is found, make one.
*/
if (table_index == ~0)
{
+ u32 new_head_index;
+
/*
* Matching table wasn't found, so create a new one at the
* head of the next_table_index chain.
*/
- next_table_index = table_index;
- table_index = ~0;
-
rv = vnet_classify_add_del_table (cm, mask, nbuckets, memory_size,
skip, match, next_table_index,
miss_next_index, &table_index,
@@ -1968,16 +1979,16 @@ classify_filter_command_fn (vlib_main_t * vm,
/*
* Reorder tables such that masks are most-specify to least-specific.
*/
- table_index = classify_sort_table_chain (cm, table_index);
+ new_head_index = classify_sort_table_chain (cm, table_index);
/*
* Put first classifier table in chain in a place where
* other data structures expect to find and use it.
*/
if (pkt_trace)
- classify_set_trace_chain (cm, table_index);
+ classify_set_trace_chain (cm, new_head_index);
else
- classify_set_pcap_chain (cm, sw_if_index, table_index);
+ classify_set_pcap_chain (cm, sw_if_index, new_head_index);
}
vec_free (mask);