nat: respect arc features (multi worker)
[vpp.git] / src / plugins / nat / out2in_ed.c
index 560c23e..a81d58e 100644 (file)
 #include <nat/nat_syslog.h>
 #include <nat/nat_ha.h>
 
-#define foreach_nat_out2in_ed_error                     \
-_(UNSUPPORTED_PROTOCOL, "unsupported protocol")         \
-_(OUT2IN_PACKETS, "good out2in packets processed")      \
-_(OUT_OF_PORTS, "out of ports")                         \
-_(BAD_ICMP_TYPE, "unsupported ICMP type")               \
-_(NO_TRANSLATION, "no translation")                     \
-_(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded")   \
-_(DROP_FRAGMENT, "drop fragment")                       \
-_(MAX_REASS, "maximum reassemblies exceeded")           \
-_(MAX_FRAG, "maximum fragments per reassembly exceeded")\
-_(NON_SYN, "non-SYN packet try to create session")      \
-_(TCP_PACKETS, "TCP packets")                           \
-_(UDP_PACKETS, "UDP packets")                           \
-_(ICMP_PACKETS, "ICMP packets")                         \
-_(OTHER_PACKETS, "other protocol packets")              \
-_(FRAGMENTS, "fragments")                               \
-_(CACHED_FRAGMENTS, "cached fragments")                 \
-_(PROCESSED_FRAGMENTS, "processed fragments")
-
-typedef enum
-{
-#define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
-  foreach_nat_out2in_ed_error
-#undef _
-    NAT_OUT2IN_ED_N_ERROR,
-} nat_out2in_ed_error_t;
-
 static char *nat_out2in_ed_error_strings[] = {
 #define _(sym,string) string,
   foreach_nat_out2in_ed_error
 #undef _
 };
 
-typedef enum
-{
-  NAT44_ED_OUT2IN_NEXT_DROP,
-  NAT44_ED_OUT2IN_NEXT_LOOKUP,
-  NAT44_ED_OUT2IN_NEXT_ICMP_ERROR,
-  NAT44_ED_OUT2IN_NEXT_IN2OUT,
-  NAT44_ED_OUT2IN_NEXT_SLOW_PATH,
-  NAT44_ED_OUT2IN_NEXT_REASS,
-  NAT44_ED_OUT2IN_N_NEXT,
-} nat44_ed_out2in_next_t;
-
 typedef struct
 {
   u32 sw_if_index;
@@ -112,7 +74,7 @@ icmp_out2in_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
   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 != NAT44_ED_OUT2IN_NEXT_DROP && s0))
