ip: Reference count the enabling the punt feature 83/35783/3
authorNeale Ranns <neale@graphiant.com>
Fri, 25 Mar 2022 08:51:58 +0000 (08:51 +0000)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 30 Mar 2022 18:31:21 +0000 (18:31 +0000)
Type: fix

otherwise punt features are applied multiple times to the same packet if enabled multiple times

Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: If0cbd9065275f68a10fd6d35e4f7a7c7508245e0

src/vnet/ip/ip4_punt_drop.c
src/vnet/ip/ip6_punt_drop.c

index 89803af..f2985a2 100644 (file)
@@ -312,6 +312,8 @@ VLIB_CLI_COMMAND (ip4_punt_policer_command, static) =
 
 #ifndef CLIB_MARCH_VARIANT
 
+static u32 ip4_punt_redirect_enable_counts;
+
 void
 ip4_punt_redirect_add_paths (u32 rx_sw_if_index,
                             const fib_route_path_t *rpaths)
@@ -320,13 +322,16 @@ ip4_punt_redirect_add_paths (u32 rx_sw_if_index,
                        rx_sw_if_index,
                        FIB_FORW_CHAIN_TYPE_UNICAST_IP4, rpaths);
 
-  vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 1, 0, 0);
+  if (1 == ++ip4_punt_redirect_enable_counts)
+    vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 1, 0, 0);
 }
 
 void
 ip4_punt_redirect_del (u32 rx_sw_if_index)
 {
-  vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 0, 0, 0);
+  ASSERT (ip4_punt_redirect_enable_counts);
+  if (0 == --ip4_punt_redirect_enable_counts)
+    vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 0, 0, 0);
 
   ip_punt_redirect_del (FIB_PROTOCOL_IP4, rx_sw_if_index);
 }
index ab5203d..32a2ab7 100644 (file)
@@ -301,6 +301,8 @@ VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
 
 #ifndef CLIB_MARCH_VARIANT
 
+static u32 ip6_punt_redirect_enable_counts;
+
 void
 ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
                             const fib_route_path_t *rpaths)
@@ -309,13 +311,16 @@ ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
                        rx_sw_if_index,
                        FIB_FORW_CHAIN_TYPE_UNICAST_IP6, rpaths);
 
-  vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
+  if (1 == ++ip6_punt_redirect_enable_counts)
+    vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
 }
 
 void
 ip6_punt_redirect_del (u32 rx_sw_if_index)
 {
-  vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
+  ASSERT (ip6_punt_redirect_enable_counts);
+  if (0 == --ip6_punt_redirect_enable_counts)
+    vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
 
   ip_punt_redirect_del (FIB_PROTOCOL_IP6, rx_sw_if_index);
 }