ipsec: Use the new tunnel API types to add flow label and TTL copy
[vpp.git] / src / vnet / ipsec / ipsec_tun.c
index ea60ab4..7434025 100644 (file)
@@ -263,15 +263,15 @@ ipsec_tun_protect_rx_db_add (ipsec_main_t * im,
           ipsec4_tunnel_mk_key(&key, &itp->itp_crypto.dst.ip4,
                                clib_host_to_net_u32 (sa->spi));
 
-          if (!im->tun4_protect_by_key.nbuckets)
-              clib_bihash_init_8_16 (&im->tun4_protect_by_key,
-                       "IPSec IPv4 tunnels",
-                       IPSEC_TUN_DEFAULT_HASH_NUM_BUCKETS,
-                       IPSEC_TUN_DEFAULT_HASH_MEMORY_SIZE);
-
-          clib_bihash_add_del_8_16 (&im->tun4_protect_by_key, bkey, 1);
-          ipsec_tun_register_nodes(AF_IP4);
-        }
+         if (!clib_bihash_is_initialised_8_16 (&im->tun4_protect_by_key))
+           clib_bihash_init_8_16 (&im->tun4_protect_by_key,
+                                  "IPSec IPv4 tunnels",
+                                  IPSEC_TUN_DEFAULT_HASH_NUM_BUCKETS,
+                                  IPSEC_TUN_DEFAULT_HASH_MEMORY_SIZE);
+
+         clib_bihash_add_del_8_16 (&im->tun4_protect_by_key, bkey, 1);
+         ipsec_tun_register_nodes (AF_IP4);
+       }
       else
         {
           ipsec6_tunnel_kv_t key = {
@@ -283,14 +283,14 @@ ipsec_tun_protect_rx_db_add (ipsec_main_t * im,
           };
           clib_bihash_kv_24_16_t *bkey = (clib_bihash_kv_24_16_t*)&key;
 
-          if (!im->tun4_protect_by_key.nbuckets)
-            clib_bihash_init_24_16 (&im->tun6_protect_by_key,
-                                   "IPSec IPv6 tunnels",
-                                   IPSEC_TUN_DEFAULT_HASH_NUM_BUCKETS,
-                                   IPSEC_TUN_DEFAULT_HASH_MEMORY_SIZE);
-          clib_bihash_add_del_24_16 (&im->tun6_protect_by_key, bkey, 1);
-          ipsec_tun_register_nodes(AF_IP6);
-        }
+         if (!clib_bihash_is_initialised_24_16 (&im->tun6_protect_by_key))
+           clib_bihash_init_24_16 (&im->tun6_protect_by_key,
+                                   "IPSec IPv6 tunnels",
+                                   IPSEC_TUN_DEFAULT_HASH_NUM_BUCKETS,
+                                   IPSEC_TUN_DEFAULT_HASH_MEMORY_SIZE);
+         clib_bihash_add_del_24_16 (&im->tun6_protect_by_key, bkey, 1);
+         ipsec_tun_register_nodes (AF_IP6);
+       }
   }))
   /* *INDENT-ON* */
 }
@@ -470,13 +470,13 @@ ipsec_tun_protect_set_crypto_addr (ipsec_tun_protect_t * itp)
   ({
     if (ipsec_sa_is_set_IS_TUNNEL (sa))
       {
-        itp->itp_crypto.src = sa->tunnel_dst_addr;
-        itp->itp_crypto.dst = sa->tunnel_src_addr;
-        if (!(itp->itp_flags & IPSEC_PROTECT_ITF))
-          {
-            ipsec_sa_set_IS_PROTECT (sa);
-            itp->itp_flags |= IPSEC_PROTECT_ENCAPED;
-          }
+       itp->itp_crypto.src = ip_addr_46 (&sa->tunnel.t_dst);
+       itp->itp_crypto.dst = ip_addr_46 (&sa->tunnel.t_src);
+       if (!(itp->itp_flags & IPSEC_PROTECT_ITF))
+         {
+           ipsec_sa_set_IS_PROTECT (sa);
+           itp->itp_flags |= IPSEC_PROTECT_ENCAPED;
+         }
       }
     else
       {