nat: optimize prefetching
[vpp.git] / src / plugins / nat / nat_det_in2out.c
index cf50805..74b4149 100644 (file)
@@ -26,6 +26,7 @@
 #include <nat/nat.h>
 #include <nat/nat_det.h>
 #include <nat/nat_inlines.h>
+#include <nat/lib/nat_inlines.h>
 
 typedef struct
 {
@@ -95,17 +96,17 @@ format_nat_det_in2out_trace (u8 * s, va_list * args)
 u32
 icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
                       u32 thread_index, vlib_buffer_t * b0,
-                      ip4_header_t * ip0, u8 * p_proto,
-                      snat_session_key_t * p_value, u8 * p_dont_translate,
-                      void *d, void *e)
+                      ip4_header_t * ip0, ip4_address_t * addr,
+                      u16 * port, u32 * fib_index,
+                      nat_protocol_t * proto, void *d, void *e,
+                      u8 * dont_translate)
 {
   vlib_main_t *vm = vlib_get_main ();
   icmp46_header_t *icmp0;
   u32 sw_if_index0;
   u32 rx_fib_index0;
-  u8 protocol;
+  nat_protocol_t protocol;
   snat_det_out_key_t key0;
-  u8 dont_translate = 0;
   u32 next0 = ~0;
   icmp_echo_header_t *echo0, *inner_echo0 = 0;
   ip4_header_t *inner_ip0;
@@ -117,6 +118,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
   snat_det_session_t *ses0 = 0;
   ip4_address_t in_addr;
   u16 in_port;
+  *dont_translate = 0;
 
   icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
   echo0 = (icmp_echo_header_t *) (icmp0 + 1);
@@ -164,7 +166,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
                                                  IP_PROTOCOL_ICMP,
                                                  rx_fib_index0)))
        {
-         dont_translate = 1;
+         *dont_translate = 1;
          goto out;
        }
       next0 = NAT_DET_IN2OUT_NEXT_DROP;
@@ -184,7 +186,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
                                                  IP_PROTOCOL_ICMP,
                                                  rx_fib_index0)))
        {
-         dont_translate = 1;
+         *dont_translate = 1;
          goto out;
        }
       if (icmp0->type != ICMP4_echo_request)
@@ -233,14 +235,13 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
   ses0->expire = now + sm->icmp_timeout;
 
 out:
-  *p_proto = protocol;
+  *proto = protocol;
   if (ses0)
     {
-      p_value->addr = new_addr0;
-      p_value->fib_index = sm->outside_fib_index;
-      p_value->port = ses0->out.out_port;
+      *addr = new_addr0;
+      *fib_index = sm->outside_fib_index;
+      *port = ses0->out.out_port;
     }
-  *p_dont_translate = dont_translate;
   if (d)
     *(snat_det_session_t **) d = ses0;
   if (e)
@@ -300,8 +301,8 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
            vlib_prefetch_buffer_header (p2, LOAD);
            vlib_prefetch_buffer_header (p3, LOAD);
 
-           CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
-           CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
+           CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
+           CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, LOAD);
          }
 
          /* speculatively enqueue b0 and b1 to the current next frame */
@@ -438,7 +439,7 @@ VLIB_NODE_FN (snat_det_in2out_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
@@ -611,7 +612,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (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);
            }
          else
@@ -820,7 +821,7 @@ VLIB_NODE_FN (snat_det_in2out_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