+  if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
     {
       /* Accounting */
       nat44_session_update_counters (s0, now,
@@ -345,55 +307,6 @@ create_session_for_static_mapping_ed (snat_main_t * sm,
   return s;
 }
 
-static_always_inline int
-icmp_get_ed_key (ip4_header_t * ip0, nat_ed_ses_key_t * p_key0)
-{
-  icmp46_header_t *icmp0;
-  nat_ed_ses_key_t key0;
-  icmp_echo_header_t *echo0, *inner_echo0 = 0;
-  ip4_header_t *inner_ip0;
-  void *l4_header = 0;
-  icmp46_header_t *inner_icmp0;
-
-  icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
-  echo0 = (icmp_echo_header_t *) (icmp0 + 1);
-
-  if (!icmp_is_error_message (icmp0))
-    {
-      key0.proto = IP_PROTOCOL_ICMP;
-      key0.l_addr = ip0->dst_address;
-      key0.r_addr = ip0->src_address;
-      key0.l_port = echo0->identifier;
-      key0.r_port = 0;
-    }
-  else
-    {
-      inner_ip0 = (ip4_header_t *) (echo0 + 1);
-      l4_header = ip4_next_header (inner_ip0);
-      key0.proto = inner_ip0->protocol;
-      key0.l_addr = inner_ip0->src_address;
-      key0.r_addr = inner_ip0->dst_address;
-      switch (ip_proto_to_snat_proto (inner_ip0->protocol))
-       {
-       case SNAT_PROTOCOL_ICMP:
-         inner_icmp0 = (icmp46_header_t *) l4_header;
-         inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
-         key0.l_port = inner_echo0->identifier;
-         key0.r_port = 0;
-         break;
-       case SNAT_PROTOCOL_UDP:
-       case SNAT_PROTOCOL_TCP:
-         key0.l_port = ((tcp_udp_header_t *) l4_header)->src_port;
-         key0.r_port = ((tcp_udp_header_t *) l4_header)->dst_port;
-         break;
-       default:
-         return -1;
-       }
-    }
-  *p_key0 = key0;
-  return 0;
-}
-
 static int
 next_src_nat (snat_main_t * sm, ip4_header_t * ip, u8 proto, u16 src_port,
              u16 dst_port, u32 thread_index, u32 rx_fib_index)
@@ -423,7 +336,7 @@ create_bypass_for_fwd (snat_main_t * sm, ip4_header_t * ip, u32 rx_fib_index,
 
   if (ip->protocol == IP_PROTOCOL_ICMP)
     {
-      if (icmp_get_ed_key (ip, &key))
+      if (get_icmp_o2i_ed_key (ip, &key))
        return;
     }
   else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
@@ -515,7 +428,7 @@ create_bypass_for_fwd_worker (snat_main_t * sm, ip4_header_t * ip,
   ip4_header_t ip_wkr = {
     .src_address = ip->dst_address,
   };
-  u32 thread_index = sm->worker_in2out_cb (&ip_wkr, rx_fib_index);
+  u32 thread_index = sm->worker_in2out_cb (&ip_wkr, rx_fib_index, 0);
 
   create_bypass_for_fwd (sm, ip, rx_fib_index, thread_index);
 }
@@ -540,10 +453,10 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
   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);
 
-  if (icmp_get_ed_key (ip, &key))
+  if (get_icmp_o2i_ed_key (ip, &key))
     {
       b->error = node->errors[NAT_OUT2IN_ED_ERROR_UNSUPPORTED_PROTOCOL];
-      next = NAT44_ED_OUT2IN_NEXT_DROP;
+      next = NAT_NEXT_DROP;
       goto out;
     }
   key.fib_index = rx_fib_index;
@@ -570,7 +483,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
                  goto out;
                }
              b->error = node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-             next = NAT44_ED_OUT2IN_NEXT_DROP;
+             next = NAT_NEXT_DROP;
              goto out;
            }
          else
@@ -579,7 +492,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
              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;
+                 next = NAT_NEXT_IN2OUT_ED_FAST_PATH;
                  goto out;
                }
              if (sm->num_workers > 1)
@@ -594,7 +507,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
                         (icmp->type != ICMP4_echo_request || !is_addr_only)))
        {
          b->error = node->errors[NAT_OUT2IN_ED_ERROR_BAD_ICMP_TYPE];
-         next = NAT44_ED_OUT2IN_NEXT_DROP;
+         next = NAT_NEXT_DROP;
          goto out;
        }
 
@@ -612,7 +525,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
 
       if (!s)
        {
-         next = NAT44_ED_OUT2IN_NEXT_DROP;
+         next = NAT_NEXT_DROP;
          goto out;
        }
     }
@@ -623,7 +536,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
                         !icmp_is_error_message (icmp)))
        {
          b->error = node->errors[NAT_OUT2IN_ED_ERROR_BAD_ICMP_TYPE];
-         next = NAT44_ED_OUT2IN_NEXT_DROP;
+         next = NAT_NEXT_DROP;
          goto out;
        }
 
@@ -752,7 +665,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                vlib_frame_t * frame, int is_slow_path)
 {
   u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
-  nat44_ed_out2in_next_t next_index;
+  nat_next_t next_index;
   snat_main_t *sm = &snat_main;
   f64 now = vlib_time_now (vm);
   u32 thread_index = vm->thread_index;
@@ -819,7 +732,9 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
          b0 = vlib_get_buffer (vm, bi0);
          b1 = vlib_get_buffer (vm, bi1);
 
-         next0 = NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         next0 = nat_buffer_opaque (b0)->arc_next;
+         next1 = nat_buffer_opaque (b1)->arc_next;
+
          vnet_buffer (b0)->snat.flags = 0;
          ip0 = vlib_buffer_get_current (b0);
 
@@ -834,7 +749,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
              icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
                                           ICMP4_time_exceeded_ttl_exceeded_in_transit,
                                           0);
