nat: deal with flows instead of sessions
[vpp.git] / src / plugins / nat / nat44_handoff.c
index 277f2de..8c1b967 100644 (file)
@@ -33,14 +33,14 @@ typedef struct
   u8 output;
 } nat44_handoff_trace_t;
 
-#define foreach_nat44_handoff_error                       \
-_(CONGESTION_DROP, "congestion drop")                     \
-_(SAME_WORKER, "same worker")                             \
-_(DO_HANDOFF, "do handoff")
+#define foreach_nat44_handoff_error                                           \
+  _ (CONGESTION_DROP, "congestion drop")                                      \
+  _ (SAME_WORKER, "same worker")                                              \
+  _ (DO_HANDOFF, "do handoff")
 
 typedef enum
 {
-#define _(sym,str) NAT44_HANDOFF_ERROR_##sym,
+#define _(sym, str) NAT44_HANDOFF_ERROR_##sym,
   foreach_nat44_handoff_error
 #undef _
     NAT44_HANDOFF_N_ERROR,
@@ -52,7 +52,6 @@ static char *nat44_handoff_error_strings[] = {
 #undef _
 };
 
-
 static u8 *
 format_nat44_handoff_trace (u8 * s, va_list * args)
 {
@@ -82,7 +81,6 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
   snat_main_t *sm = &snat_main;
 
-  snat_get_worker_function_t *get_worker;
   u32 fq_index, thread_index = vm->thread_index;
 
   from = vlib_frame_vector_args (frame);
@@ -93,16 +91,15 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
   if (is_in2out)
     {
       fq_index = is_output ? sm->fq_in2out_output_index : sm->fq_in2out_index;
-      get_worker = sm->worker_in2out_cb;
     }
   else
     {
       fq_index = sm->fq_out2in_index;
-      get_worker = sm->worker_out2in_cb;
     }
 
   while (n_left_from >= 4)
     {
+      u32 arc_next0, arc_next1, arc_next2, arc_next3;
       u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
       u32 rx_fib_index0, rx_fib_index1, rx_fib_index2, rx_fib_index3;
       u32 iph_offset0 = 0, iph_offset1 = 0, iph_offset2 = 0, iph_offset3 = 0;
@@ -110,14 +107,14 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
 
       if (PREDICT_TRUE (n_left_from >= 8))
        {
-         vlib_prefetch_buffer_header (b[4], STORE);
-         vlib_prefetch_buffer_header (b[5], STORE);
-         vlib_prefetch_buffer_header (b[6], STORE);
-         vlib_prefetch_buffer_header (b[7], STORE);
-         CLIB_PREFETCH (&b[4]->data, CLIB_CACHE_LINE_BYTES, STORE);
-         CLIB_PREFETCH (&b[5]->data, CLIB_CACHE_LINE_BYTES, STORE);
-         CLIB_PREFETCH (&b[6]->data, CLIB_CACHE_LINE_BYTES, STORE);
-         CLIB_PREFETCH (&b[7]->data, CLIB_CACHE_LINE_BYTES, STORE);
+         vlib_prefetch_buffer_header (b[4], LOAD);
+         vlib_prefetch_buffer_header (b[5], LOAD);
+         vlib_prefetch_buffer_header (b[6], LOAD);
+         vlib_prefetch_buffer_header (b[7], LOAD);
+         CLIB_PREFETCH (&b[4]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+         CLIB_PREFETCH (&b[5]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+         CLIB_PREFETCH (&b[6]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+         CLIB_PREFETCH (&b[7]->data, CLIB_CACHE_LINE_BYTES, LOAD);
        }
 
       if (is_output)
@@ -137,6 +134,16 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
       ip3 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[3]) +
                              iph_offset3);
 
+      vnet_feature_next (&arc_next0, b[0]);
+      vnet_feature_next (&arc_next1, b[1]);
+      vnet_feature_next (&arc_next2, b[2]);
+      vnet_feature_next (&arc_next3, b[3]);
+
+      vnet_buffer2 (b[0])->nat.arc_next = arc_next0;
+      vnet_buffer2 (b[1])->nat.arc_next = arc_next1;
+      vnet_buffer2 (b[2])->nat.arc_next = arc_next2;
+      vnet_buffer2 (b[3])->nat.arc_next = arc_next3;
+
       sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
       sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
       sw_if_index2 = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
@@ -147,10 +154,20 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
       rx_fib_index2 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index2);
       rx_fib_index3 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index3);
 
-      ti[0] = get_worker (ip0, rx_fib_index0, is_output);
-      ti[1] = get_worker (ip1, rx_fib_index1, is_output);
-      ti[2] = get_worker (ip2, rx_fib_index2, is_output);
-      ti[3] = get_worker (ip3, rx_fib_index3, is_output);
+      if (is_in2out)
+       {
+         ti[0] = sm->worker_in2out_cb (ip0, rx_fib_index0, is_output);
+         ti[1] = sm->worker_in2out_cb (ip1, rx_fib_index1, is_output);
+         ti[2] = sm->worker_in2out_cb (ip2, rx_fib_index2, is_output);
+         ti[3] = sm->worker_in2out_cb (ip3, rx_fib_index3, is_output);
+       }
+      else
+       {
+         ti[0] = sm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
+         ti[1] = sm->worker_out2in_cb (b[1], ip1, rx_fib_index1, is_output);
+         ti[2] = sm->worker_out2in_cb (b[2], ip2, rx_fib_index2, is_output);
+         ti[3] = sm->worker_out2in_cb (b[3], ip3, rx_fib_index3, is_output);
+       }
 
       if (ti[0] == thread_index)
        same_worker++;
@@ -179,6 +196,7 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
 
   while (n_left_from > 0)
     {
+      u32 arc_next0;
       u32 sw_if_index0;
       u32 rx_fib_index0;
       u32 iph_offset0 = 0;
@@ -191,10 +209,20 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
       ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[0]) +
                              iph_offset0);
 
+      vnet_feature_next (&arc_next0, b[0]);
+      vnet_buffer2 (b[0])->nat.arc_next = arc_next0;
+
       sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
       rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
 
-      ti[0] = get_worker (ip0, rx_fib_index0, is_output);
+      if (is_in2out)
+       {
+         ti[0] = sm->worker_in2out_cb (ip0, rx_fib_index0, is_output);
+       }
+      else
+       {
+         ti[0] = sm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
+       }
 
       if (ti[0] == thread_index)
        same_worker++;
@@ -248,8 +276,6 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-
-
 VLIB_NODE_FN (snat_in2out_worker_handoff_node) (vlib_main_t * vm,
                                                vlib_node_runtime_t * node,
                                                vlib_frame_t * frame)