nat: add tracing for nat44-hairpinning
[vpp.git] / src / plugins / nat / in2out.c
old mode 100755 (executable)
new mode 100644 (file)
index 7eaaab2..8616d90
 #include <nat/nat.h>
 #include <nat/nat_ipfix_logging.h>
 #include <nat/nat_inlines.h>
-#include <nat/nat44_inlines.h>
+#include <nat/nat44/inlines.h>
 #include <nat/nat_syslog.h>
 #include <nat/nat_ha.h>
 
 #include <vppinfra/hash.h>
 #include <vppinfra/error.h>
 #include <vppinfra/elog.h>
+#include <nat/lib/nat_inlines.h>
 
 typedef struct
 {
@@ -42,6 +43,7 @@ typedef struct
   u32 next_index;
   u32 session_index;
   u32 is_slow_path;
+  u32 is_hairpinning;
 } snat_in2out_trace_t;
 
 /* packet trace format function */
@@ -57,6 +59,10 @@ format_snat_in2out_trace (u8 * s, va_list * args)
 
   s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
              t->sw_if_index, t->next_index, t->session_index);
+  if (t->is_hairpinning)
+    {
+      s = format (s, ", with-hairpinning");
+    }
 
   return s;
 }
@@ -264,10 +270,7 @@ slow_path (snat_main_t * sm, vlib_buffer_t * b0,
   };
   nat44_is_idle_session_ctx_t ctx0;
 