-             next0 = NAT44_ED_OUT2IN_NEXT_ICMP_ERROR;
+             next0 = NAT_NEXT_ICMP_ERROR;
              goto trace00;
            }
 
@@ -855,7 +770,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if (!sm->forwarding_enabled)
                    {
                      if (!s0)
-                       next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                       next0 = NAT_NEXT_DROP;
                      goto trace00;
                    }
                }
@@ -873,20 +788,20 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
            {
              if (PREDICT_FALSE (proto0 == ~0))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace00;
                }
 
              if (ip4_is_fragment (ip0))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_REASS;
+                 next0 = NAT_NEXT_OUT2IN_ED_REASS;
                  fragments++;
                  goto trace00;
                }
 
              if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace00;
                }
            }
@@ -919,7 +834,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                             clib_host_to_net_u16
                                             (UDP_DST_PORT_dhcp_to_client))))
                        {
-                         vnet_feature_next (&next0, b0);
                          goto trace00;
                        }
 
@@ -927,7 +841,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                        {
                          b0->error =
                            node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-                         next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                         next0 = NAT_NEXT_DROP;
                        }
                      else
                        {
@@ -935,7 +849,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                            udp0->src_port, udp0->dst_port,
                                            thread_index, rx_fib_index0))
                            {
-                             next0 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
+                             next0 = NAT_NEXT_IN2OUT_ED_FAST_PATH;
                              goto trace00;
                            }
                          if (sm->num_workers > 1)
@@ -954,7 +868,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if ((proto0 == SNAT_PROTOCOL_TCP) && !tcp_is_init (tcp0))
                    {
                      b0->error = node->errors[NAT_OUT2IN_ED_ERROR_NON_SYN];
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace00;
                    }
 
@@ -967,13 +881,13 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
                  if (!s0)
                    {
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace00;
                    }
                }
              else
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace00;
                }
            }
@@ -995,11 +909,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                   src_address);
          ip0->checksum = ip_csum_fold (sum0);
 
+         old_port0 = udp0->dst_port;
+         new_port0 = udp0->dst_port = s0->in2out.port;
+
          if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
            {
-             old_port0 = tcp0->dst_port;
-             new_port0 = tcp0->dst_port = s0->in2out.port;
-
              sum0 = tcp0->checksum;
              sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
                                     dst_address);
@@ -1022,15 +936,34 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  (sm, s0, tcp0, thread_index))
                goto trace00;
            }
+         else if (udp0->checksum)
+           {
+             sum0 = udp0->checksum;
+             sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
+                                    dst_address);
+             sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
+                                    length);
+             if (PREDICT_FALSE (is_twice_nat_session (s0)))
+               {
+                 sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
+                                        s0->ext_host_nat_addr.as_u32,
+                                        ip4_header_t, dst_address);
+                 sum0 = ip_csum_update (sum0, udp0->src_port,
+                                        s0->ext_host_nat_port, ip4_header_t,
+                                        length);
+                 udp0->src_port = s0->ext_host_nat_port;
+                 ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
+               }
+             udp0->checksum = ip_csum_fold (sum0);
+             udp_packets++;
+           }
          else
            {
-             udp0->dst_port = s0->in2out.port;
-             if (is_twice_nat_session (s0))
+             if (PREDICT_FALSE (is_twice_nat_session (s0)))
                {
                  udp0->src_port = s0->ext_host_nat_port;
                  ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
                }
-             udp0->checksum = 0;
              udp_packets++;
            }
 
@@ -1055,9 +988,8 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                t->session_index = s0 - tsm->sessions;
            }
 
-         pkts_processed += next0 == NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
 
-         next1 = NAT44_ED_OUT2IN_NEXT_LOOKUP;
          vnet_buffer (b1)->snat.flags = 0;
          ip1 = vlib_buffer_get_current (b1);
 
@@ -1072,7 +1004,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
              icmp4_error_set_vnet_buffer (b1, ICMP4_time_exceeded,
                                           ICMP4_time_exceeded_ttl_exceeded_in_transit,
                                           0);
-             next1 = NAT44_ED_OUT2IN_NEXT_ICMP_ERROR;
+             next1 = NAT_NEXT_ICMP_ERROR;
              goto trace01;
            }
 
