NAT44: add support for session timeout (VPP-1272)
[vpp.git] / src / plugins / nat / out2in.c
index 80465b0..46a8a1e 100755 (executable)
@@ -140,6 +140,43 @@ typedef enum {
   SNAT_OUT2IN_N_NEXT,
 } snat_out2in_next_t;
 
+int
+nat44_o2i_is_idle_session_cb (clib_bihash_kv_8_8_t * kv, void * arg)
+{
+  snat_main_t *sm = &snat_main;
+  nat44_is_idle_session_ctx_t *ctx = arg;
+  snat_session_t *s;
+  u64 sess_timeout_time;
+  snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
+                                                       ctx->thread_index);
+  clib_bihash_kv_8_8_t s_kv;
+
+  s = pool_elt_at_index (tsm->sessions, kv->value);
+  sess_timeout_time = s->last_heard + (f64)nat44_session_get_timeout(sm, s);
+  if (ctx->now >= sess_timeout_time)
+    {
+      s_kv.key = s->in2out.as_u64;
+      if (clib_bihash_add_del_8_8 (&tsm->in2out, &s_kv, 0))
+        nat_log_warn ("out2in key del failed");
+
+      snat_ipfix_logging_nat44_ses_delete(s->in2out.addr.as_u32,
+                                          s->out2in.addr.as_u32,
+                                          s->in2out.protocol,
+                                          s->in2out.port,
+                                          s->out2in.port,
+                                          s->in2out.fib_index);
+
+      if (!snat_is_session_static (s))
+        snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
+                                            &s->out2in);
+
+      nat44_delete_session (sm, s, ctx->thread_index);
+      return 1;
+    }
+
+  return 0;
+}
+
 /**
  * @brief Create session for static mapping.
  *
@@ -160,13 +197,15 @@ create_session_for_static_mapping (snat_main_t *sm,
                                    snat_session_key_t in2out,
                                    snat_session_key_t out2in,
                                    vlib_node_runtime_t * node,
-                                   u32 thread_index)
+                                   u32 thread_index,
+                                   f64 now)
 {
   snat_user_t *u;
   snat_session_t *s;
   clib_bihash_kv_8_8_t kv0;
   ip4_header_t *ip0;
   udp_header_t *udp0;
+  nat44_is_idle_session_ctx_t ctx0;
 
   if (PREDICT_FALSE (maximum_sessions_exceeded(sm, thread_index)))
     {
@@ -188,6 +227,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;
     }
@@ -202,16 +242,20 @@ create_session_for_static_mapping (snat_main_t *sm,
   s->in2out.protocol = out2in.protocol;
 
   /* Add to translation hashes */
+  ctx0.now = now;
+  ctx0.thread_index = thread_index;
   kv0.key = s->in2out.as_u64;
   kv0.value = s - sm->per_thread_data[thread_index].sessions;
-  if (clib_bihash_add_del_8_8 (&sm->per_thread_data[thread_index].in2out, &kv0,
-                               1 /* is_add */))
+  if (clib_bihash_add_or_overwrite_stale_8_8 (
+       &sm->per_thread_data[thread_index].in2out, &kv0,
+       nat44_i2o_is_idle_session_cb, &ctx0))
       nat_log_notice ("in2out key add failed");
 
   kv0.key = s->out2in.as_u64;
 
-  if (clib_bihash_add_del_8_8 (&sm->per_thread_data[thread_index].out2in, &kv0,
-                               1 /* is_add */))
+  if (clib_bihash_add_or_overwrite_stale_8_8 (
+        &sm->per_thread_data[thread_index].out2in, &kv0,
+        nat44_o2i_is_idle_session_cb, &ctx0))
       nat_log_notice ("out2in key add failed");
 
   /* log NAT event */
@@ -221,7 +265,7 @@ create_session_for_static_mapping (snat_main_t *sm,
                                       s->in2out.port,
                                       s->out2in.port,
                                       s->in2out.fib_index);
-   return s;
+  return s;
 }
 
 static_always_inline
