summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44_hairpinning.c
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-04-22 12:45:50 +0000
committerOle Trøan <otroan@employees.org>2020-05-14 12:12:45 +0000
commit2a595da121b28784f73e710534522583cac7af40 (patch)
treec43c09673183f6ab4a0cee0b2329458581bfc8ce /src/plugins/nat/nat44_hairpinning.c
parent88120824acc299a0aec17ce4c208dbc8be394779 (diff)
nat: ED: store both thread&session idx in hash
By storing thread and session index in hash table we are able to skip multiple hash lookups in multi-worker scenario, which were used for handoff before. Also, by storing sesion index in vnet_buffer2, we can avoid repeating the lookup after handoff. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I406fb12f4e2dd8f4a5ca5d83d59dbc37e1af9abf
Diffstat (limited to 'src/plugins/nat/nat44_hairpinning.c')
-rw-r--r--src/plugins/nat/nat44_hairpinning.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/plugins/nat/nat44_hairpinning.c b/src/plugins/nat/nat44_hairpinning.c
index d109bb88dea..02cdfb12380 100644
--- a/src/plugins/nat/nat44_hairpinning.c
+++ b/src/plugins/nat/nat44_hairpinning.c
@@ -128,10 +128,10 @@ snat_hairpinning (snat_main_t * sm,
clib_bihash_kv_16_8_t ed_kv, ed_value;
make_ed_kv (&ip0->dst_address, &ip0->src_address,
ip0->protocol, sm->outside_fib_index, udp0->dst_port,
- udp0->src_port, ~0ULL, &ed_kv);
- rv = clib_bihash_search_16_8 (&sm->per_thread_data[ti].out2in_ed,
- &ed_kv, &ed_value);
- si = ed_value.value;
+ udp0->src_port, ~0, ~0, &ed_kv);
+ rv = clib_bihash_search_16_8 (&sm->out2in_ed, &ed_kv, &ed_value);
+ ASSERT (ti == ed_value_get_thread_index (&ed_value));
+ si = ed_value_get_session_index (&ed_value);
}
else
{
@@ -228,12 +228,12 @@ snat_icmp_hairpinning (snat_main_t * sm,
clib_bihash_kv_16_8_t ed_kv, ed_value;
make_ed_kv (&ip0->dst_address, &ip0->src_address,
inner_ip0->protocol, sm->outside_fib_index,
- l4_header->src_port, l4_header->dst_port, ~0ULL,
+ l4_header->src_port, l4_header->dst_port, ~0, ~0,
&ed_kv);
- if (clib_bihash_search_16_8
- (&sm->per_thread_data[ti].out2in_ed, &ed_kv, &ed_value))
+ if (clib_bihash_search_16_8 (&sm->out2in_ed, &ed_kv, &ed_value))
return 1;
- si = ed_value.value;
+ ASSERT (ti == ed_value_get_thread_index (&ed_value));
+ si = ed_value_get_session_index (&ed_value);
}
else
{
@@ -389,18 +389,16 @@ nat44_ed_hairpinning_unknown_proto (snat_main_t * sm,
snat_static_mapping_t *m;
ip_csum_t sum;
snat_session_t *s;
- snat_main_per_thread_data_t *tsm;
if (sm->num_workers > 1)
ti = sm->worker_out2in_cb (b, ip, sm->outside_fib_index, 0);
else
ti = sm->num_workers;
- tsm = &sm->per_thread_data[ti];
old_addr = ip->dst_address.as_u32;
make_ed_kv (&ip->dst_address, &ip->src_address, ip->protocol,
- sm->outside_fib_index, 0, 0, ~0ULL, &s_kv);
- if (clib_bihash_search_16_8 (&tsm->out2in_ed, &s_kv, &s_value))
+ sm->outside_fib_index, 0, 0, ~0, ~0, &s_kv);
+ if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
{
make_sm_kv (&kv, &ip->dst_address, 0, 0, 0);
if (clib_bihash_search_8_8
@@ -414,7 +412,10 @@ nat44_ed_hairpinning_unknown_proto (snat_main_t * sm,
}
else
{
- s = pool_elt_at_index (sm->per_thread_data[ti].sessions, s_value.value);
+ ASSERT (ti == ed_value_get_thread_index (&s_value));
+ s =
+ pool_elt_at_index (sm->per_thread_data[ti].sessions,
+ ed_value_get_session_index (&s_value));
if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
vnet_buffer (b)->sw_if_index[VLIB_TX] = s->in2out.fib_index;
new_addr = ip->dst_address.as_u32 = s->in2out.addr.as_u32;