nat: Final NAT44 EI/ED split patch
[vpp.git] / src / plugins / nat / nat44-ed / nat44_ed_out2in.c
similarity index 94%
rename from src/plugins/nat/out2in_ed.c
rename to src/plugins/nat/nat44-ed/nat44_ed_out2in.c
index d6beadc..4d354d3 100644 (file)
 #include <vnet/fib/ip4_fib.h>
 #include <vnet/udp/udp_local.h>
 #include <vppinfra/error.h>
-#include <nat/nat.h>
-#include <nat/lib/ipfix_logging.h>
-#include <nat/nat_inlines.h>
-#include <nat/nat44/inlines.h>
+
 #include <nat/lib/nat_syslog.h>
-#include <nat/nat44/ed_inlines.h>
+#include <nat/lib/ipfix_logging.h>
+
+#include <nat/nat44-ed/nat44_ed.h>
+#include <nat/nat44-ed/nat44_ed_inlines.h>
 
 static char *nat_out2in_ed_error_strings[] = {
 #define _(sym,string) string,
@@ -243,6 +243,7 @@ nat_alloc_addr_and_port_exact (snat_address_t * a,
                               u16 * port,
                               u16 port_per_thread, u32 snat_thread_index)
 {
+  snat_main_t *sm = &snat_main;
   u32 portnum;
 
   switch (proto)
@@ -269,8 +270,7 @@ nat_alloc_addr_and_port_exact (snat_address_t * a,
       break;
       foreach_nat_protocol
 #undef _
-    default:
-      nat_elog_info ("unknown protocol");
+       default : nat_elog_info (sm, "unknown protocol");
       return 1;
     }
 
@@ -286,9 +286,10 @@ nat44_ed_alloc_outside_addr_and_port (snat_address_t *addresses, u32 fib_index,
                                      u16 port_per_thread,
                                      u32 snat_thread_index)
 {
-  int i;
+  snat_main_t *sm = &snat_main;
   snat_address_t *a, *ga = 0;
   u32 portnum;
+  int i;
 
   for (i = 0; i < vec_len (addresses); i++)
     {
@@ -323,7 +324,7 @@ nat44_ed_alloc_outside_addr_and_port (snat_address_t *addresses, u32 fib_index,
     break;
          foreach_nat_protocol
 #undef _
-           default : nat_elog_info ("unknown protocol");
+           default : nat_elog_info (sm, "unknown protocol");
          return 1;
        }
     }
@@ -351,7 +352,7 @@ nat44_ed_alloc_outside_addr_and_port (snat_address_t *addresses, u32 fib_index,
          break;
          foreach_nat_protocol
 #undef _
-           default : nat_elog_info ("unknown protocol");
+           default : nat_elog_info (sm, "unknown protocol");
          return 1;
        }
     }
@@ -378,15 +379,15 @@ create_session_for_static_mapping_ed (
       (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
     {
       b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_SESSIONS_EXCEEDED];
-      nat_elog_notice ("maximum sessions exceeded");
+      nat_elog_notice (sm, "maximum sessions exceeded");
       return 0;
     }
 
   s = nat_ed_session_alloc (sm, thread_index, now, nat_proto);
   if (!s)
     {
-      b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_USER_SESS_EXCEEDED];
-      nat_elog_warn ("create NAT session failed");
+      b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_SESSIONS_EXCEEDED];
+      nat_elog_warn (sm, "create NAT session failed");
       return 0;
     }
 
@@ -429,7 +430,7 @@ create_session_for_static_mapping_ed (
     {
       b->error = node->errors[NAT_OUT2IN_ED_ERROR_HASH_ADD_FAILED];
       nat_ed_session_delete (sm, s, thread_index, 1);
-      nat_elog_warn ("out2in flow hash add failed");
+      nat_elog_warn (sm, "out2in flow hash add failed");
       return 0;
     }
 
@@ -477,7 +478,7 @@ create_session_for_static_mapping_ed (
          b->error = node->errors[NAT_OUT2IN_ED_ERROR_OUT_OF_PORTS];
          if (nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 0))
            {
-             nat_elog_warn ("out2in flow hash del failed");
+             nat_elog_warn (sm, "out2in flow hash del failed");
            }
          snat_free_outside_address_and_port (
            sm->twice_nat_addresses, thread_index, &s->ext_host_nat_addr,
@@ -541,10 +542,10 @@ create_session_for_static_mapping_ed (
 
   if (nat_ed_ses_i2o_flow_hash_add_del (sm, thread_index, s, 1))
     {
-      nat_elog_notice ("in2out flow hash add failed");
+      nat_elog_notice (sm, "in2out flow hash add failed");
       if (nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 0))
        {
-         nat_elog_warn ("out2in flow hash del failed");
+         nat_elog_warn (sm, "out2in flow hash del failed");
        }
       nat_ed_session_delete (sm, s, thread_index, 1);
       return 0;
@@ -557,12 +558,11 @@ create_session_for_static_mapping_ed (
                                      s->in2out.port,
                                      s->out2in.port, s->in2out.fib_index);
 
-  nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
-                        &s->in2out.addr, s->in2out.port,
-                        &s->ext_host_nat_addr, s->ext_host_nat_port,
-                        &s->out2in.addr, s->out2in.port,
-                        &s->ext_host_addr, s->ext_host_port,
-                        s->nat_proto, is_twice_nat_session (s));
+  nat_syslog_nat44_sadd (0, s->in2out.fib_index, &s->in2out.addr,
+                        s->in2out.port, &s->ext_host_nat_addr,
+                        s->ext_host_nat_port, &s->out2in.addr, s->out2in.port,
+                        &s->ext_host_addr, s->ext_host_port, s->nat_proto,
+                        is_twice_nat_session (s));
 
   per_vrf_sessions_register_session (s, thread_index);
 
@@ -635,7 +635,7 @@ create_bypass_for_fwd (snat_main_t *sm, vlib_buffer_t *b, snat_session_t *s,
       s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
       if (!s)
        {
-         nat_elog_warn ("create NAT session failed");
+         nat_elog_warn (sm, "create NAT session failed");
          return;
        }
 
@@ -663,7 +663,7 @@ create_bypass_for_fwd (snat_main_t *sm, vlib_buffer_t *b, snat_session_t *s,
       nat_6t_flow_txfib_rewrite_set (&s->i2o, rx_fib_index);
       if (nat_ed_ses_i2o_flow_hash_add_del (sm, thread_index, s, 1))
        {
-         nat_elog_notice ("in2out flow add failed");
+         nat_elog_notice (sm, "in2out flow add failed");
          nat_ed_session_delete (sm, s, thread_index, 1);
          return;
        }
@@ -700,7 +700,7 @@ nat44_ed_out2in_slowpath_unknown_proto (snat_main_t *sm, vlib_buffer_t *b,
        nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
     {
       b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_SESSIONS_EXCEEDED];
-      nat_elog_notice ("maximum sessions exceeded");
+      nat_elog_notice (sm, "maximum sessions exceeded");
       return 0;
     }
 
@@ -717,8 +717,8 @@ nat44_ed_out2in_slowpath_unknown_proto (snat_main_t *sm, vlib_buffer_t *b,
   s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
   if (!s)
     {
-      b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_USER_SESS_EXCEEDED];
-      nat_elog_warn ("create NAT session failed");
+      b->error = node->errors[NAT_OUT2IN_ED_ERROR_MAX_SESSIONS_EXCEEDED];
+      nat_elog_warn (sm, "create NAT session failed");
       return 0;
     }
 
@@ -737,7 +737,7 @@ nat44_ed_out2in_slowpath_unknown_proto (snat_main_t *sm, vlib_buffer_t *b,
   nat_6t_flow_saddr_rewrite_set (&s->i2o, ip->dst_address.as_u32);
   if (nat_ed_ses_i2o_flow_hash_add_del (sm, thread_index, s, 1))
     {
-      nat_elog_notice ("in2out key add failed");
+      nat_elog_notice (sm, "in2out key add failed");
       nat_ed_session_delete (sm, s, thread_index, 1);
       return NULL;
     }
@@ -748,7 +748,7 @@ nat44_ed_out2in_slowpath_unknown_proto (snat_main_t *sm, vlib_buffer_t *b,
   nat_6t_flow_txfib_rewrite_set (&s->o2i, m->fib_index);
   if (nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 1))
     {
-      nat_elog_notice ("out2in flow hash add failed");
+      nat_elog_notice (sm, "out2in flow hash add failed");
       nat_ed_session_delete (sm, s, thread_index, 1);
       return NULL;
     }
@@ -1010,7 +1010,7 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
       switch (proto0)
        {
        case NAT_PROTOCOL_TCP:
-         vlib_increment_simple_counter (&sm->counters.fastpath.out2in_ed.tcp,
+         vlib_increment_simple_counter (&sm->counters.fastpath.out2in.tcp,
                                         thread_index, sw_if_index0, 1);
          nat44_set_tcp_session_state_o2i (sm, now, s0,
                                           vnet_buffer (b0)->ip.
@@ -1022,17 +1022,16 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
                                           thread_index);
          break;
        case NAT_PROTOCOL_UDP:
-         vlib_increment_simple_counter (&sm->counters.fastpath.out2in_ed.udp,
+         vlib_increment_simple_counter (&sm->counters.fastpath.out2in.udp,
                                         thread_index, sw_if_index0, 1);
          break;
        case NAT_PROTOCOL_ICMP:
-         vlib_increment_simple_counter (&sm->counters.fastpath.out2in_ed.icmp,
+         vlib_increment_simple_counter (&sm->counters.fastpath.out2in.icmp,
                                         thread_index, sw_if_index0, 1);
          break;
        case NAT_PROTOCOL_OTHER:
-         vlib_increment_simple_counter (
-           &sm->counters.fastpath.out2in_ed.other, thread_index, sw_if_index0,
-           1);
+         vlib_increment_simple_counter (&sm->counters.fastpath.out2in.other,
+                                        thread_index, sw_if_index0, 1);
          break;
        }
 
@@ -1071,9 +1070,8 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm,
 
       if (next[0] == NAT_NEXT_DROP)
        {
-         vlib_increment_simple_counter (&sm->counters.fastpath.
-                                        out2in_ed.drops, thread_index,
-                                        sw_if_index0, 1);
+         vlib_increment_simple_counter (&sm->counters.fastpath.out2in.drops,
+                                        thread_index, sw_if_index0, 1);
        }
 
       n_left_from--;
@@ -1163,9 +1161,8 @@ nat44_ed_out2in_slow_path_node_fn_inline (vlib_main_t * vm,
              goto trace0;
            }
 
-         vlib_increment_simple_counter (&sm->counters.slowpath.
-                                        out2in_ed.other, thread_index,
-                                        sw_if_index0, 1);
+         vlib_increment_simple_counter (&sm->counters.slowpath.out2in.other,
+                                        thread_index, sw_if_index0, 1);
          goto trace0;
        }
 
@@ -1183,9 +1180,8 @@ nat44_ed_out2in_slow_path_node_fn_inline (vlib_main_t * vm,
              goto trace0;
            }
 
-         vlib_increment_simple_counter (&sm->counters.slowpath.
-                                        out2in_ed.icmp, thread_index,
-                                        sw_if_index0, 1);
+         vlib_increment_simple_counter (&sm->counters.slowpath.out2in.icmp,
+                                        thread_index, sw_if_index0, 1);
          goto trace0;
        }
 
@@ -1297,7 +1293,7 @@ nat44_ed_out2in_slow_path_node_fn_inline (vlib_main_t * vm,
 
       if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
        {
-         vlib_increment_simple_counter (&sm->counters.slowpath.out2in_ed.tcp,
+         vlib_increment_simple_counter (&sm->counters.slowpath.out2in.tcp,
                                         thread_index, sw_if_index0, 1);
          nat44_set_tcp_session_state_o2i (sm, now, s0,
                                           vnet_buffer (b0)->ip.
@@ -1310,7 +1306,7 @@ nat44_ed_out2in_slow_path_node_fn_inline (vlib_main_t * vm,
        }
       else
        {
-         vlib_increment_simple_counter (&sm->counters.slowpath.out2in_ed.udp,
+         vlib_increment_simple_counter (&sm->counters.slowpath.out2in.udp,
                                         thread_index, sw_if_index0, 1);
        }
 
@@ -1347,9 +1343,8 @@ nat44_ed_out2in_slow_path_node_fn_inline (vlib_main_t * vm,
 
       if (next[0] == NAT_NEXT_DROP)
        {
-         vlib_increment_simple_counter (&sm->counters.slowpath.
-                                        out2in_ed.drops, thread_index,
-                                        sw_if_index0, 1);
+         vlib_increment_simple_counter (&sm->counters.slowpath.out2in.drops,
+                                        thread_index, sw_if_index0, 1);
        }
 
       n_left_from--;