@@ -1093,7 +1025,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if (!sm->forwarding_enabled)
                    {
                      if (!s1)
-                       next1 = NAT44_ED_OUT2IN_NEXT_DROP;
+                       next1 = NAT_NEXT_DROP;
                      goto trace01;
                    }
                }
@@ -1111,20 +1043,20 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
            {
              if (PREDICT_FALSE (proto1 == ~0))
                {
-                 next1 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next1 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace01;
                }
 
              if (ip4_is_fragment (ip1))
                {
-                 next1 = NAT44_ED_OUT2IN_NEXT_REASS;
+                 next1 = NAT_NEXT_OUT2IN_ED_REASS;
                  fragments++;
                  goto trace01;
                }
 
              if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
                {
-                 next1 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next1 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace01;
                }
            }
@@ -1157,7 +1089,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                             clib_host_to_net_u16
                                             (UDP_DST_PORT_dhcp_to_client))))
                        {
-                         vnet_feature_next (&next1, b1);
                          goto trace01;
                        }
 
@@ -1165,7 +1096,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                        {
                          b1->error =
                            node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-                         next1 = NAT44_ED_OUT2IN_NEXT_DROP;
+                         next1 = NAT_NEXT_DROP;
                        }
                      else
                        {
@@ -1173,7 +1104,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                            udp1->src_port, udp1->dst_port,
                                            thread_index, rx_fib_index1))
                            {
-                             next1 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
+                             next1 = NAT_NEXT_IN2OUT_ED_FAST_PATH;
                              goto trace01;
                            }
                          if (sm->num_workers > 1)
@@ -1192,7 +1123,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if ((proto1 == SNAT_PROTOCOL_TCP) && !tcp_is_init (tcp1))
                    {
                      b1->error = node->errors[NAT_OUT2IN_ED_ERROR_NON_SYN];
-                     next1 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next1 = NAT_NEXT_DROP;
                      goto trace01;
                    }
 
@@ -1205,13 +1136,13 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
                  if (!s1)
                    {
-                     next1 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next1 = NAT_NEXT_DROP;
                      goto trace01;
                    }
                }
              else
                {
-                 next1 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next1 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace01;
                }
            }
@@ -1233,11 +1164,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                   src_address);
          ip1->checksum = ip_csum_fold (sum1);
 
+         old_port1 = udp1->dst_port;
+         new_port1 = udp1->dst_port = s1->in2out.port;
+
          if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
            {
-             old_port1 = tcp1->dst_port;
-             new_port1 = tcp1->dst_port = s1->in2out.port;
-
              sum1 = tcp1->checksum;
              sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
                                     dst_address);
@@ -1260,15 +1191,34 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  (sm, s1, tcp1, thread_index))
                goto trace01;
            }
+         else if (udp1->checksum)
+           {
+             sum1 = udp1->checksum;
+             sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
+                                    dst_address);
+             sum1 = ip_csum_update (sum1, old_port1, new_port1, ip4_header_t,
+                                    length);
+             if (PREDICT_FALSE (is_twice_nat_session (s1)))
+               {
+                 sum1 = ip_csum_update (sum1, ip1->src_address.as_u32,
+                                        s1->ext_host_nat_addr.as_u32,
+                                        ip4_header_t, dst_address);
+                 sum1 = ip_csum_update (sum1, udp1->src_port,
+                                        s1->ext_host_nat_port, ip4_header_t,
+                                        length);
+                 udp1->src_port = s1->ext_host_nat_port;
+                 ip1->src_address.as_u32 = s1->ext_host_nat_addr.as_u32;
+               }
+             udp1->checksum = ip_csum_fold (sum1);
+             udp_packets++;
+           }
          else
            {
-             udp1->dst_port = s1->in2out.port;
-             if (is_twice_nat_session (s1))
+             if (PREDICT_FALSE (is_twice_nat_session (s1)))
                {
                  udp1->src_port = s1->ext_host_nat_port;
                  ip1->src_address.as_u32 = s1->ext_host_nat_addr.as_u32;
                }
-             udp1->checksum = 0;
              udp_packets++;
            }
 
@@ -1293,7 +1243,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                t->session_index = s1 - tsm->sessions;
            }
 
-         pkts_processed += next1 == NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         pkts_processed += next1 == nat_buffer_opaque (b1)->arc_next;
 
          /* verify speculative enqueues, maybe switch current next frame */
          vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
