nat: fix coverity warning 09/26709/4
authorKlement Sekera <ksekera@cisco.com>
Mon, 27 Apr 2020 08:19:12 +0000 (08:19 +0000)
committerOle Trøan <otroan@employees.org>
Wed, 6 May 2020 08:46:14 +0000 (08:46 +0000)
Type: fix
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: I609fef6f96c6a3fc85a4dc07e75244b0e1ba9239

src/plugins/nat/in2out_ed.c

index f0bbe0b..21ef75c 100644 (file)
@@ -296,7 +296,6 @@ slow_path_ed (snat_main_t * sm,
   nat_outside_fib_t *outside_fib;
   fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
   clib_bihash_kv_16_8_t out2in_ed_kv;
   nat_outside_fib_t *outside_fib;
   fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
   clib_bihash_kv_16_8_t out2in_ed_kv;
-  bool out2in_ed_inserted = false;
   ip4_address_t allocated_addr;
   u16 allocated_port;
   u8 identity_nat;
   ip4_address_t allocated_addr;
   u16 allocated_port;
   u8 identity_nat;
@@ -346,7 +345,7 @@ slow_path_ed (snat_main_t * sm,
        {
          nat_elog_warn ("create NAT session failed");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
        {
          nat_elog_warn ("create NAT session failed");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
-         goto drop;
+         return NAT_NEXT_DROP;
        }
       switch (vec_len (sm->outside_fibs))
        {
        }
       switch (vec_len (sm->outside_fibs))
        {
@@ -384,10 +383,10 @@ slow_path_ed (snat_main_t * sm,
        {
          nat_elog_notice ("addresses exhausted");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
        {
          nat_elog_notice ("addresses exhausted");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
-         goto drop;
+         nat_free_session_data (sm, s, thread_index, 0);
+         nat44_ed_delete_session (sm, s, thread_index, 1);
+         return NAT_NEXT_DROP;
        }
        }
-
-      out2in_ed_inserted = true;
       key1.addr = allocated_addr;
       key1.port = allocated_port;
     }
       key1.addr = allocated_addr;
       key1.port = allocated_port;
     }
@@ -403,7 +402,7 @@ slow_path_ed (snat_main_t * sm,
        {
          nat_elog_warn ("create NAT session failed");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
        {
          nat_elog_warn ("create NAT session failed");
          b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
-         goto drop;
+         return NAT_NEXT_DROP;
        }
       switch (vec_len (sm->outside_fibs))
        {
        }
       switch (vec_len (sm->outside_fibs))
        {
@@ -441,7 +440,6 @@ slow_path_ed (snat_main_t * sm,
          (&tsm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
           &ctx))
        nat_elog_notice ("out2in-ed key add failed");
          (&tsm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
           &ctx))
        nat_elog_notice ("out2in-ed key add failed");
-      out2in_ed_inserted = true;
     }
 
   if (lb)
     }
 
   if (lb)
@@ -487,18 +485,6 @@ slow_path_ed (snat_main_t * sm,
               thread_index, 0);
 
   return next;
               thread_index, 0);
 
   return next;
-drop:
-  if (out2in_ed_inserted)
-    {
-      if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &out2in_ed_kv, 0))
-       nat_elog_notice ("out2in-ed key del failed");
-    }
-  if (s)
-    {
-      nat_free_session_data (sm, s, thread_index, 0);
-      nat44_ed_delete_session (sm, s, thread_index, 1);
-    }
-  return NAT_NEXT_DROP;
 }
 
 static_always_inline int
 }
 
 static_always_inline int