aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44_handoff.c
diff options
context:
space:
mode:
authorFilip Varga <fivarga@cisco.com>2019-08-12 14:24:39 +0200
committerOle Trøan <otroan@employees.org>2019-08-22 14:13:42 +0000
commit22bb417e91c7bdf639b24b5edd321028f56ea04a (patch)
tree036c33c359752ca5eeabf0f612335d1a2489dfef /src/plugins/nat/nat44_handoff.c
parent95e091b268212c4bc7153d1526fdffd3ce1d647a (diff)
nat: handoff traffic matching for dynamic NAT
Type: feature Change-Id: I5c5af6f9acb340cc674323305104b8ce23e6d21d Signed-off-by: Filip Varga <fivarga@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat44_handoff.c')
-rw-r--r--src/plugins/nat/nat44_handoff.c88
1 files changed, 49 insertions, 39 deletions
diff --git a/src/plugins/nat/nat44_handoff.c b/src/plugins/nat/nat44_handoff.c
index 04590e409ac..c97c958d2a9 100644
--- a/src/plugins/nat/nat44_handoff.c
+++ b/src/plugins/nat/nat44_handoff.c
@@ -29,6 +29,7 @@ typedef struct
u32 next_worker_index;
u32 trace_index;
u8 in2out;
+ u8 output;
} nat44_handoff_trace_t;
#define foreach_nat44_handoff_error \
@@ -57,12 +58,13 @@ format_nat44_handoff_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 *);
nat44_handoff_trace_t *t = va_arg (*args, nat44_handoff_trace_t *);
- char *tag;
+ char *tag, *output;
tag = t->in2out ? "IN2OUT" : "OUT2IN";
+ output = t->output ? "OUTPUT-FEATURE" : "";
s =
- format (s, "NAT44_%s_WORKER_HANDOFF: next-worker %d trace index %d", tag,
- t->next_worker_index, t->trace_index);
+ format (s, "NAT44_%s_WORKER_HANDOFF %s: next-worker %d trace index %d",
+ tag, output, t->next_worker_index, t->trace_index);
return s;
}
@@ -101,8 +103,8 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
while (n_left_from >= 4)
{
u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
- u32 rx_fib_index0 = 0, rx_fib_index1 = 0,
- rx_fib_index2 = 0, rx_fib_index3 = 0;
+ 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;
ip4_header_t *ip0, *ip1, *ip2, *ip3;
if (PREDICT_TRUE (n_left_from >= 8))
@@ -117,32 +119,37 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
CLIB_PREFETCH (&b[7]->data, CLIB_CACHE_LINE_BYTES, STORE);
}
- ip0 = vlib_buffer_get_current (b[0]);
- ip1 = vlib_buffer_get_current (b[1]);
- ip2 = vlib_buffer_get_current (b[2]);
- ip3 = vlib_buffer_get_current (b[3]);
-
- if (PREDICT_FALSE (is_in2out))
+ if (is_output)
{
- 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];
- sw_if_index3 = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
-
- rx_fib_index0 =
- ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
- rx_fib_index1 =
- ip4_fib_table_get_index_for_sw_if_index (sw_if_index1);
- 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);
+ iph_offset0 = vnet_buffer (b[0])->ip.save_rewrite_length;
+ iph_offset1 = vnet_buffer (b[1])->ip.save_rewrite_length;
+ iph_offset2 = vnet_buffer (b[2])->ip.save_rewrite_length;
+ iph_offset3 = vnet_buffer (b[3])->ip.save_rewrite_length;
}
- ti[0] = get_worker (ip0, rx_fib_index0);
- ti[1] = get_worker (ip1, rx_fib_index1);
- ti[2] = get_worker (ip2, rx_fib_index2);
- ti[3] = get_worker (ip3, rx_fib_index3);
+ ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[0]) +
+ iph_offset0);
+ ip1 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[1]) +
+ iph_offset1);
+ ip2 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[2]) +
+ iph_offset2);
+ ip3 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[3]) +
+ iph_offset3);
+
+ 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];
+ sw_if_index3 = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
+
+ rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
+ rx_fib_index1 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index1);
+ 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 (ti[0] == thread_index)
same_worker++;
@@ -172,19 +179,21 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
while (n_left_from > 0)
{
u32 sw_if_index0;
- u32 rx_fib_index0 = 0;
+ u32 rx_fib_index0;
+ u32 iph_offset0 = 0;
ip4_header_t *ip0;
- ip0 = vlib_buffer_get_current (b[0]);
- if (PREDICT_FALSE (is_in2out))
- {
- 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);
- }
+ if (is_output)
+ iph_offset0 = vnet_buffer (b[0])->ip.save_rewrite_length;
+
+ ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b[0]) +
+ iph_offset0);
+
+ 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);
+ ti[0] = get_worker (ip0, rx_fib_index0, is_output);
if (ti[0] == thread_index)
same_worker++;
@@ -211,9 +220,10 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
t->next_worker_index = ti[0];
t->trace_index = vlib_buffer_get_trace_index (b[0]);
t->in2out = is_in2out;
+ t->output = is_output;
- b++;
- ti++;
+ b += 1;
+ ti += 1;
}
else
break;