IPSEC: API coverity error of unitialised stat_index value
[vpp.git] / src / vnet / ipsec / ipsec_if.c
index 357d638..3ec4b0b 100644 (file)
@@ -109,7 +109,9 @@ ipsec_if_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
          hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
          t0 = pool_elt_at_index (im->tunnel_interfaces, hi0->dev_instance);
          vnet_buffer (b0)->ipsec.sad_index = t0->output_sa_index;
-         next0 = IPSEC_OUTPUT_NEXT_ESP4_ENCRYPT;
+
+         /* 0, tx-node next[0] was added by vlib_node_add_next_with_slot */
+         next0 = 0;
 
          len0 = vlib_buffer_length_in_chain (vm, b0);
 
@@ -278,7 +280,8 @@ ipsec_add_del_tunnel_if_internal (vnet_main_t * vnm,
   ipsec_sa_flags_t flags;
   int rv;
 
-  u64 key = (u64) args->remote_ip.ip4.as_u32 << 32 | (u64) args->remote_spi;
+  u64 key = ((u64) args->remote_ip.ip4.as_u32 << 32 |
+            (u64) clib_host_to_net_u32 (args->remote_spi));
   p = hash_get (im->ipsec_if_pool_index_by_key, key);
 
   if (args->is_add)
@@ -362,12 +365,12 @@ ipsec_add_del_tunnel_if_internal (vnet_main_t * vnm,
                                             t - im->tunnel_interfaces);
 
       hi = vnet_get_hw_interface (vnm, hw_if_index);
+      /* add esp4 as the next-node-index of this tx-node */
 
       slot = vlib_node_add_next_with_slot
-       (vnm->vlib_main, hi->tx_node_index, im->esp4_encrypt_node_index,
-        IPSEC_OUTPUT_NEXT_ESP4_ENCRYPT);
+       (vnm->vlib_main, hi->tx_node_index, im->esp4_encrypt_node_index, 0);
 
-      ASSERT (slot == IPSEC_OUTPUT_NEXT_ESP4_ENCRYPT);
+      ASSERT (slot == 0);
 
       t->hw_if_index = hw_if_index;
 
@@ -434,9 +437,11 @@ ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm,
   sa = pool_elt_at_index (im->sad, p[0]);
 
   if (sa->is_tunnel)
-    key = (u64) sa->tunnel_dst_addr.ip4.as_u32 << 32 | (u64) sa->spi;
+    key = ((u64) sa->tunnel_dst_addr.ip4.as_u32 << 32 |
+          (u64) clib_host_to_net_u32 (sa->spi));
   else
-    key = (u64) args->remote_ip.as_u32 << 32 | (u64) sa->spi;
+    key = ((u64) args->remote_ip.as_u32 << 32 |
+          (u64) clib_host_to_net_u32 (sa->spi));
 
   p = hash_get (im->ipsec_if_pool_index_by_key, key);
 
@@ -561,15 +566,16 @@ ipsec_set_interface_sa (vnet_main_t * vnm, u32 hw_if_index, u32 sa_id,
       old_sa = pool_elt_at_index (im->sad, old_sa_index);
 
       /* unset old inbound hash entry. packets should stop arriving */
-      key =
-       (u64) old_sa->tunnel_src_addr.ip4.as_u32 << 32 | (u64) old_sa->spi;
+      key = ((u64) old_sa->tunnel_src_addr.ip4.as_u32 << 32 |
+            (u64) clib_host_to_net_u32 (old_sa->spi));
       p = hash_get (im->ipsec_if_pool_index_by_key, key);
       if (p)
        hash_unset (im->ipsec_if_pool_index_by_key, key);
 
       /* set new inbound SA, then set new hash entry */
       t->input_sa_index = sa_index;
-      key = (u64) sa->tunnel_src_addr.ip4.as_u32 << 32 | (u64) sa->spi;
+      key = ((u64) sa->tunnel_src_addr.ip4.as_u32 << 32 |
+            (u64) clib_host_to_net_u32 (sa->spi));
       hash_set (im->ipsec_if_pool_index_by_key, key, hi->dev_instance);
     }
   else