@@ -1329,7 +1279,8 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
          n_left_to_next -= 1;
 
          b0 = vlib_get_buffer (vm, bi0);
-         next0 = NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         next0 = nat_buffer_opaque (b0)->arc_next;
+
          vnet_buffer (b0)->snat.flags = 0;
          ip0 = vlib_buffer_get_current (b0);
 
@@ -1344,7 +1295,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
              icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
                                           ICMP4_time_exceeded_ttl_exceeded_in_transit,
                                           0);
-             next0 = NAT44_ED_OUT2IN_NEXT_ICMP_ERROR;
+             next0 = NAT_NEXT_ICMP_ERROR;
              goto trace0;
            }
 
@@ -1365,7 +1316,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if (!sm->forwarding_enabled)
                    {
                      if (!s0)
-                       next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                       next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
                }
@@ -1383,20 +1334,20 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
            {
              if (PREDICT_FALSE (proto0 == ~0))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace0;
                }
 
              if (ip4_is_fragment (ip0))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_REASS;
+                 next0 = NAT_NEXT_OUT2IN_ED_REASS;
                  fragments++;
                  goto trace0;
                }
 
              if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace0;
                }
            }
@@ -1429,7 +1380,6 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                             clib_host_to_net_u16
                                             (UDP_DST_PORT_dhcp_to_client))))
                        {
-                         vnet_feature_next (&next0, b0);
                          goto trace0;
                        }
 
@@ -1437,7 +1387,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                        {
                          b0->error =
                            node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-                         next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                         next0 = NAT_NEXT_DROP;
                        }
                      else
                        {
@@ -1445,7 +1395,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                            udp0->src_port, udp0->dst_port,
                                            thread_index, rx_fib_index0))
                            {
-                             next0 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
+                             next0 = NAT_NEXT_IN2OUT_ED_FAST_PATH;
                              goto trace0;
                            }
                          if (sm->num_workers > 1)
@@ -1464,7 +1414,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  if ((proto0 == SNAT_PROTOCOL_TCP) && !tcp_is_init (tcp0))
                    {
                      b0->error = node->errors[NAT_OUT2IN_ED_ERROR_NON_SYN];
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
 
@@ -1477,13 +1427,13 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
 
                  if (!s0)
                    {
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
                }
              else
                {
-                 next0 = NAT44_ED_OUT2IN_NEXT_SLOW_PATH;
+                 next0 = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
                  goto trace0;
                }
            }
@@ -1505,11 +1455,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                                   src_address);
          ip0->checksum = ip_csum_fold (sum0);
 
+         old_port0 = udp0->dst_port;
+         new_port0 = udp0->dst_port = s0->in2out.port;
+
          if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
            {
-             old_port0 = tcp0->dst_port;
-             new_port0 = tcp0->dst_port = s0->in2out.port;
-
              sum0 = tcp0->checksum;
              sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
                                     dst_address);
@@ -1532,15 +1482,34 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                  (sm, s0, tcp0, thread_index))
                goto trace0;
            }
+         else if (udp0->checksum)
+           {
+             sum0 = udp0->checksum;
+             sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
+                                    dst_address);
+             sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
+                                    length);
+             if (PREDICT_FALSE (is_twice_nat_session (s0)))
+               {
+                 sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
+                                        s0->ext_host_nat_addr.as_u32,
+                                        ip4_header_t, dst_address);
+                 sum0 = ip_csum_update (sum0, udp0->src_port,
+                                        s0->ext_host_nat_port, ip4_header_t,
+                                        length);
+                 udp0->src_port = s0->ext_host_nat_port;
+                 ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
+               }
+             udp0->checksum = ip_csum_fold (sum0);
+             udp_packets++;
+           }
          else
            {
-             udp0->dst_port = s0->in2out.port;
-             if (is_twice_nat_session (s0))
+             if (PREDICT_FALSE (is_twice_nat_session (s0)))
                {
                  udp0->src_port = s0->ext_host_nat_port;
                  ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
                }
-             udp0->checksum = 0;
              udp_packets++;
            }
 
@@ -1565,7 +1534,7 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
                t->session_index = s0 - tsm->sessions;
            }
 
