nat: fix LRU blocked by inactive session
[vpp.git] / src / plugins / nat / in2out_ed.c
index f8682d0..45d9fd0 100644 (file)
@@ -31,6 +31,7 @@
 #include <nat/nat44/inlines.h>
 #include <nat/nat_syslog.h>
 #include <nat/nat_ha.h>
+#include <nat/nat44/ed_inlines.h>
 
 static char *nat_in2out_ed_error_strings[] = {
 #define _(sym,string) string,
@@ -155,7 +156,7 @@ nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
       snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
                                          &s->out2in);
     delete:
-      nat44_ed_delete_session (sm, s, ctx->thread_index, 1);
+      nat_ed_session_delete (sm, s, ctx->thread_index, 1);
       return 1;
     }
 
@@ -323,7 +324,7 @@ slow_path_ed (snat_main_t * sm,
   if (PREDICT_FALSE
       (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
     {
-      if (!nat_global_lru_free_one (sm, thread_index, now))
+      if (!nat_lru_free_one (sm, thread_index, now))
        {
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
          nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
@@ -342,7 +343,7 @@ slow_path_ed (snat_main_t * sm,
   if (snat_static_mapping_match
       (sm, key0, &key1, 0, 0, 0, &lb, 0, &identity_nat))
     {
-      s = nat_ed_session_alloc (sm, thread_index, now);
+      s = nat_ed_session_alloc (sm, thread_index, now, proto);
       if (!s)
        {
          nat_elog_warn ("create NAT session failed");
@@ -386,7 +387,7 @@ slow_path_ed (snat_main_t * sm,
          nat_elog_notice ("addresses exhausted");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
          nat_free_session_data (sm, s, thread_index, 0);
-         nat44_ed_delete_session (sm, s, thread_index, 1);
+         nat_ed_session_delete (sm, s, thread_index, 1);
          return NAT_NEXT_DROP;
        }
       key1.addr = allocated_addr;
@@ -399,7 +400,7 @@ slow_path_ed (snat_main_t * sm,
          *sessionp = s;
          return next;
        }
-      s = nat_ed_session_alloc (sm, thread_index, now);
+      s = nat_ed_session_alloc (sm, thread_index, now, proto);
       if (!s)
        {
          nat_elog_warn ("create NAT session failed");
@@ -601,7 +602,7 @@ nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
       if (nat44_is_ses_closed (s))
        {
          nat_free_session_data (sm, s, thread_index, 0);
-         nat44_ed_delete_session (sm, s, thread_index, 1);
+         nat_ed_session_delete (sm, s, thread_index, 1);
        }
       else
        s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
@@ -857,7 +858,7 @@ nat44_ed_in2out_unknown_proto (snat_main_t * sm,
        }
 
     create_ses:
-      s = nat_ed_session_alloc (sm, thread_index, now);
+      s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
       if (!s)
        {
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
@@ -1026,9 +1027,9 @@ nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
            }
          s0 = pool_elt_at_index (tsm->sessions, value0.value);
 
-         if (s0->tcp_close_timestamp)
+         if (s0->tcp_closed_timestamp)
            {
-             if (now >= s0->tcp_close_timestamp)
+             if (now >= s0->tcp_closed_timestamp)
                {
                  // session is closed, go slow path
                  next0 = def_slow;
@@ -1049,7 +1050,7 @@ nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
          if (now >= sess_timeout_time)
            {
              nat_free_session_data (sm, s0, thread_index, 0);
-             nat44_ed_delete_session (sm, s0, thread_index, 1);
+             nat_ed_session_delete (sm, s0, thread_index, 1);
              // session is closed, go slow path
              next0 = def_slow;
              goto trace0;
@@ -1307,10 +1308,10 @@ nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
            {
              s0 = pool_elt_at_index (tsm->sessions, value0.value);
 
-             if (s0->tcp_close_timestamp && now >= s0->tcp_close_timestamp)
+             if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
                {
                  nat_free_session_data (sm, s0, thread_index, 0);
-                 nat44_ed_delete_session (sm, s0, thread_index, 1);
+                 nat_ed_session_delete (sm, s0, thread_index, 1);
                  s0 = NULL;
                }
            }