X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fclassify%2Fvnet_classify.c;h=088890a5717caf5fde7551d1c10ecb5abaab69c2;hb=b2c31b685fd2cf28436ca32bc93e23eb24c74878;hp=165d4fc0316b1044c94d3c723b77e361a9c87810;hpb=2c8e0023f91882e53f06eb99c901b97fe013f981;p=vpp.git diff --git a/src/vnet/classify/vnet_classify.c b/src/vnet/classify/vnet_classify.c old mode 100755 new mode 100644 index 165d4fc0316..088890a5717 --- a/src/vnet/classify/vnet_classify.c +++ b/src/vnet/classify/vnet_classify.c @@ -147,9 +147,8 @@ vnet_classify_new_table (vnet_classify_main_t * cm, 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); @@ -176,7 +175,7 @@ vnet_classify_delete_table_index (vnet_classify_main_t * cm, vec_free (t->mask); vec_free (t->buckets); - destroy_mspace (t->mheap); + clib_mem_destroy_heap (t->mheap); pool_put (cm->tables, t); } @@ -1028,7 +1027,7 @@ unformat_ip6_mask (unformat_input_t * input, va_list * args) { 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; @@ -1061,6 +1060,10 @@ unformat_ip6_mask (unformat_input_t * input, va_list * args) 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 _ @@ -1696,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 @@ -1724,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)) @@ -1753,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); @@ -1808,21 +1825,23 @@ classify_filter_command_fn (vlib_main_t * vm, 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; } } @@ -1834,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); @@ -1859,19 +1878,9 @@ classify_filter_command_fn (vlib_main_t * vm, 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++) { @@ -1883,10 +1892,18 @@ classify_filter_command_fn (vlib_main_t * vm, 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; @@ -2065,7 +2082,6 @@ show_classify_filter_command_fn (vlib_main_t * vm, if (verbose) { - u8 *s = 0; u32 table_index; for (j = 0; j < vec_len (set->table_indices); j++) @@ -2082,8 +2098,7 @@ show_classify_filter_command_fn (vlib_main_t * vm, } else { - u8 *s = 0; - table_index = set->table_indices[0]; + table_index = set->table_indices ? set->table_indices[0] : ~0; if (table_index != ~0) s = format (s, " %u", table_index); @@ -2132,7 +2147,8 @@ format_vnet_classify_table (u8 * s, va_list * args) 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, @@ -2174,11 +2190,11 @@ show_classify_tables_command_fn (vlib_main_t * vm, } /* *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))