diff options
author | Klement Sekera <ksekera@cisco.com> | 2021-01-26 12:18:53 +0100 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2021-02-04 14:35:43 +0000 |
commit | 6b3f1c0a9cf66f82cda1dc6b15982ee910671340 (patch) | |
tree | 5cb27b76f68f82421e0f1aca2a80b818fc220957 /src/plugins/nat/nat_inlines.h | |
parent | 92e9caea3b1bea837b4061a8328361ed166e5eab (diff) |
nat: reduce number of hash tables for EI NAT
Making code more simple and storing thread index along with session
index as a preparation step for fixing thread safety patches.
Type: improvement
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: Ib0c531e9f1f64b1f1ee912d4a83279200638e931
Diffstat (limited to 'src/plugins/nat/nat_inlines.h')
-rw-r--r-- | src/plugins/nat/nat_inlines.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/plugins/nat/nat_inlines.h b/src/plugins/nat/nat_inlines.h index 3408e533f69..d53e2453607 100644 --- a/src/plugins/nat/nat_inlines.h +++ b/src/plugins/nat/nat_inlines.h @@ -63,11 +63,12 @@ init_nat_k (clib_bihash_kv_8_8_t * kv, ip4_address_t addr, u16 port, } always_inline void -init_nat_kv (clib_bihash_kv_8_8_t * kv, ip4_address_t addr, u16 port, - u32 fib_index, nat_protocol_t proto, u64 value) +init_nat_kv (clib_bihash_kv_8_8_t *kv, ip4_address_t addr, u16 port, + u32 fib_index, nat_protocol_t proto, u32 thread_index, + u32 session_index) { init_nat_k (kv, addr, port, fib_index, proto); - kv->value = value; + kv->value = (u64) thread_index << 32 | session_index; } always_inline void @@ -78,11 +79,12 @@ init_nat_i2o_k (clib_bihash_kv_8_8_t * kv, snat_session_t * s) } always_inline void -init_nat_i2o_kv (clib_bihash_kv_8_8_t * kv, snat_session_t * s, u64 value) +init_nat_i2o_kv (clib_bihash_kv_8_8_t *kv, snat_session_t *s, u32 thread_index, + u32 session_index) { init_nat_k (kv, s->in2out.addr, s->in2out.port, s->in2out.fib_index, s->nat_proto); - kv->value = value; + kv->value = (u64) thread_index << 32 | session_index; } always_inline void @@ -93,11 +95,24 @@ init_nat_o2i_k (clib_bihash_kv_8_8_t * kv, snat_session_t * s) } always_inline void -init_nat_o2i_kv (clib_bihash_kv_8_8_t * kv, snat_session_t * s, u64 value) +init_nat_o2i_kv (clib_bihash_kv_8_8_t *kv, snat_session_t *s, u32 thread_index, + u32 session_index) { init_nat_k (kv, s->out2in.addr, s->out2in.port, s->out2in.fib_index, s->nat_proto); - kv->value = value; + kv->value = (u64) thread_index << 32 | session_index; +} + +always_inline u32 +nat_value_get_thread_index (clib_bihash_kv_8_8_t *value) +{ + return value->value >> 32; +} + +always_inline u32 +nat_value_get_session_index (clib_bihash_kv_8_8_t *value) +{ + return value->value & ~(u32) 0; } static inline uword |