From 2de7e96e6f1d657c124f55a75c8d63d6f05803a7 Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Thu, 25 Mar 2021 15:39:15 +0100 Subject: nat: add thread index assertions Add extra assertions to debug build. Type: improvement Signed-off-by: Klement Sekera Change-Id: Ib20130365e8f9dbb556fcbb4321dd184c7eff603 --- src/plugins/nat/nat44-ed/nat44_ed.h | 1 + src/plugins/nat/nat44-ed/nat44_ed_in2out.c | 2 ++ src/plugins/nat/nat44-ed/nat44_ed_inlines.h | 6 ++++++ src/plugins/nat/nat44-ed/nat44_ed_out2in.c | 2 ++ 4 files changed, 11 insertions(+) diff --git a/src/plugins/nat/nat44-ed/nat44_ed.h b/src/plugins/nat/nat44-ed/nat44_ed.h index 1668d0295d5..91b3645254e 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed.h +++ b/src/plugins/nat/nat44-ed/nat44_ed.h @@ -344,6 +344,7 @@ typedef CLIB_PACKED(struct /* per vrf sessions index */ u32 per_vrf_sessions_index; + u32 thread_index; }) snat_session_t; typedef struct diff --git a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c index fe5fbac71a7..85cda76db39 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c @@ -1122,6 +1122,8 @@ nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t *vm, skip_lookup: + ASSERT (thread_index == s0->thread_index); + if (PREDICT_FALSE (per_vrf_sessions_is_expired (s0, thread_index))) { // session is closed, go slow path diff --git a/src/plugins/nat/nat44-ed/nat44_ed_inlines.h b/src/plugins/nat/nat44-ed/nat44_ed_inlines.h index d1cd85e2418..b2b578a5a8b 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_inlines.h +++ b/src/plugins/nat/nat44-ed/nat44_ed_inlines.h @@ -329,6 +329,8 @@ nat_ed_ses_i2o_flow_hash_add_del (snat_main_t *sm, u32 thread_idx, nat_6t_flow_to_ed_kv (&kv, &s->i2o, thread_idx, s - tsm->sessions); nat_6t_l3_l4_csum_calc (&s->i2o); } + + ASSERT (thread_idx == s->thread_index); return clib_bihash_add_del_16_8 (&sm->flow_hash, &kv, is_add); } @@ -348,6 +350,7 @@ nat_ed_ses_o2i_flow_hash_add_del (snat_main_t *sm, u32 thread_idx, nat_6t_flow_to_ed_kv (&kv, &s->o2i, thread_idx, s - tsm->sessions); nat_6t_l3_l4_csum_calc (&s->o2i); } + ASSERT (thread_idx == s->thread_index); return clib_bihash_add_del_16_8 (&sm->flow_hash, &kv, is_add); } @@ -441,6 +444,9 @@ nat_ed_session_alloc (snat_main_t *sm, u32 thread_index, f64 now, u8 proto) s->ha_last_refreshed = now; vlib_set_simple_counter (&sm->total_sessions, thread_index, 0, pool_elts (tsm->sessions)); +#if CLIB_ASSERT_ENABLE + s->thread_index = thread_index; +#endif return s; } diff --git a/src/plugins/nat/nat44-ed/nat44_ed_out2in.c b/src/plugins/nat/nat44-ed/nat44_ed_out2in.c index 45455576994..039d46406d1 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_out2in.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_out2in.c @@ -933,6 +933,8 @@ nat44_ed_out2in_fast_path_node_fn_inline (vlib_main_t * vm, ed_value_get_session_index (&value0)); skip_lookup: + ASSERT (thread_index == s0->thread_index); + if (PREDICT_FALSE (per_vrf_sessions_is_expired (s0, thread_index))) { // session is closed, go slow path -- cgit 1.2.3-korg