-  nat44_session_try_cleanup (&ip0->src_address, rx_fib_index0, thread_index,
-                            now);
-
-  if (PREDICT_FALSE (maximum_sessions_exceeded (sm, thread_index)))
+  if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
     {
       b0->error = node->errors[SNAT_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
       nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
@@ -412,7 +415,7 @@ static_always_inline
   if (!icmp_type_is_error_message
       (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
     {
-      key0.protocol = SNAT_PROTOCOL_ICMP;
+      key0.protocol = NAT_PROTOCOL_ICMP;
       key0.addr = ip0->src_address;
       key0.port = vnet_buffer (b)->ip.reass.l4_src_port;       // TODO fixme should this be dst port?
     }
@@ -420,17 +423,17 @@ static_always_inline
     {
       inner_ip0 = (ip4_header_t *) (echo0 + 1);
       l4_header = ip4_next_header (inner_ip0);
-      key0.protocol = ip_proto_to_snat_proto (inner_ip0->protocol);
+      key0.protocol = ip_proto_to_nat_proto (inner_ip0->protocol);
       key0.addr = inner_ip0->dst_address;
       switch (key0.protocol)
        {
-       case SNAT_PROTOCOL_ICMP:
+       case NAT_PROTOCOL_ICMP:
          inner_icmp0 = (icmp46_header_t *) l4_header;
          inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
          key0.port = inner_echo0->identifier;
          break;
-       case SNAT_PROTOCOL_UDP:
-       case SNAT_PROTOCOL_TCP:
+       case NAT_PROTOCOL_UDP:
+       case NAT_PROTOCOL_TCP:
          key0.port = ((tcp_udp_header_t *) l4_header)->dst_port;
          break;
        default:
@@ -449,6 +452,7 @@ static_always_inline
  * @param[in,out] node           NAT node runtime
  * @param[in] thread_index       thread index
  * @param[in,out] b0             buffer containing packet to be translated
+ * @param[in,out] ip0            ip header
  * @param[out] p_proto           protocol used for matching
  * @param[out] p_value           address and port after NAT translation
  * @param[out] p_dont_translate  if packet should not be translated
@@ -462,6 +466,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
                        snat_session_key_t * p_value,
                        u8 * p_dont_translate, void *d, void *e)
 {
+  snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
   u32 sw_if_index0;
   u32 rx_fib_index0;
   snat_session_key_t key0;
@@ -470,6 +475,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
   clib_bihash_kv_8_8_t kv0, value0;
   u32 next0 = ~0;
   int err;
+  vlib_main_t *vm = vlib_get_main ();
 
   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);
@@ -485,8 +491,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
 
   kv0.key = key0.as_u64;
 
-  if (clib_bihash_search_8_8 (&sm->per_thread_data[thread_index].in2out, &kv0,
-                             &value0))
+  if (clib_bihash_search_8_8 (&tsm->in2out, &kv0, &value0))
     {
       if (vnet_buffer (b0)->sw_if_index[VLIB_TX] != ~0)
        {
@@ -504,7 +509,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
       else
        {
          if (PREDICT_FALSE (snat_not_translate (sm, node, sw_if_index0,
-                                                ip0, SNAT_PROTOCOL_ICMP,
+                                                ip0, NAT_PROTOCOL_ICMP,
                                                 rx_fib_index0,
                                                 thread_index)))
            {
@@ -523,7 +528,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
        }
 
       next0 = slow_path (sm, b0, ip0, rx_fib_index0, &key0, &s0, node, next0,
-                        thread_index, vlib_time_now (sm->vlib_main));
+                        thread_index, vlib_time_now (vm));
 
       if (PREDICT_FALSE (next0 == SNAT_IN2OUT_NEXT_DROP))
        goto out;
@@ -549,8 +554,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
          goto out;
        }
 
-      s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
-                             value0.value);
+      s0 = pool_elt_at_index (tsm->sessions, value0.value);
     }
 
 out:
@@ -572,6 +576,7 @@ out:
  * @param[in,out] node           NAT node runtime
  * @param[in] thread_index       thread index
  * @param[in,out] b0             buffer containing packet to be translated
+ * @param[in,out] ip0            ip header
  * @param[out] p_proto           protocol used for matching
  * @param[out] p_value           address and port after NAT translation
  * @param[out] p_dont_translate  if packet should not be translated
@@ -661,6 +666,7 @@ icmp_in2out (snat_main_t * sm,
             vlib_node_runtime_t * node,
             u32 next0, u32 thread_index, void *d, void *e)
 {
+  vlib_main_t *vm = vlib_get_main ();
   snat_session_key_t sm0;
   u8 protocol;
   icmp_echo_header_t *echo0, *inner_echo0 = 0;
@@ -687,11 +693,12 @@ icmp_in2out (snat_main_t * sm,
 
   if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
     {
-      sum0 = ip_incremental_checksum_buffer (sm->vlib_main, b0, (u8 *) icmp0 -
-                                            (u8 *)
-                                            vlib_buffer_get_current (b0),
-                                            ntohs (ip0->length) -
-                                            ip4_header_bytes (ip0), 0);
+      sum0 =
+       ip_incremental_checksum_buffer (vm, b0,
+                                       (u8 *) icmp0 -
+                                       (u8 *) vlib_buffer_get_current (b0),
+                                       ntohs (ip0->length) -
+                                       ip4_header_bytes (ip0), 0);
       checksum0 = ~ip_csum_fold (sum0);
       if (PREDICT_FALSE (checksum0 != 0 && checksum0 != 0xffff))
        {
@@ -764,7 +771,7 @@ icmp_in2out (snat_main_t * sm,
 
          switch (protocol)
            {
-           case SNAT_PROTOCOL_ICMP:
+           case NAT_PROTOCOL_ICMP:
              inner_icmp0 = (icmp46_header_t *) l4_header;
              inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
 
@@ -778,8 +785,8 @@ icmp_in2out (snat_main_t * sm,
                                identifier);
              icmp0->checksum = ip_csum_fold (sum0);
              break;
-           case SNAT_PROTOCOL_UDP:
-           case SNAT_PROTOCOL_TCP:
+           case NAT_PROTOCOL_UDP:
+           case NAT_PROTOCOL_TCP:
              old_id0 = ((tcp_udp_header_t *) l4_header)->dst_port;
              new_id0 = sm0.port;
              ((tcp_udp_header_t *) l4_header)->dst_port = new_id0;
@@ -819,6 +826,8 @@ icmp_in2out_slow_path (snat_main_t * sm,
                       u32 next0,
                       f64 now, u32 thread_index, snat_session_t ** p_s0)
 {
+  vlib_main_t *vm = vlib_get_main ();
+
   next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
                       next0, thread_index, p_s0, 0);
   snat_session_t *s0 = *p_s0;
@@ -827,7 +836,7 @@ icmp_in2out_slow_path (snat_main_t * sm,
       /* Accounting */
       nat44_session_update_counters (s0, now,
                                     vlib_buffer_length_in_chain
-                                    (sm->vlib_main, b0), thread_index);
+                                    (vm, b0), thread_index);
       /* Per-user LRU list maintenance */
       nat44_session_update_lru (sm, s0, thread_index);
     }
@@ -972,12 +981,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
              goto trace00;
            }
 
-         proto0 = ip_proto_to_snat_proto (ip0->protocol);
+         proto0 = ip_proto_to_nat_proto (ip0->protocol);
 
          /* Next configured feature, probably ip4-lookup */
          if (is_slow_path)
            {
-             if (PREDICT_FALSE (proto0 == ~0))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
                {
                  if (nat_in2out_sm_unknown_proto
                      (sm, b0, ip0, rx_fib_index0))
@@ -990,7 +999,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  goto trace00;
                }
 
-             if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
                {
                  next0 = icmp_in2out_slow_path
                    (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
@@ -1001,13 +1010,13 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            }
          else
            {
-             if (PREDICT_FALSE (proto0 == ~0))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
                {
                  next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace00;
                }
 
-             if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
                {
                  next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace00;
@@ -1043,11 +1052,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto0 == SNAT_PROTOCOL_UDP
+                         (proto0 == NAT_PROTOCOL_UDP
                           && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip0->dst_address.as_u32 == 0xffffffff))
                        goto trace00;
                    }
                  else
@@ -1093,7 +1102,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
          ip0->checksum = ip_csum_fold (sum0);
 
 
-         if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+         if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
@@ -1106,7 +1115,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  sum0 = ip_csum_update (sum0, old_port0, new_port0,
                                         ip4_header_t /* cheat */ ,
                                         length /* changed member */ );
-                 mss_clamping (sm, tcp0, &sum0);
+                 mss_clamping (sm->mss_clamping, tcp0, &sum0);
                  tcp0->checksum = ip_csum_fold (sum0);
                }
              tcp_packets++;
@@ -1115,10 +1124,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
+                 udp0->src_port = s0->out2in.port;
                  if (PREDICT_FALSE (udp0->checksum))
                    {
                      old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
-                     new_port0 = udp0->src_port = s0->out2in.port;
+                     new_port0 = udp0->src_port;
                      sum0 = udp0->checksum;
                      sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address      /* changed member */
                        );
@@ -1180,12 +1190,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
              goto trace01;
            }
 
-         proto1 = ip_proto_to_snat_proto (ip1->protocol);
+         proto1 = ip_proto_to_nat_proto (ip1->protocol);
 
          /* Next configured feature, probably ip4-lookup */
          if (is_slow_path)
            {
-             if (PREDICT_FALSE (proto1 == ~0))
+             if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_OTHER))
                {
                  if (nat_in2out_sm_unknown_proto
                      (sm, b1, ip1, rx_fib_index1))
@@ -1198,7 +1208,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  goto trace01;
                }
 
-             if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
                {
                  next1 = icmp_in2out_slow_path
                    (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
@@ -1209,13 +1219,13 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            }
          else
            {
-             if (PREDICT_FALSE (proto1 == ~0))
+             if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_OTHER))
                {
                  next1 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace01;
                }
 
-             if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
                {
                  next1 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace01;
@@ -1251,11 +1261,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto1 == SNAT_PROTOCOL_UDP
+                         (proto1 == NAT_PROTOCOL_UDP
                           && (vnet_buffer (b1)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip1->dst_address.as_u32 == 0xffffffff))
                        goto trace01;
                    }
                  else
@@ -1300,7 +1310,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                                 src_address /* changed member */ );
          ip1->checksum = ip_csum_fold (sum1);
 
-         if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
+         if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP))
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
@@ -1313,7 +1323,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  sum1 = ip_csum_update (sum1, old_port1, new_port1,
                                         ip4_header_t /* cheat */ ,
                                         length /* changed member */ );
-                 mss_clamping (sm, tcp1, &sum1);
+                 mss_clamping (sm->mss_clamping, tcp1, &sum1);
                  tcp1->checksum = ip_csum_fold (sum1);
                }
              tcp_packets++;
@@ -1322,10 +1332,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
+                 udp1->src_port = s1->out2in.port;
                  if (PREDICT_FALSE (udp1->checksum))
                    {
                      old_port1 = vnet_buffer (b1)->ip.reass.l4_src_port;
-                     new_port1 = udp1->src_port = s1->out2in.port;
+                     new_port1 = udp1->src_port;
                      sum1 = udp1->checksum;
                      sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t, dst_address      /* changed member */
                        );
@@ -1423,12 +1434,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
              goto trace0;
            }
 
-         proto0 = ip_proto_to_snat_proto (ip0->protocol);
+         proto0 = ip_proto_to_nat_proto (ip0->protocol);
 
          /* Next configured feature, probably ip4-lookup */
          if (is_slow_path)
            {
-             if (PREDICT_FALSE (proto0 == ~0))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
                {
                  if (nat_in2out_sm_unknown_proto
                      (sm, b0, ip0, rx_fib_index0))
@@ -1441,7 +1452,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  goto trace0;
                }
 
-             if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
                {
                  next0 = icmp_in2out_slow_path
                    (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
@@ -1452,13 +1463,13 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            }
          else
            {
-             if (PREDICT_FALSE (proto0 == ~0))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
                {
                  next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace0;
                }
 
-             if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
                {
                  next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
                  goto trace0;
@@ -1492,11 +1503,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                       * be able to use dhcp client on the outside interface
                       */
                      if (PREDICT_FALSE
-                         ((b0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)
-                          && proto0 == SNAT_PROTOCOL_UDP
+                         (proto0 == NAT_PROTOCOL_UDP
                           && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
                               clib_host_to_net_u16
-                              (UDP_DST_PORT_dhcp_to_server))))
+                              (UDP_DST_PORT_dhcp_to_server))
+                          && ip0->dst_address.as_u32 == 0xffffffff))
                        goto trace0;
                    }
                  else
@@ -1542,7 +1553,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                                 src_address /* changed member */ );
          ip0->checksum = ip_csum_fold (sum0);
 
-         if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+         if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
@@ -1555,7 +1566,7 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
                  sum0 = ip_csum_update (sum0, old_port0, new_port0,
                                         ip4_header_t /* cheat */ ,
                                         length /* changed member */ );
-                 mss_clamping (sm, tcp0, &sum0);
+                 mss_clamping (sm->mss_clamping, tcp0, &sum0);
                  tcp0->checksum = ip_csum_fold (sum0);
                }
              tcp_packets++;