-         pkts_processed += next0 == NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
          /* verify speculative enqueue, maybe switch current next frame */
          vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
                                           to_next, n_left_to_next,
@@ -1593,68 +1562,13 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-VLIB_NODE_FN (nat44_ed_out2in_node) (vlib_main_t * vm,
-                                    vlib_node_runtime_t * node,
-                                    vlib_frame_t * frame)
-{
-  return nat44_ed_out2in_node_fn_inline (vm, node, frame, 0);
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (nat44_ed_out2in_node) = {
-  .name = "nat44-ed-out2in",
-  .vector_size = sizeof (u32),
-  .format_trace = format_nat44_ed_out2in_trace,
-  .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = ARRAY_LEN(nat_out2in_ed_error_strings),
-  .error_strings = nat_out2in_ed_error_strings,
-  .runtime_data_bytes = sizeof (snat_runtime_t),
-  .n_next_nodes = NAT44_ED_OUT2IN_N_NEXT,
-  .next_nodes = {
-    [NAT44_ED_OUT2IN_NEXT_DROP] = "error-drop",
-    [NAT44_ED_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
-    [NAT44_ED_OUT2IN_NEXT_SLOW_PATH] = "nat44-ed-out2in-slowpath",
-    [NAT44_ED_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
-    [NAT44_ED_OUT2IN_NEXT_IN2OUT] = "nat44-ed-in2out",
-    [NAT44_ED_OUT2IN_NEXT_REASS] = "nat44-ed-out2in-reass",
-  },
-};
-/* *INDENT-ON* */
-
-VLIB_NODE_FN (nat44_ed_out2in_slowpath_node) (vlib_main_t * vm,
-                                             vlib_node_runtime_t * node,
-                                             vlib_frame_t * frame)
-{
-  return nat44_ed_out2in_node_fn_inline (vm, node, frame, 1);
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (nat44_ed_out2in_slowpath_node) = {
-  .name = "nat44-ed-out2in-slowpath",
-  .vector_size = sizeof (u32),
-  .format_trace = format_nat44_ed_out2in_trace,
-  .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = ARRAY_LEN(nat_out2in_ed_error_strings),
-  .error_strings = nat_out2in_ed_error_strings,
-  .runtime_data_bytes = sizeof (snat_runtime_t),
-  .n_next_nodes = NAT44_ED_OUT2IN_N_NEXT,
-  .next_nodes = {
-    [NAT44_ED_OUT2IN_NEXT_DROP] = "error-drop",
-    [NAT44_ED_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
-    [NAT44_ED_OUT2IN_NEXT_SLOW_PATH] = "nat44-ed-out2in-slowpath",
-    [NAT44_ED_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
-    [NAT44_ED_OUT2IN_NEXT_IN2OUT] = "nat44-ed-in2out",
-    [NAT44_ED_OUT2IN_NEXT_REASS] = "nat44-ed-out2in-reass",
-  },
-};
-/* *INDENT-ON* */
-
-VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
-                                          vlib_node_runtime_t * node,
-                                          vlib_frame_t * frame)
+static inline uword
+nat44_ed_out2in_reass_node_fn_inline (vlib_main_t * vm,
+                                     vlib_node_runtime_t * node,
+                                     vlib_frame_t * frame)
 {
   u32 n_left_from, *from, *to_next;
-  nat44_ed_out2in_next_t next_index;
+  nat_next_t next_index;
   u32 pkts_processed = 0;
   snat_main_t *sm = &snat_main;
   f64 now = vlib_time_now (vm);
@@ -1703,7 +1617,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
          n_left_to_next -= 1;
 
          b0 = vlib_get_buffer (vm, bi0);
-         next0 = NAT44_ED_OUT2IN_NEXT_LOOKUP;
+         next0 = nat_buffer_opaque (b0)->arc_next;
 
          sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
          rx_fib_index0 =
@@ -1712,7 +1626,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
 
          if (PREDICT_FALSE (nat_reass_is_drop_frag (0)))
            {
-             next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+             next0 = NAT_NEXT_DROP;
              b0->error = node->errors[NAT_OUT2IN_ED_ERROR_DROP_FRAGMENT];
              goto trace0;
            }
@@ -1731,7 +1645,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
 
          if (PREDICT_FALSE (!reass0))
            {
-             next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+             next0 = NAT_NEXT_DROP;
              b0->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_REASS];
              nat_elog_notice ("maximum reassemblies exceeded");
              goto trace0;
@@ -1745,7 +1659,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                    (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
                     next0, now, thread_index, &s0);
 
-                 if (PREDICT_TRUE (next0 != NAT44_ED_OUT2IN_NEXT_DROP))
+                 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP))
                    {
                      if (s0)
                        reass0->sess_index = s0 - per_thread_data->sessions;
@@ -1786,7 +1700,6 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                                             clib_host_to_net_u16
                                             (UDP_DST_PORT_dhcp_to_client))))
                        {
-                         vnet_feature_next (&next0, b0);
                          goto trace0;
                        }
 
@@ -1794,7 +1707,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                        {
                          b0->error =
                            node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-                         next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                         next0 = NAT_NEXT_DROP;
                        }
                      else
                        {
@@ -1802,7 +1715,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                                            udp0->src_port, udp0->dst_port,
                                            thread_index, rx_fib_index0))
                            {
-                             next0 = NAT44_ED_OUT2IN_NEXT_IN2OUT;
+                             next0 = NAT_NEXT_IN2OUT_ED_FAST_PATH;
                              goto trace0;
                            }
                          if (sm->num_workers > 1)
@@ -1827,7 +1740,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                  if ((proto0 == SNAT_PROTOCOL_TCP) && !tcp_is_init (tcp0))
                    {
                      b0->error = node->errors[NAT_OUT2IN_ED_ERROR_NON_SYN];
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
 
@@ -1841,7 +1754,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                    {
                      b0->error =
                        node->errors[NAT_OUT2IN_ED_ERROR_NO_TRANSLATION];
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
                  reass0->sess_index = s0 - per_thread_data->sessions;
@@ -1867,7 +1780,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                      b0->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_FRAG];
                      nat_elog_notice
                        ("maximum fragments per reassembly exceeded");
-                     next0 = NAT44_ED_OUT2IN_NEXT_DROP;
+                     next0 = NAT_NEXT_DROP;
                      goto trace0;
                    }
                  cached0 = 1;
@@ -1894,12 +1807,11 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
 
          if (PREDICT_FALSE (ip4_is_first_fragment (ip0)))
            {
+             old_port0 = udp0->dst_port;
+             new_port0 = udp0->dst_port = s0->in2out.port;
+
              if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
                {
-                 old_port0 = tcp0->dst_port;
-                 tcp0->dst_port = s0->in2out.port;
-                 new_port0 = tcp0->dst_port;
-
                  sum0 = tcp0->checksum;
                  sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
                                         ip4_header_t,
@@ -1921,16 +1833,35 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
                    }
                  tcp0->checksum = ip_csum_fold (sum0);
                }
+             else if (udp0->checksum)
+               {
+                 sum0 = udp0->checksum;
+                 sum0 =
+                   ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
+                                   dst_address);
+                 sum0 =
+                   ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
+                                   length);
+                 if (PREDICT_FALSE (is_twice_nat_session (s0)))
+                   {
+                     sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
+                                            s0->ext_host_nat_addr.as_u32,
+                                            ip4_header_t, dst_address);
+                     sum0 = ip_csum_update (sum0, udp0->src_port,
+                                            s0->ext_host_nat_port,
+                                            ip4_header_t, length);
+                     udp0->src_port = s0->ext_host_nat_port;
+                     ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
+                   }
+                 udp0->checksum = ip_csum_fold (sum0);
+               }
              else
                {
-                 old_port0 = udp0->dst_port;
-                 udp0->dst_port = s0->in2out.port;
-                 if (is_twice_nat_session (s0))
+                 if (PREDICT_FALSE (is_twice_nat_session (s0)))
                    {
                      udp0->src_port = s0->ext_host_nat_port;
                      ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
                    }
-                 udp0->checksum = 0;
                }
            }
 
