misc: move to new pool_foreach macros
[vpp.git] / src / plugins / nat / in2out_ed.c
index f0bb0f9..776efdf 100644 (file)
@@ -28,7 +28,7 @@
 #include <nat/lib/ipfix_logging.h>
 #include <nat/nat_inlines.h>
 #include <nat/nat44/inlines.h>
-#include <nat/nat_syslog.h>
+#include <nat/lib/nat_syslog.h>
 #include <nat/nat_ha.h>
 #include <nat/nat44/ed_inlines.h>
 #include <nat/lib/nat_inlines.h>
@@ -565,9 +565,7 @@ nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
        {
          if (ip->protocol == IP_PROTOCOL_TCP)
            {
-             if (nat44_set_tcp_session_state_i2o
-                 (sm, now, s, b, thread_index))
-               return 1;
+             nat44_set_tcp_session_state_i2o (sm, now, s, b, thread_index);
            }
          /* Accounting */
          nat44_session_update_counters (s, now,
@@ -588,7 +586,7 @@ static_always_inline int
 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
                                       u16 src_port, u16 dst_port,
                                       u32 thread_index, u32 rx_sw_if_index,
-                                      u32 tx_sw_if_index)
+                                      u32 tx_sw_if_index, f64 now)
 {
   clib_bihash_kv_16_8_t kv, value;
   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
@@ -606,13 +604,12 @@ nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
       s =
        pool_elt_at_index (tsm->sessions,
                           ed_value_get_session_index (&value));
-      if (nat44_is_ses_closed (s))
+      if (nat44_is_ses_closed (s)
+         && (!s->tcp_closed_timestamp || now >= s->tcp_closed_timestamp))
        {
          nat_free_session_data (sm, s, thread_index, 0);
          nat_ed_session_delete (sm, s, thread_index, 1);
        }
-      else
-       s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
       return 1;
     }
 
@@ -630,11 +627,11 @@ nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
 
       /* hairpinning */
       /* *INDENT-OFF* */
-      pool_foreach (i, sm->output_feature_interfaces,
-      ({
+      pool_foreach (i, sm->output_feature_interfaces)
+       {
         if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
            return 0;
-      }));
+      }
       /* *INDENT-ON* */
       return 1;
     }
@@ -660,6 +657,7 @@ icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
   vlib_main_t *vm = vlib_get_main ();
   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
   *dont_translate = 0;
+  f64 now = vlib_time_now (vm);
 
   sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
   rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
@@ -681,7 +679,7 @@ icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
          if (PREDICT_FALSE
              (nat44_ed_not_translate_output_feature
               (sm, ip, l_port, r_port, thread_index,
-               sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
+               sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX], now)))
            {
              *dont_translate = 1;
              goto out;
@@ -828,7 +826,7 @@ nat44_ed_in2out_unknown_proto (snat_main_t * sm,
       else
        {
          /* *INDENT-OFF* */
-         pool_foreach (s, tsm->sessions, {
+         pool_foreach (s, tsm->sessions) {
            if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
              {
                new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
@@ -839,7 +837,7 @@ nat44_ed_in2out_unknown_proto (snat_main_t * sm,
 
                break;
              }
-         });
+         }
          /* *INDENT-ON* */
 
          for (i = 0; i < vec_len (sm->addresses); i++)
@@ -1114,8 +1112,7 @@ nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
            }
          vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.tcp,
                                         thread_index, sw_if_index0, 1);
-         if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
-           goto trace0;
+         nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
        }
       else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
               && udp0->checksum)
@@ -1314,7 +1311,8 @@ nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
                  (nat44_ed_not_translate_output_feature
                   (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
                    vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
-                   sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX])))
+                   sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX],
+                   now)))
                goto trace0;
 
              /*
@@ -1400,8 +1398,7 @@ nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
            }
          vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.tcp,
                                         thread_index, sw_if_index0, 1);
-         if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
-           goto trace0;
+         nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
        }
       else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
               && udp0->checksum)