@@ -355,7 +399,8 @@ u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node,
 
       /* Create session initiated by host from external network */
       s0 = create_session_for_static_mapping(sm, b0, sm0, key0,
-                                             node, thread_index);
+                                             node, thread_index,
+                                             vlib_time_now (sm->vlib_main));
 
       if (!s0)
         {
@@ -626,7 +671,7 @@ nat_out2in_sm_unknown_proto (snat_main_t *sm,
   m_key.addr = ip->dst_address;
   m_key.port = 0;
   m_key.protocol = 0;
-  m_key.fib_index = rx_fib_index;
+  m_key.fib_index = 0;
   kv.key = m_key.as_u64;
   if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
     return 1;
@@ -653,7 +698,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 +831,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,13 +839,13 @@ 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 */
               s0 = create_session_for_static_mapping(sm, b0, sm0, key0, node,
-                                                     thread_index);
+                                                     thread_index, now);
               if (!s0)
                 {
                   next0 = SNAT_OUT2IN_NEXT_DROP;
@@ -938,8 +982,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,13 +990,13 @@ 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 */
               s1 = create_session_for_static_mapping(sm, b1, sm1, key1, node,
-                                                     thread_index);
+                                                     thread_index, now);
               if (!s1)
                 {
                   next1 = SNAT_OUT2IN_NEXT_DROP;
@@ -1126,8 +1169,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,13 +1177,13 @@ 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 */
               s0 = create_session_for_static_mapping(sm, b0, sm0, key0, node,
-                                                     thread_index);
+                                                     thread_index, now);
               if (!s0)
                 {
                   next0 = SNAT_OUT2IN_NEXT_DROP;
@@ -1256,7 +1298,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 +1394,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;
                         }
 
@@ -1368,7 +1408,7 @@ nat44_out2in_reass_node_fn (vlib_main_t * vm,
 
                   /* Create session initiated by host from external network */
                   s0 = create_session_for_static_mapping(sm, b0, sm0, key0, node,
-                                                         thread_index);
+                                                         thread_index, now);
                   if (!s0)
                     {
                       b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
@@ -1568,6 +1608,109 @@ format_nat44_ed_out2in_trace (u8 * s, va_list * args)
   return s;
 }
 
+static inline u32
+icmp_out2in_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
+                          ip4_header_t * ip0, icmp46_header_t * icmp0,
+                          u32 sw_if_index0, u32 rx_fib_index0,
+                          vlib_node_runtime_t * node, u32 next0, f64 now,
+                          u32 thread_index, snat_session_t ** p_s0)
+{
+  next0 = icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
+                      next0, thread_index, p_s0, 0);
+  snat_session_t * s0 = *p_s0;
+  if (PREDICT_TRUE(next0 != SNAT_OUT2IN_NEXT_DROP && s0))
+    {
+      /* Accounting */
+      nat44_session_update_counters (s0, now,
+                                     vlib_buffer_length_in_chain (sm->vlib_main, b0));
+    }
+  return next0;
+}
+
+int
+nat44_o2i_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void * arg)
+{
+  snat_main_t *sm = &snat_main;
+  nat44_is_idle_session_ctx_t *ctx = arg;
+  snat_session_t *s;
+  u64 sess_timeout_time;
+  nat_ed_ses_key_t ed_key;
+  clib_bihash_kv_16_8_t ed_kv;
+  int i;
+  snat_address_t *a;
+  snat_session_key_t key;
+  snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
+                                                       ctx->thread_index);
+
+  s = pool_elt_at_index (tsm->sessions, kv->value);
+  sess_timeout_time = s->last_heard + (f64)nat44_session_get_timeout(sm, s);
+  if (ctx->now >= sess_timeout_time)
+    {
+      ed_key.l_addr = s->in2out.addr;
+      ed_key.r_addr = s->ext_host_addr;
+      ed_key.fib_index = s->out2in.fib_index;
+      if (snat_is_unk_proto_session (s))
+        {
+          ed_key.proto = s->in2out.port;
+          ed_key.r_port = 0;
+          ed_key.l_port = 0;
+        }
+      else
+        {
+          ed_key.proto = snat_proto_to_ip_proto (s->in2out.protocol);
+          ed_key.l_port = s->in2out.port;
+          ed_key.r_port = s->ext_host_port;
+        }
+      if (is_twice_nat_session (s))
+        {
+          ed_key.r_addr = s->ext_host_nat_addr;
+          ed_key.r_port = s->ext_host_nat_port;
+        }
+      ed_kv.key[0] = ed_key.as_u64[0];
+      ed_kv.key[1] = ed_key.as_u64[1];
+      if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &ed_kv, 0))
+        nat_log_warn ("in2out_ed key del failed");
+
+      if (snat_is_unk_proto_session (s))
+        goto delete;
+
+      snat_ipfix_logging_nat44_ses_delete(s->in2out.addr.as_u32,
+                                          s->out2in.addr.as_u32,
+                                          s->in2out.protocol,
+                                          s->in2out.port,
+                                          s->out2in.port,
+                                          s->in2out.fib_index);
+
+      if (is_twice_nat_session (s))
+        {
+          for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
+            {
+              key.protocol = s->in2out.protocol;
+              key.port = s->ext_host_nat_port;
+              a = sm->twice_nat_addresses + i;
+              if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
+                {
+                  snat_free_outside_address_and_port (sm->twice_nat_addresses,
+                                                      ctx->thread_index, &key);
+                  break;
+                }
+            }
+        }
+
+      if (snat_is_session_static (s))
+        goto delete;
+
+      if (s->outside_address_index != ~0)
+        snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
+                                            &s->out2in);
+    delete:
+      nat44_delete_session (sm, s, ctx->thread_index);
+      return 1;
+    }
+
+  return 0;
+}
+
 static snat_session_t *
 create_session_for_static_mapping_ed (snat_main_t * sm,
                                       vlib_buffer_t *b,
@@ -1576,7 +1719,8 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
                                       vlib_node_runtime_t * node,
                                       u32 thread_index,
                                       twice_nat_type_t twice_nat,
-                                      u8 is_lb)
+                                      u8 is_lb,
+                                      f64 now)
 {
   snat_session_t *s;
   snat_user_t *u;
@@ -1586,6 +1730,7 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
   clib_bihash_kv_16_8_t kv;
   snat_session_key_t eh_key;
   u32 address_index;
+  nat44_is_idle_session_ctx_t ctx;
 
   if (PREDICT_FALSE (maximum_sessions_exceeded(sm, thread_index)))
     {
@@ -1601,9 +1746,10 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
       return 0;
     }
 
-  s = nat_session_alloc_or_recycle (sm, u, thread_index);
+  s = nat_ed_session_alloc (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;
     }
@@ -1627,7 +1773,11 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
   make_ed_kv (&kv, &e_key.addr, &s->ext_host_addr, ip->protocol,
               e_key.fib_index, e_key.port, s->ext_host_port);
   kv.value = s - tsm->sessions;
-  if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &kv, 1))
+  ctx.now = now;
+  ctx.thread_index = thread_index;
+  if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->out2in_ed, &kv,
+                                               nat44_o2i_ed_is_idle_session_cb,
+                                               &ctx))
     nat_log_notice ("out2in-ed key add failed");
 
   if (twice_nat == TWICE_NAT || (twice_nat == TWICE_NAT_SELF &&
@@ -1658,7 +1808,9 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
                   l_key.fib_index, l_key.port, s->ext_host_port);
     }
   kv.value = s - tsm->sessions;
