summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_inlines.h
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/nat_inlines.h
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/nat_inlines.h')
-rw-r--r--src/plugins/nat/nat_inlines.h48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/plugins/nat/nat_inlines.h b/src/plugins/nat/nat_inlines.h
index d37cb10b6fd..121d2c71aaa 100644
--- a/src/plugins/nat/nat_inlines.h
+++ b/src/plugins/nat/nat_inlines.h
@@ -445,13 +445,39 @@ nat44_session_update_lru (snat_main_t * sm, snat_session_t * s,
always_inline void
make_ed_kv (ip4_address_t * l_addr, ip4_address_t * r_addr, u8 proto,
- u32 fib_index, u16 l_port, u16 r_port, u64 value,
- clib_bihash_kv_16_8_t * kv)
+ u32 fib_index, u16 l_port, u16 r_port, u32 thread_index,
+ u32 session_index, clib_bihash_kv_16_8_t * kv)
{
kv->key[0] = (u64) r_addr->as_u32 << 32 | l_addr->as_u32;
kv->key[1] =
(u64) r_port << 48 | (u64) l_port << 32 | fib_index << 8 | proto;
- kv->value = value;
+ kv->value = (u64) thread_index << 32 | session_index;
+}
+
+always_inline u32
+ed_value_get_thread_index (clib_bihash_kv_16_8_t * value)
+{
+ return value->value >> 32;
+}
+
+always_inline u32
+ed_value_get_session_index (clib_bihash_kv_16_8_t * value)
+{
+ return value->value & ~(u32) 0;
+}
+
+always_inline void
+split_ed_value (clib_bihash_kv_16_8_t * value, u32 * thread_index,
+ u32 * session_index)
+{
+ if (thread_index)
+ {
+ *thread_index = ed_value_get_thread_index (value);
+ }
+ if (session_index)
+ {
+ *session_index = ed_value_get_session_index (value);
+ }
}
always_inline void
@@ -497,8 +523,8 @@ make_sm_kv (clib_bihash_kv_8_8_t * kv, ip4_address_t * addr, u8 proto,
static_always_inline int
get_icmp_i2o_ed_key (vlib_buffer_t * b, ip4_header_t * ip0, u32 rx_fib_index,
- u64 value, u8 * nat_proto, u16 * l_port, u16 * r_port,
- clib_bihash_kv_16_8_t * kv)
+ u32 thread_index, u32 session_index, u8 * nat_proto,
+ u16 * l_port, u16 * r_port, clib_bihash_kv_16_8_t * kv)
{
u8 proto;
u16 _l_port, _r_port;
@@ -546,8 +572,8 @@ get_icmp_i2o_ed_key (vlib_buffer_t * b, ip4_header_t * ip0, u32 rx_fib_index,
return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
}
}
- make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port, value,
- kv);
+ make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port,
+ thread_index, session_index, kv);
if (nat_proto)
{
*nat_proto = ip_proto_to_nat_proto (proto);
@@ -566,8 +592,8 @@ get_icmp_i2o_ed_key (vlib_buffer_t * b, ip4_header_t * ip0, u32 rx_fib_index,
static_always_inline int
get_icmp_o2i_ed_key (vlib_buffer_t * b, ip4_header_t * ip0, u32 rx_fib_index,
- u64 value, u8 * nat_proto, u16 * l_port, u16 * r_port,
- clib_bihash_kv_16_8_t * kv)
+ u32 thread_index, u32 session_index, u8 * nat_proto,
+ u16 * l_port, u16 * r_port, clib_bihash_kv_16_8_t * kv)
{
icmp46_header_t *icmp0;
u8 proto;
@@ -614,8 +640,8 @@ get_icmp_o2i_ed_key (vlib_buffer_t * b, ip4_header_t * ip0, u32 rx_fib_index,
return -1;
}
}
- make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port, value,
- kv);
+ make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port,
+ thread_index, session_index, kv);
if (nat_proto)
{
*nat_proto = ip_proto_to_nat_proto (proto);