t->skip_n_vectors = skip_n_vectors;
t->entries_per_page = 2;
- t->mheap = create_mspace (memory_size, 1 /* locked */ );
- /* classifier requires the memory to be contiguous, so can not expand. */
- mspace_disable_expand (t->mheap);
+ t->mheap = clib_mem_create_heap (0, memory_size, 1 /* locked */ ,
+ "classify");
vec_validate_aligned (t->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
oldheap = clib_mem_set_heap (t->mheap);
vec_free (t->mask);
vec_free (t->buckets);
- destroy_mspace (t->mheap);
+ clib_mem_destroy_heap (t->mheap);
pool_put (cm->tables, t);
}
{
u8 **maskp = va_arg (*args, u8 **);
u8 *mask = 0;
- u8 found_something = 0;
+ u8 found_something;
ip6_header_t *ip;
u32 ip_version_traffic_class_and_flow_label;
break;
}
+ /* Account for "special" field names */
+ found_something = version + traffic_class + flow_label
+ + src_address + dst_address + protocol;
+
#define _(a) found_something += a;
foreach_ip6_proto_field;
#undef _
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
}
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))
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);
else
set = pool_elt_at_index (cm->filter_sets, set_index);
+ ASSERT (set);
+
for (i = 0; i < vec_len (set->table_indices); i++)
{
- t = pool_elt_at_index (cm->tables, i);
+ t = pool_elt_at_index (cm->tables, set->table_indices[i]);
/* classifier geometry mismatch, can't use this table */
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)))
continue;
/* Winner... */
- table_index = i;
+ table_index = set->table_indices[i];
goto found_table;
}
}
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);
cm->filter_set_by_sw_if_index[sw_if_index] = set - cm->filter_sets;
}
- /* Put top table index where device drivers can find them */
- if (sw_if_index > 0 && pkt_trace == 0)
- {
- vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
- ASSERT (vec_len (set->table_indices) > 0);
- hi->trace_classify_table_index = set->table_indices[0];
- }
-
/* Sort filter tables from most-specific mask to least-specific mask */
vec_sort_with_function (set->table_indices, filter_table_mask_compare);
- ASSERT (set);
-
/* Setup next_table_index fields */
for (i = 0; i < vec_len (set->table_indices); i++)
{
t->next_table_index = ~0;
}
+ /* Put top table index where device drivers can find them */
+ if (sw_if_index > 0 && pkt_trace == 0)
+ {
+ vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
+ ASSERT (vec_len (set->table_indices) > 0);
+ hi->trace_classify_table_index = set->table_indices[0];
+ }
+
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;
s = format (s, "%10u%10d%10d%10d", index, t->active_elements,
t->next_table_index, t->miss_next_index);
- s = format (s, "\n Heap: %U", format_mheap, t->mheap, 0 /*verbose */ );
+ s = format (s, "\n Heap: %U", format_clib_mem_heap, t->mheap,
+ 0 /*verbose */ );
s = format (s, "\n nbuckets %d, skip %d match %d flag %d offset %d",
t->nbuckets, t->skip_n_vectors, t->match_n_vectors,
}
/* *INDENT-OFF* */
- pool_foreach (t, cm->tables,
- ({
+ pool_foreach (t, cm->tables)
+ {
if (match_index == ~0 || (match_index == t - cm->tables))
vec_add1 (indices, t - cm->tables);
- }));
+ }
/* *INDENT-ON* */
if (vec_len (indices))