-  if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &kv, 1))
+  if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, &kv,
+                                               nat44_i2o_ed_is_idle_session_cb,
+                                               &ctx))
     nat_log_notice ("in2out-ed key add failed");
 
   return s;
@@ -1715,13 +1867,13 @@ icmp_get_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
 
 static int
 next_src_nat (snat_main_t * sm, ip4_header_t * ip, u8 proto, u16 src_port,
-              u16 dst_port, u32 thread_index)
+              u16 dst_port, u32 thread_index, u32 rx_fib_index)
 {
   clib_bihash_kv_16_8_t kv, value;
   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
 
   make_ed_kv (&kv, &ip->src_address, &ip->dst_address, proto,
-              sm->inside_fib_index, src_port, dst_port);
+              rx_fib_index, src_port, dst_port);
   if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
     return 1;
 
@@ -1782,9 +1934,10 @@ create_bypass_for_fwd(snat_main_t * sm, ip4_header_t * ip, u32 rx_fib_index,
           return;
         }
 
-      s = nat_session_alloc_or_recycle (sm, u, thread_index);
+      s = nat_ed_session_alloc (sm, u, thread_index);
       if (!s)
         {
+          nat44_delete_user_with_no_session (sm, u, thread_index);
           nat_log_warn ("create NAT session failed");
           return;
         }
@@ -1812,8 +1965,6 @@ create_bypass_for_fwd(snat_main_t * sm, ip4_header_t * ip, u32 rx_fib_index,
         return;
     }
 
-  /* Per-user LRU list maintenance */
-  nat44_session_update_lru (sm, s, thread_index);
   /* Accounting */
   nat44_session_update_counters (s, now, 0);
 }
