classify: fix "show classify filter" debug CLI
[vpp.git] / src / vnet / classify / vnet_classify.c
index 3d338d1..bf03024 100755 (executable)
@@ -147,13 +147,9 @@ vnet_classify_new_table (vnet_classify_main_t * cm,
   t->skip_n_vectors = skip_n_vectors;
   t->entries_per_page = 2;
 
-#if USE_DLMALLOC == 0
-  t->mheap = mheap_alloc (0 /* use VM */ , memory_size);
-#else
   t->mheap = create_mspace (memory_size, 1 /* locked */ );
   /* classifier requires the memory to be contiguous, so can not expand. */
   mspace_disable_expand (t->mheap);
-#endif
 
   vec_validate_aligned (t->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
   oldheap = clib_mem_set_heap (t->mheap);
@@ -180,12 +176,7 @@ vnet_classify_delete_table_index (vnet_classify_main_t * cm,
 
   vec_free (t->mask);
   vec_free (t->buckets);
-#if USE_DLMALLOC == 0
-  mheap_free (t->mheap);
-#else
   destroy_mspace (t->mheap);
-#endif
-
   pool_put (cm->tables, t);
 }
 
@@ -775,6 +766,9 @@ vnet_classify_add_del_table (vnet_classify_main_t * cm,
          if (nbuckets == 0)
            return VNET_API_ERROR_INVALID_VALUE;
 
+         if (match < 1 || match > 5)
+           return VNET_API_ERROR_INVALID_VALUE;
+
          t = vnet_classify_new_table (cm, mask, nbuckets, memory_size,
                                       skip, match);
          t->next_table_index = next_table_index;
@@ -1694,6 +1688,7 @@ classify_filter_command_fn (vlib_main_t * vm,
   int current_data_offset = 0;
   u32 sw_if_index = ~0;
   int pkt_trace = 0;
+  int pcap = 0;
   int i;
   vnet_classify_table_t *t;
   u8 *mask = 0;
@@ -1706,13 +1701,16 @@ classify_filter_command_fn (vlib_main_t * vm,
     {
       if (unformat (input, "del"))
        is_add = 0;
-      else if (unformat (input, "pcap %=", &sw_if_index, 0))
-       ;
+      else if (unformat (input, "pcap %=", &pcap, 1))
+       sw_if_index = 0;
       else if (unformat (input, "trace"))
        pkt_trace = 1;
       else if (unformat (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 (input, "mask %U", unformat_classify_mask,
@@ -1725,9 +1723,6 @@ classify_filter_command_fn (vlib_main_t * vm,
        break;
     }
 
-  if (sw_if_index == 0)
-    return clib_error_return (0, "Local interface not supported...");
-
   if (is_add && mask == 0 && table_index == ~0)
     return clib_error_return (0, "Mask required");
 
@@ -1737,9 +1732,13 @@ classify_filter_command_fn (vlib_main_t * vm,
   if (is_add && match == ~0 && table_index == ~0)
     return clib_error_return (0, "match count required");
 
-  if (sw_if_index == ~0 && pkt_trace == 0)
+  if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
     return clib_error_return (0, "Must specify trace, pcap or interface...");
 
+  if (pkt_trace && pcap)
+    return 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");
 
@@ -2066,7 +2065,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++)
@@ -2083,8 +2081,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);
@@ -2946,13 +2943,11 @@ vnet_classify_init (vlib_main_t * vm)
   vnet_classify_register_unformat_acl_next_index_fn (unformat_acl_next_node);
 
   /* Filter set 0 is grounded... */
-  pool_get (cm->filter_sets, set);
+  pool_get_zero (cm->filter_sets, set);
   set->refcnt = 0x7FFFFFFF;
-  vec_validate (set->table_indices, 0);
-  set->table_indices[0] = ~0;
   /* Initialize the pcap filter set */
   vec_validate (cm->filter_set_by_sw_if_index, 0);
-  cm->filter_set_by_sw_if_index[0] = ~0;
+  cm->filter_set_by_sw_if_index[0] = 0;
   /* Initialize the packet tracer filter set */
   vlib_global_main.trace_filter.trace_filter_set_index = ~0;