@@ -1564,10 +1575,11 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
            {
              if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
                {
+                 udp0->src_port = s0->out2in.port;
                  if (PREDICT_FALSE (udp0->checksum))
                    {
                      old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
-                     new_port0 = udp0->src_port = s0->out2in.port;
+                     new_port0 = udp0->src_port;
                      sum0 = udp0->checksum;
                      sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address      /* changed member */
                        );
@@ -1769,6 +1781,7 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
   u32 pkts_processed = 0;
   snat_main_t *sm = &snat_main;
   u32 stats_node_index;
+  int is_hairpinning = 0;
 
   stats_node_index = sm->in2out_fast_node_index;
 
@@ -1829,12 +1842,12 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
              goto trace0;
            }
 
-         proto0 = ip_proto_to_snat_proto (ip0->protocol);
+         proto0 = ip_proto_to_nat_proto (ip0->protocol);
 
-         if (PREDICT_FALSE (proto0 == ~0))
+         if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
            goto trace0;
 
-         if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+         if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
            {
              next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
                                   rx_fib_index0, node, next0, ~0, 0, 0);
@@ -1870,7 +1883,7 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
              old_port0 = udp0->src_port;
              udp0->src_port = new_port0;
 
-             if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+             if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
                {
                  sum0 = tcp0->checksum;
                  sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
@@ -1879,7 +1892,7 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
                  sum0 = ip_csum_update (sum0, old_port0, new_port0,
                                         ip4_header_t /* cheat */ ,
                                         length /* changed member */ );
-                 mss_clamping (sm, tcp0, &sum0);
+                 mss_clamping (sm->mss_clamping, tcp0, &sum0);
                  tcp0->checksum = ip_csum_fold (sum0);
                }
              else if (udp0->checksum)
@@ -1896,13 +1909,13 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
            }
          else
            {
-             if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+             if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
                {
                  sum0 = tcp0->checksum;
                  sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
                                         ip4_header_t,
                                         dst_address /* changed member */ );
-                 mss_clamping (sm, tcp0, &sum0);
+                 mss_clamping (sm->mss_clamping, tcp0, &sum0);
                  tcp0->checksum = ip_csum_fold (sum0);
                }
              else if (udp0->checksum)
@@ -1916,7 +1929,9 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
            }
 
          /* Hairpinning */
-         snat_hairpinning (sm, b0, ip0, udp0, tcp0, proto0, 0);
+         snat_hairpinning (vm, node, sm, b0, ip0, udp0, tcp0, proto0, 0,
+                           0 /* do_trace */ );
+         is_hairpinning = 1;
 
        trace0:
          if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
@@ -1926,6 +1941,7 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
                vlib_add_trace (vm, node, b0, sizeof (*t));
              t->sw_if_index = sw_if_index0;
              t->next_index = next0;
+             t->is_hairpinning = is_hairpinning;
            }
 
          pkts_processed += next0 != SNAT_IN2OUT_NEXT_DROP;