NAT44: delete user with zero sessions (VPP-1282)
[vpp.git] / src / plugins / nat / out2in.c
index 1a1a1f1..774ae67 100755 (executable)
@@ -188,6 +188,7 @@ create_session_for_static_mapping (snat_main_t *sm,
   s = nat_session_alloc_or_recycle (sm, u, thread_index);
   if (!s)
     {
+      nat44_delete_user_with_no_session (sm, u, thread_index);
       nat_log_warn ("create NAT session failed");
       return 0;
     }
@@ -653,7 +654,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
   u32 pkts_processed = 0;
   snat_main_t * sm = &snat_main;
   f64 now = vlib_time_now (vm);
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index = vm->thread_index;
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -786,8 +787,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
                      && (udp0->dst_port ==
                          clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                    {
-                     vnet_feature_next
-                       (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0, b0);
+                     vnet_feature_next (&next0, b0);
                      goto trace0;
                    }
 
@@ -795,8 +795,8 @@ snat_out2in_node_fn (vlib_main_t * vm,
                     {
                       b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
                       next0 = SNAT_OUT2IN_NEXT_DROP;
-                      goto trace0;
                     }
+                  goto trace0;
                 }
 
               /* Create session initiated by host from external network */
@@ -938,8 +938,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
                      && (udp1->dst_port ==
                          clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                    {
-                     vnet_feature_next
-                       (vnet_buffer (b1)->sw_if_index[VLIB_RX], &next1, b1);
+                     vnet_feature_next (&next1, b1);
                      goto trace1;
                    }
 
@@ -947,8 +946,8 @@ snat_out2in_node_fn (vlib_main_t * vm,
                     {
                       b1->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
                       next1 = SNAT_OUT2IN_NEXT_DROP;
-                      goto trace1;
                     }
+                  goto trace1;
                 }
 
               /* Create session initiated by host from external network */
@@ -1126,8 +1125,7 @@ snat_out2in_node_fn (vlib_main_t * vm,
                      && (udp0->dst_port ==
                          clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                    {
-                     vnet_feature_next
-                       (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0, b0);
+                     vnet_feature_next (&next0, b0);
                      goto trace00;
                    }
 
@@ -1135,8 +1133,8 @@ snat_out2in_node_fn (vlib_main_t * vm,
                     {
                       b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
                       next0 = SNAT_OUT2IN_NEXT_DROP;
-                      goto trace00;
                     }
+                  goto trace00;
                 }
 
               /* Create session initiated by host from external network */
@@ -1256,7 +1254,7 @@ nat44_out2in_reass_node_fn (vlib_main_t * vm,
   u32 pkts_processed = 0;
   snat_main_t *sm = &snat_main;
   f64 now = vlib_time_now (vm);
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index = vm->thread_index;
   snat_main_per_thread_data_t *per_thread_data =
     &sm->per_thread_data[thread_index];
   u32 *fragments_to_drop = 0;
@@ -1352,9 +1350,7 @@ nat44_out2in_reass_node_fn (vlib_main_t * vm,
                           && (udp0->dst_port
                               == clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                        {
-                          vnet_feature_next
-                            (vnet_buffer (b0)->sw_if_index[VLIB_RX],
-                             &next0, b0);
+                          vnet_feature_next (&next0, b0);
                           goto trace0;
                         }
 
@@ -1604,6 +1600,7 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
   s = nat_session_alloc_or_recycle (sm, u, thread_index);
   if (!s)
     {
+      nat44_delete_user_with_no_session (sm, u, thread_index);
       nat_log_warn ("create NAT session failed");
       return 0;
     }
@@ -1785,6 +1782,7 @@ create_bypass_for_fwd(snat_main_t * sm, ip4_header_t * ip, u32 rx_fib_index,
       s = nat_session_alloc_or_recycle (sm, u, thread_index);
       if (!s)
         {
+          nat44_delete_user_with_no_session (sm, u, thread_index);
           nat_log_warn ("create NAT session failed");
           return;
         }
@@ -1985,6 +1983,7 @@ nat44_ed_out2in_unknown_proto (snat_main_t *sm,
       s = nat_session_alloc_or_recycle (sm, u, thread_index);
       if (!s)
         {
+          nat44_delete_user_with_no_session (sm, u, thread_index);
           nat_log_warn ("create NAT session failed");
           return 0;
         }
@@ -2038,7 +2037,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
   nat44_ed_out2in_next_t next_index;
   snat_main_t *sm = &snat_main;
   f64 now = vlib_time_now (vm);
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index = vm->thread_index;
   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
 
   stats_node_index = is_slow_path ? nat44_ed_out2in_slowpath_node.index :
@@ -2182,8 +2181,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                           && (udp0->dst_port ==
                           clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                         {
-                          vnet_feature_next
-                            (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0, b0);
+                          vnet_feature_next (&next0, b0);
                           goto trace00;
                         }
 
@@ -2386,8 +2384,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                           && (udp1->dst_port ==
                           clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                         {
-                          vnet_feature_next
-                            (vnet_buffer (b1)->sw_if_index[VLIB_RX], &next1, b1);
+                          vnet_feature_next (&next1, b1);
                           goto trace01;
                         }
 
@@ -2622,8 +2619,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                           && (udp0->dst_port ==
                           clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
                         {
-                          vnet_feature_next
-                            (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0, b0);
+                          vnet_feature_next (&next0, b0);
                           goto trace0;
                         }
 
@@ -2837,7 +2833,7 @@ snat_det_out2in_node_fn (vlib_main_t * vm,
   snat_out2in_next_t next_index;
   u32 pkts_processed = 0;
   snat_main_t * sm = &snat_main;
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index = vm->thread_index;
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -3473,7 +3469,7 @@ snat_out2in_worker_handoff_fn (vlib_main_t * vm,
   u32 n_left_to_next_worker = 0, *to_next_worker = 0;
   u32 next_worker_index = 0;
   u32 current_worker_index = ~0;
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index = vm->thread_index;
   vlib_frame_t *d = 0;
 
   ASSERT (vec_len (sm->workers));
@@ -3700,7 +3696,7 @@ snat_out2in_fast_node_fn (vlib_main_t * vm,
           sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
          rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index(sw_if_index0);
 
-         vnet_feature_next (sw_if_index0, &next0, b0);
+         vnet_feature_next (&next0, b0);
 
           if (PREDICT_FALSE(ip0->ttl == 1))
             {