acl-plugin: fix acl plugin test failing sporadically (VPP-898)
[vpp.git] / src / plugins / acl / acl.c
index 51929ad..02fcb4f 100644 (file)
@@ -665,12 +665,15 @@ acl_interface_add_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
         /* the entry is already there */
         return -1;
       }
+      /* if there was no ACL applied before, enable the ACL processing */
+      if (vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index]) == 0) {
+        acl_interface_in_enable_disable (am, sw_if_index, 1);
+      }
       vec_add (am->input_acl_vec_by_sw_if_index[sw_if_index], &acl_list_index,
               1);
       vec_validate (am->input_sw_if_index_vec_by_acl, acl_list_index);
       vec_add (am->input_sw_if_index_vec_by_acl[acl_list_index], &sw_if_index,
               1);
-      acl_interface_in_enable_disable (am, sw_if_index, 1);
     }
   else
     {
@@ -683,12 +686,15 @@ acl_interface_add_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
         /* the entry is already there */
         return -1;
       }
+      /* if there was no ACL applied before, enable the ACL processing */
+      if (vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index]) == 0) {
+        acl_interface_out_enable_disable (am, sw_if_index, 1);
+      }
       vec_add (am->output_acl_vec_by_sw_if_index[sw_if_index],
               &acl_list_index, 1);
       vec_validate (am->output_sw_if_index_vec_by_acl, acl_list_index);
       vec_add (am->output_sw_if_index_vec_by_acl[acl_list_index], &sw_if_index,
               1);
-      acl_interface_out_enable_disable (am, sw_if_index, 1);
     }
   return 0;
 }
@@ -723,6 +729,7 @@ acl_interface_del_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
         }
       }
 
+      /* If there is no more ACLs applied on an interface, disable ACL processing */
       if (0 == vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]))
        {
          acl_interface_in_enable_disable (am, sw_if_index, 0);
@@ -751,6 +758,7 @@ acl_interface_del_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
         }
       }
 
+      /* If there is no more ACLs applied on an interface, disable ACL processing */
       if (0 == vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]))
        {
          acl_interface_out_enable_disable (am, sw_if_index, 0);
@@ -766,8 +774,10 @@ acl_interface_reset_inout_acls (u32 sw_if_index, u8 is_input)
   int i;
   if (is_input)
     {
-      acl_interface_in_enable_disable (am, sw_if_index, 0);
       vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
+      if (vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0) {
+        acl_interface_in_enable_disable (am, sw_if_index, 0);
+      }
 
       for(i = vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index])-1; i>=0; i--) {
         u32 acl_list_index = am->input_acl_vec_by_sw_if_index[sw_if_index][i];
@@ -784,8 +794,10 @@ acl_interface_reset_inout_acls (u32 sw_if_index, u8 is_input)
     }
   else
     {
-      acl_interface_out_enable_disable (am, sw_if_index, 0);
       vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
+      if (vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0) {
+        acl_interface_out_enable_disable (am, sw_if_index, 0);
+      }
 
       for(i = vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index])-1; i>=0; i--) {
         u32 acl_list_index = am->output_acl_vec_by_sw_if_index[sw_if_index][i];
@@ -1828,12 +1840,6 @@ acl_set_aclplugin_fn (vlib_main_t * vm,
       goto done;
     }
   if (unformat (input, "session")) {
-    if (unformat (input, "clear")) {
-      acl_main_t *am = &acl_main;
-      vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
-                               ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
-         goto done;
-    }
     if (unformat (input, "table")) {
       /* The commands here are for tuning/testing. No user-serviceable parts inside */
       if (unformat (input, "max-entries")) {
@@ -1968,6 +1974,7 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
 #define _(cnt, desc) out0 = format(out0, "             %20lu: %s\n", am->cnt, desc);
       foreach_fa_cleaner_counter;
 #undef _
+      vec_terminate_c_string(out0);
       vlib_cli_output(vm, "\n\n%s\n\n", out0);
       vlib_cli_output(vm, "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
               am->fa_min_deleted_sessions_per_interval, am->fa_max_deleted_sessions_per_interval,
@@ -2005,6 +2012,7 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
         }
 
       }
+      vec_terminate_c_string(out0);
       vlib_cli_output(vm, "\n%s\n", out0);
       vec_free(out0);
     }
@@ -2061,6 +2069,7 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
           out0 = format(out0, "\n");
         }
       }
+      vec_terminate_c_string(out0);
       vlib_cli_output(vm, "\n%s\n", out0);
       vec_free(out0);
     }
@@ -2076,6 +2085,8 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
       u32 show_bihash_verbose = 0;
 
       if (unformat (input, "acl")) {
+        show_acl_hash_info = 1;
+        /* mask-type is handy to see as well right there */
         show_mask_type = 1;
         unformat (input, "index %u", &acl_index);
       } else if (unformat (input, "applied")) {
@@ -2130,6 +2141,7 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
                                 pa->src_portrange_not_powerof2, pa->dst_portrange_not_powerof2);
           }
         }
+        vec_terminate_c_string(out0);
         vlib_cli_output(vm, "\n%s\n", out0);
         vec_free(out0);
       }
@@ -2176,6 +2188,7 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
           }
 
         }
+        vec_terminate_c_string(out0);
         vlib_cli_output(vm, "\n%s\n", out0);
         vec_free(out0);
       }
@@ -2187,6 +2200,17 @@ acl_show_aclplugin_fn (vlib_main_t * vm,
   return error;
 }
 
+static clib_error_t *
+acl_clear_aclplugin_fn (vlib_main_t * vm,
+                              unformat_input_t * input,
+                              vlib_cli_command_t * cmd)
+{
+  clib_error_t *error = 0;
+  acl_main_t *am = &acl_main;
+  vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
+                               ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
+  return error;
+}
 
  /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
@@ -2200,6 +2224,12 @@ VLIB_CLI_COMMAND (aclplugin_show_command, static) = {
     .short_help = "show acl-plugin {sessions|acl|interface|tables}",
     .function = acl_show_aclplugin_fn,
 };
+
+VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
+    .path = "clear acl-plugin sessions",
+    .short_help = "clear acl-plugin sessions",
+    .function = acl_clear_aclplugin_fn,
+};
 /* *INDENT-ON* */