@@ -1959,7 +1890,7 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
            }
          else
            {
-             pkts_processed += next0 != NAT44_ED_OUT2IN_NEXT_DROP;
+             pkts_processed += next0 != NAT_NEXT_DROP;
 
              /* verify speculative enqueue, maybe switch current next frame */
              vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
@@ -1998,33 +1929,100 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
 
   nat_send_all_to_node (vm, fragments_to_drop, node,
                        &node->errors[NAT_OUT2IN_ED_ERROR_DROP_FRAGMENT],
-                       NAT44_ED_OUT2IN_NEXT_DROP);
+                       NAT_NEXT_DROP);
 
   vec_free (fragments_to_drop);
   vec_free (fragments_to_loopback);
   return frame->n_vectors;
 }
 
+VLIB_NODE_FN (nat44_ed_out2in_node) (vlib_main_t * vm,
+                                    vlib_node_runtime_t * node,
+                                    vlib_frame_t * frame)
+{
+  return nat44_ed_out2in_node_fn_inline (vm, node, frame, 0);
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (nat44_ed_out2in_node) = {
+  .name = "nat44-ed-out2in",
+  .vector_size = sizeof (u32),
+  .sibling_of = "nat-default",
+  .format_trace = format_nat44_ed_out2in_trace,
+  .type = VLIB_NODE_TYPE_INTERNAL,
+  .n_errors = ARRAY_LEN(nat_out2in_ed_error_strings),
+  .error_strings = nat_out2in_ed_error_strings,
+  .runtime_data_bytes = sizeof (snat_runtime_t),
+};
+/* *INDENT-ON* */
+
+VLIB_NODE_FN (nat44_ed_out2in_slowpath_node) (vlib_main_t * vm,
+                                             vlib_node_runtime_t * node,
+                                             vlib_frame_t * frame)
+{
+  return nat44_ed_out2in_node_fn_inline (vm, node, frame, 1);
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (nat44_ed_out2in_slowpath_node) = {
+  .name = "nat44-ed-out2in-slowpath",
+  .vector_size = sizeof (u32),
+  .sibling_of = "nat-default",
+  .format_trace = format_nat44_ed_out2in_trace,
+  .type = VLIB_NODE_TYPE_INTERNAL,
+  .n_errors = ARRAY_LEN(nat_out2in_ed_error_strings),
+  .error_strings = nat_out2in_ed_error_strings,
+  .runtime_data_bytes = sizeof (snat_runtime_t),
+};
+/* *INDENT-ON* */
+
+VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
+                                          vlib_node_runtime_t * node,
+                                          vlib_frame_t * frame)
+{
+  return nat44_ed_out2in_reass_node_fn_inline (vm, node, frame);
+}
+
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (nat44_ed_out2in_reass_node) = {
   .name = "nat44-ed-out2in-reass",
   .vector_size = sizeof (u32),
+  .sibling_of = "nat-default",
   .format_trace = format_nat44_reass_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
   .n_errors = ARRAY_LEN(nat_out2in_ed_error_strings),
   .error_strings = nat_out2in_ed_error_strings,
-  .n_next_nodes = NAT44_ED_OUT2IN_N_NEXT,
-  .next_nodes = {
-    [NAT44_ED_OUT2IN_NEXT_DROP] = "error-drop",
-    [NAT44_ED_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
-    [NAT44_ED_OUT2IN_NEXT_SLOW_PATH] = "nat44-ed-out2in-slowpath",
-    [NAT44_ED_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
-    [NAT44_ED_OUT2IN_NEXT_IN2OUT] = "nat44-ed-in2out",
-    [NAT44_ED_OUT2IN_NEXT_REASS] = "nat44-ed-out2in-reass",
-  },
 };
 /* *INDENT-ON* */
 
+static u8 *
+format_nat_pre_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
+  return format (s, "out2in next_index %d", t->next_index);
+}
+
+VLIB_NODE_FN (nat_pre_out2in_node) (vlib_main_t * vm,
+                                   vlib_node_runtime_t * node,
+                                   vlib_frame_t * frame)
+{
+  return nat_pre_node_fn_inline (vm, node, frame,
+                                NAT_NEXT_OUT2IN_ED_FAST_PATH);
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (nat_pre_out2in_node) = {
+  .name = "nat-pre-out2in",
+  .vector_size = sizeof (u32),
+  .sibling_of = "nat-default",
+  .format_trace = format_nat_pre_trace,
+  .type = VLIB_NODE_TYPE_INTERNAL,
+  .n_errors = 0,
+ };
+/* *INDENT-ON* */
+
 /*
  * fd.io coding-style-patch-verification: ON
  *