@@ -1872,7 +2023,8 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
           else
             {
               dont_translate = 1;
-              if (next_src_nat(sm, ip, key.proto, key.l_port, key.r_port, thread_index))
+              if (next_src_nat(sm, ip, key.proto, key.l_port, key.r_port,
+                               thread_index, rx_fib_index))
                 {
                   next = NAT44_ED_OUT2IN_NEXT_IN2OUT;
                   goto out;
@@ -1892,7 +2044,8 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
 
       /* Create session initiated by host from external network */
       s = create_session_for_static_mapping_ed(sm, b, l_key, e_key, node,
-                                               thread_index, 0, 0);
+                                               thread_index, 0, 0,
+                                               vlib_time_now (sm->vlib_main));
 
       if (!s)
         {
@@ -1962,7 +2115,7 @@ nat44_ed_out2in_unknown_proto (snat_main_t *sm,
           return 0;
         }
 
-      make_sm_kv (&kv, &ip->dst_address, 0, rx_fib_index, 0);
+      make_sm_kv (&kv, &ip->dst_address, 0, 0, 0);
       if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
         {
           b->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
@@ -1973,7 +2126,7 @@ nat44_ed_out2in_unknown_proto (snat_main_t *sm,
 
       new_addr = ip->dst_address.as_u32 = m->local_addr.as_u32;
 
-      u = nat_user_get_or_create (sm, &ip->src_address, m->fib_index,
+      u = nat_user_get_or_create (sm, &m->local_addr, m->fib_index,
                                   thread_index);
       if (!u)
         {
@@ -1982,9 +2135,10 @@ nat44_ed_out2in_unknown_proto (snat_main_t *sm,
         }
 
       /* Create a new session */
-      s = nat_session_alloc_or_recycle (sm, u, thread_index);
+      s = nat_ed_session_alloc (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;
         }
@@ -2023,8 +2177,6 @@ nat44_ed_out2in_unknown_proto (snat_main_t *sm,
   /* Accounting */
   nat44_session_update_counters (s, now,
                                  vlib_buffer_length_in_chain (vm, b));
-  /* Per-user LRU list maintenance */
-  nat44_session_update_lru (sm, s, thread_index);
 
   return s;
 }
@@ -2038,7 +2190,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 :
@@ -2136,7 +2288,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
               if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
                 {
-                  next0 = icmp_out2in_slow_path
+                  next0 = icmp_out2in_ed_slow_path
                     (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
                      next0, now, thread_index, &s0);
                   goto trace00;
@@ -2182,8 +2334,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;
                         }
 
@@ -2196,7 +2347,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                         {
                           if (next_src_nat(sm, ip0, ip0->protocol,
                                            udp0->src_port, udp0->dst_port,
-                                           thread_index))
+                                           thread_index, rx_fib_index0))
                             {
                               next0 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
                               goto trace00;
@@ -2211,7 +2362,8 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                   s0 = create_session_for_static_mapping_ed(sm, b0, l_key0,
                                                             e_key0, node,
                                                             thread_index,
-                                                            twice_nat0, is_lb0);
+                                                            twice_nat0, is_lb0,
+                                                            now);
 
                   if (!s0)
                     {
@@ -2282,8 +2434,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
           /* Accounting */
           nat44_session_update_counters (s0, now,
                                          vlib_buffer_length_in_chain (vm, b0));
-          /* Per-user LRU list maintenance */
-          nat44_session_update_lru (sm, s0, thread_index);
 
         trace00:
           if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
@@ -2340,7 +2490,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
               if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
                 {
-                  next1 = icmp_out2in_slow_path
+                  next1 = icmp_out2in_ed_slow_path
                     (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
                      next1, now, thread_index, &s1);
                   goto trace01;
@@ -2386,8 +2536,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;
                         }
 
@@ -2400,7 +2549,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                         {
                           if (next_src_nat(sm, ip1, ip1->protocol,
                                            udp1->src_port, udp1->dst_port,
-                                           thread_index))
+                                           thread_index, rx_fib_index1))
                             {
                               next1 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
                               goto trace01;
@@ -2415,7 +2564,8 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                   s1 = create_session_for_static_mapping_ed(sm, b1, l_key1,
                                                             e_key1, node,
                                                             thread_index,
-                                                            twice_nat1, is_lb1);
+                                                            twice_nat1, is_lb1,
+                                                            now);
 
                   if (!s1)
                     {
@@ -2486,8 +2636,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
           /* Accounting */
           nat44_session_update_counters (s1, now,
                                          vlib_buffer_length_in_chain (vm, b1));
-          /* Per-user LRU list maintenance */
-          nat44_session_update_lru (sm, s1, thread_index);
 
         trace01:
           if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
@@ -2576,7 +2724,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
               if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
                 {
-                  next0 = icmp_out2in_slow_path
+                  next0 = icmp_out2in_ed_slow_path
                     (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
                      next0, now, thread_index, &s0);
                   goto trace0;
@@ -2622,8 +2770,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;
                         }
 
@@ -2636,7 +2783,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                         {
                           if (next_src_nat(sm, ip0, ip0->protocol,
                                            udp0->src_port, udp0->dst_port,
-                                           thread_index))
+                                           thread_index, rx_fib_index0))
                             {
                               next0 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
                               goto trace0;
@@ -2651,7 +2798,8 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                   s0 = create_session_for_static_mapping_ed(sm, b0, l_key0,
                                                             e_key0, node,
                                                             thread_index,
-                                                            twice_nat0, is_lb0);
+                                                            twice_nat0, is_lb0,
+                                                            now);
 
                   if (!s0)
                     {
@@ -2722,8 +2870,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
           /* Accounting */
           nat44_session_update_counters (s0, now,
                                          vlib_buffer_length_in_chain (vm, b0));
-          /* Per-user LRU list maintenance */
-          nat44_session_update_lru (sm, s0, thread_index);
 
         trace0:
           if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
@@ -2837,7 +2983,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 +3619,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 +3846,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))
             {