snat: fix coverity issues
Change-Id: Icb8239c02af8758a9e4bf299726a89677f53451d
Signed-off-by: Matus Fabian <matfabia@cisco.com>
diff --git a/plugins/snat-plugin/snat/in2out.c b/plugins/snat-plugin/snat/in2out.c
index e1edbb8..43ee2d0 100644
--- a/plugins/snat-plugin/snat/in2out.c
+++ b/plugins/snat-plugin/snat/in2out.c
@@ -1047,6 +1047,8 @@
u32 current_worker_index = ~0;
u32 cpu_index = os_get_cpu_number ();
+ ASSERT (vec_len (sm->workers));
+
if (PREDICT_FALSE (handoff_queue_elt_by_worker_index == 0))
{
vec_validate (handoff_queue_elt_by_worker_index, tm->n_vlib_mains - 1);
diff --git a/plugins/snat-plugin/snat/out2in.c b/plugins/snat-plugin/snat/out2in.c
index a4641d3..13e596b 100644
--- a/plugins/snat-plugin/snat/out2in.c
+++ b/plugins/snat-plugin/snat/out2in.c
@@ -830,6 +830,8 @@
u32 current_worker_index = ~0;
u32 cpu_index = os_get_cpu_number ();
+ ASSERT (vec_len (sm->workers));
+
if (PREDICT_FALSE (handoff_queue_elt_by_worker_index == 0))
{
vec_validate (handoff_queue_elt_by_worker_index, tm->n_vlib_mains - 1);
@@ -888,6 +890,8 @@
if (PREDICT_FALSE (next_worker_index != cpu_index))
{
+ do_handoff = 1;
+
if (next_worker_index != current_worker_index)
{
if (hf)
diff --git a/plugins/snat-plugin/snat/snat.c b/plugins/snat-plugin/snat/snat.c
index 70df44e..02077c3 100644
--- a/plugins/snat-plugin/snat/snat.c
+++ b/plugins/snat-plugin/snat/snat.c
@@ -494,8 +494,10 @@
if (!clib_bihash_search_8_8 (&sm->user_hash, &kv, &value))
{
user_index = value.value;
- clib_bihash_search_8_8 (&sm->worker_by_in, &kv, &value);
- tsm = vec_elt_at_index (sm->per_thread_data, value.value);
+ if (!clib_bihash_search_8_8 (&sm->worker_by_in, &kv, &value))
+ tsm = vec_elt_at_index (sm->per_thread_data, value.value);
+ else
+ tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
u = pool_elt_at_index (tsm->users, user_index);
if (u->nstaticsessions)
{