NAT44: delete user with zero sessions (VPP-1282)
[vpp.git] / src / plugins / nat / out2in.c
index ecfabc9..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;
     }
@@ -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 */
@@ -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;
         }
@@ -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;
                         }
 
@@ -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))
             {