api: clean up use of deprecated flag
[vpp.git] / src / plugins / nat / nat64_in2out.c
index 8d4b1a8..1928bf8 100644 (file)
@@ -21,6 +21,7 @@
 #include <nat/nat_inlines.h>
 #include <vnet/ip/ip6_to_ip4.h>
 #include <vnet/fib/fib_table.h>
+#include <nat/lib/nat_inlines.h>
 
 typedef struct
 {
@@ -48,17 +49,8 @@ format_nat64_in2out_trace (u8 * s, va_list * args)
 
 #define foreach_nat64_in2out_error                       \
 _(UNSUPPORTED_PROTOCOL, "unsupported protocol")          \
-_(IN2OUT_PACKETS, "good in2out packets processed")       \
 _(NO_TRANSLATION, "no translation")                      \
-_(UNKNOWN, "unknown")                                    \
-_(DROP_FRAGMENT, "drop fragment")                        \
-_(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")
+_(UNKNOWN, "unknown")
 
 
 typedef enum
@@ -224,7 +216,7 @@ nat64_in2out_tcp_udp (vlib_main_t * vm, vlib_buffer_t * p, u16 l4_offset,
          u16 out_port;
          ip4_address_t out_addr;
          if (nat64_alloc_out_addr_and_port
-             (fib_index, ip_proto_to_snat_proto (proto), &out_addr,
+             (fib_index, ip_proto_to_nat_proto (proto), &out_addr,
               &out_port, ctx->thread_index))
            return -1;
 
@@ -276,7 +268,7 @@ nat64_in2out_tcp_udp (vlib_main_t * vm, vlib_buffer_t * p, u16 l4_offset,
          csum = ip_csum_add_even (csum, ip4->src_address.as_u32);
          csum = ip_csum_sub_even (csum, sport);
          csum = ip_csum_add_even (csum, udp->src_port);
-         mss_clamping (nm->sm, tcp, &csum);
+         mss_clamping (nm->sm->mss_clamping, tcp, &csum);
          tcp->checksum = ip_csum_fold (csum);
 
          nat64_tcp_session_set_state (ste, tcp, 1);
@@ -335,7 +327,7 @@ nat64_in2out_icmp_set_cb (ip6_header_t * ip6, ip4_header_t * ip4, void *arg)
              u16 out_id;
              ip4_address_t out_addr;
              if (nat64_alloc_out_addr_and_port
-                 (fib_index, SNAT_PROTOCOL_ICMP, &out_addr, &out_id,
+                 (fib_index, NAT_PROTOCOL_ICMP, &out_addr, &out_id,
                   ctx->thread_index))
                return -1;
 
@@ -715,7 +707,7 @@ nat64_in2out_tcp_udp_hairpinning (vlib_main_t * vm, vlib_buffer_t * b,
          u16 out_port;
          ip4_address_t out_addr;
          if (nat64_alloc_out_addr_and_port
-             (fib_index, ip_proto_to_snat_proto (proto), &out_addr,
+             (fib_index, ip_proto_to_nat_proto (proto), &out_addr,
               &out_port, thread_index))
            return -1;
 
@@ -1044,17 +1036,9 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 {
   u32 n_left_from, *from, *to_next;
   nat64_in2out_next_t next_index;
-  u32 pkts_processed = 0;
-  u32 stats_node_index;
   u32 thread_index = vm->thread_index;
   nat64_main_t *nm = &nat64_main;
 
-  u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
-    0, fragments = 0;
-
-  stats_node_index =
-    is_slow_path ? nm->in2out_slowpath_node_index : nm->in2out_node_index;
-
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
   next_index = node->cached_next_index;
@@ -1088,6 +1072,8 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          b0 = vlib_get_buffer (vm, bi0);
          ip60 = vlib_buffer_get_current (b0);
 
+         sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+
          ctx0.b = b0;
          ctx0.vm = vm;
          ctx0.thread_index = thread_index;
@@ -1104,21 +1090,21 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              goto trace0;
            }
 
-         sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
-
          if (nat64_not_translate (sw_if_index0, ip60->dst_address))
            {
              next0 = NAT64_IN2OUT_NEXT_IP6_LOOKUP;
              goto trace0;
            }
 
-         proto0 = ip_proto_to_snat_proto (l4_protocol0);
+         proto0 = ip_proto_to_nat_proto (l4_protocol0);
 
          if (is_slow_path)
            {
-             if (PREDICT_TRUE (proto0 == ~0))
+             if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_OTHER))
                {
-                 other_packets++;
+                 vlib_increment_simple_counter (&nm->counters.in2out.other,
+                                                thread_index, sw_if_index0,
+                                                1);
                  if (is_hairpinning (&ip60->dst_address))
                    {
                      next0 = NAT64_IN2OUT_NEXT_IP6_LOOKUP;
@@ -1146,16 +1132,17 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            }
          else
            {
-             if (PREDICT_FALSE (proto0 == ~0))
+             if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
                {
                  next0 = NAT64_IN2OUT_NEXT_SLOWPATH;
                  goto trace0;
                }
            }
 
-         if (proto0 == SNAT_PROTOCOL_ICMP)
+         if (proto0 == NAT_PROTOCOL_ICMP)
            {
-             icmp_packets++;
+             vlib_increment_simple_counter (&nm->counters.in2out.icmp,
+                                            thread_index, sw_if_index0, 1);
              if (is_hairpinning (&ip60->dst_address))
                {
                  next0 = NAT64_IN2OUT_NEXT_IP6_LOOKUP;
@@ -1178,12 +1165,14 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                  goto trace0;
                }
            }
-         else if (proto0 == SNAT_PROTOCOL_TCP || proto0 == SNAT_PROTOCOL_UDP)
+         else if (proto0 == NAT_PROTOCOL_TCP || proto0 == NAT_PROTOCOL_UDP)
            {
-             if (proto0 == SNAT_PROTOCOL_TCP)
-               tcp_packets++;
+             if (proto0 == NAT_PROTOCOL_TCP)
+               vlib_increment_simple_counter (&nm->counters.in2out.tcp,
+                                              thread_index, sw_if_index0, 1);
              else
-               udp_packets++;
+               vlib_increment_simple_counter (&nm->counters.in2out.udp,
+                                              thread_index, sw_if_index0, 1);
 
              if (is_hairpinning (&ip60->dst_address))
                {
@@ -1218,7 +1207,12 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              t->is_slow_path = is_slow_path;
            }
 
-         pkts_processed += next0 == NAT64_IN2OUT_NEXT_IP4_LOOKUP;
+         if (next0 == NAT64_IN2OUT_NEXT_DROP)
+           {
+             vlib_increment_simple_counter (&nm->counters.in2out.drops,
+                                            thread_index, sw_if_index0, 1);
+           }
+
 
          /* verify speculative enqueue, maybe switch current next frame */
          vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
@@ -1226,20 +1220,6 @@ nat64_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
        }
       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
     }
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_IN2OUT_PACKETS,
-                              pkts_processed);
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_TCP_PACKETS, tcp_packets);
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_UDP_PACKETS, udp_packets);
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_ICMP_PACKETS, icmp_packets);
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_OTHER_PACKETS,
-                              other_packets);
-  vlib_node_increment_counter (vm, stats_node_index,
-                              NAT64_IN2OUT_ERROR_FRAGMENTS, fragments);
 
   return frame->n_vectors;
 }