- /* 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) clib_host_to_net_u32 (sa->spi));
- hash_set (im->ipsec_if_pool_index_by_key, key, hi->dev_instance);
+ /* unset old inbound hash entry. packets should stop arriving */
+ key.remote_ip = old_sa->tunnel_src_addr.ip6;
+ key.spi = clib_host_to_net_u32 (old_sa->spi);
+
+ p = hash_get_mem (im->ipsec6_if_pool_index_by_key, &key);
+ if (p)
+ hash_unset_mem_free (&im->ipsec6_if_pool_index_by_key, &key);
+
+ /* set new inbound SA, then set new hash entry */
+ t->input_sa_index = sa_index;
+ key.remote_ip = sa->tunnel_src_addr.ip6;
+ key.spi = clib_host_to_net_u32 (sa->spi);
+
+ hash_set_mem_alloc (&im->ipsec6_if_pool_index_by_key, &key,
+ hi->dev_instance);
+ }
+ else
+ {
+ ipsec4_tunnel_key_t key;
+
+ /* unset old inbound hash entry. packets should stop arriving */
+ key.remote_ip = old_sa->tunnel_src_addr.ip4.as_u32;
+ key.spi = clib_host_to_net_u32 (old_sa->spi);
+
+ p = hash_get (im->ipsec4_if_pool_index_by_key, key.as_u64);
+ if (p)
+ hash_unset (im->ipsec4_if_pool_index_by_key, key.as_u64);
+
+ /* set new inbound SA, then set new hash entry */
+ t->input_sa_index = sa_index;
+ key.remote_ip = sa->tunnel_src_addr.ip4.as_u32;
+ key.spi = clib_host_to_net_u32 (sa->spi);
+
+ hash_set (im->ipsec4_if_pool_index_by_key, key.as_u64,
+ hi->dev_instance);
+ }