ipsec: Derive the TUNNEL_V6 flag from the configured address types 94/32894/2
authorNeale Ranns <neale@graphiant.com>
Thu, 24 Jun 2021 15:41:03 +0000 (15:41 +0000)
committerMatthew Smith <mgsmith@netgate.com>
Wed, 30 Jun 2021 14:05:55 +0000 (14:05 +0000)
Type: improvement

There's no need for the user to set the TUNNEL_V6 flag, it can be
derived from the tunnel's address type.

Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I073073dc970b8a3f2b2645bc697fc00db1adbb47

src/vnet/ipsec/ipsec_sa.c
src/vnet/ipsec/ipsec_types.api
test/vpp_ipsec.py

index b1e3374..b5d58d0 100644 (file)
@@ -270,6 +270,10 @@ ipsec_sa_add_and_lock (u32 id, u32 spi, ipsec_protocol_t proto,
       return VNET_API_ERROR_SYSCALL_ERROR_1;
     }
 
+  if (ipsec_sa_is_set_IS_TUNNEL (sa) &&
+      AF_IP6 == ip_addr_version (&tun->t_src))
+    ipsec_sa_set_IS_TUNNEL_V6 (sa);
+
   if (ipsec_sa_is_set_IS_TUNNEL (sa) && !ipsec_sa_is_set_IS_INBOUND (sa))
     {
       sa->tunnel_flags = sa->tunnel.t_encap_decap_flags;
index 9fa7e05..ed04f47 100644 (file)
@@ -68,7 +68,10 @@ enum ipsec_sad_flags
   /* IPsec tunnel mode if non-zero, else transport mode */
   IPSEC_API_SAD_FLAG_IS_TUNNEL = 0x04,
   /* IPsec tunnel mode is IPv6 if non-zero,
-   *  else IPv4 tunnel only valid if is_tunnel is non-zero */
+   *  else IPv4 tunnel only valid if is_tunnel is non-zero
+   *  DEPRECATED - the user does not need to set this it is
+   *               derived from the tunnel's address types.
+   */
   IPSEC_API_SAD_FLAG_IS_TUNNEL_V6 = 0x08,
   /* enable UDP encapsulation for NAT traversal */
   IPSEC_API_SAD_FLAG_UDP_ENCAP = 0x10,
index 57e5f02..f9b7bc4 100644 (file)
@@ -217,8 +217,6 @@ class VppIpsecSA(VppObject):
         if (tun_src):
             self.tun_src = ip_address(text_type(tun_src))
             self.flags = self.flags | e.IPSEC_API_SAD_FLAG_IS_TUNNEL
-            if (self.tun_src.version == 6):
-                self.flags = self.flags | e.IPSEC_API_SAD_FLAG_IS_TUNNEL_V6
         if (tun_dst):
             self.tun_dst = ip_address(text_type(tun_dst))
         self.udp_src = udp_src