2018-06-24 22:49:55 +02:00
|
|
|
import unittest
|
|
|
|
import socket
|
2019-03-20 18:24:43 +00:00
|
|
|
import copy
|
2019-04-11 15:14:07 +00:00
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
from scapy.layers.ipsec import SecurityAssociation, ESP
|
2020-01-31 23:48:30 -05:00
|
|
|
from scapy.layers.l2 import Ether, GRE, Dot1Q
|
2024-07-23 01:28:19 -04:00
|
|
|
from scapy.packet import Raw, bind_layers, Padding
|
2023-06-16 09:48:52 +02:00
|
|
|
from scapy.layers.inet import IP, UDP, ICMP
|
|
|
|
from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest
|
2020-12-21 13:19:10 +00:00
|
|
|
from scapy.contrib.mpls import MPLS
|
2023-08-31 00:47:44 -04:00
|
|
|
from asfframework import VppTestRunner, tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
from template_ipsec import (
|
|
|
|
TemplateIpsec,
|
|
|
|
IpsecTun4Tests,
|
|
|
|
IpsecTun6Tests,
|
|
|
|
IpsecTun4,
|
|
|
|
IpsecTun6,
|
|
|
|
IpsecTcpTests,
|
|
|
|
mk_scapy_crypt_key,
|
|
|
|
IpsecTun6HandoffTests,
|
|
|
|
IpsecTun4HandoffTests,
|
|
|
|
config_tun_params,
|
|
|
|
)
|
2019-02-07 07:26:12 -08:00
|
|
|
from vpp_gre_interface import VppGreInterface
|
|
|
|
from vpp_ipip_tun_interface import VppIpIpTunInterface
|
2022-04-26 19:02:15 +02:00
|
|
|
from vpp_ip_route import (
|
|
|
|
VppIpRoute,
|
|
|
|
VppRoutePath,
|
|
|
|
DpoProto,
|
|
|
|
VppMplsLabel,
|
|
|
|
VppMplsTable,
|
|
|
|
VppMplsRoute,
|
|
|
|
FibPathProto,
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect, VppIpsecInterface
|
2019-03-29 20:23:58 +00:00
|
|
|
from vpp_l2 import VppBridgeDomain, VppBridgeDomainPort
|
2020-01-31 23:48:30 -05:00
|
|
|
from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
|
2019-12-16 00:53:11 +00:00
|
|
|
from vpp_teib import VppTeib
|
2019-03-29 20:23:58 +00:00
|
|
|
from util import ppp
|
2019-04-11 15:14:07 +00:00
|
|
|
from vpp_papi import VppEnum
|
2020-10-13 20:02:11 -04:00
|
|
|
from vpp_papi_provider import CliFailedCommandError
|
2020-05-12 08:51:02 +00:00
|
|
|
from vpp_acl import AclRule, VppAcl, VppAclInterface
|
2022-04-05 19:23:12 +02:00
|
|
|
from vpp_policer import PolicerAction, VppPolicer, Dir
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
2018-06-24 22:49:55 +02:00
|
|
|
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
def config_tun_params(p, encryption_type, tun_if, src=None, dst=None):
|
2019-09-26 16:20:19 +00:00
|
|
|
ip_class_by_addr_type = {socket.AF_INET: IP, socket.AF_INET6: IPv6}
|
2022-04-26 19:02:15 +02:00
|
|
|
esn_en = bool(
|
|
|
|
p.flags & (VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN)
|
|
|
|
)
|
2019-09-26 16:20:19 +00:00
|
|
|
crypt_key = mk_scapy_crypt_key(p)
|
2020-06-30 07:47:14 +00:00
|
|
|
if tun_if:
|
|
|
|
p.tun_dst = tun_if.remote_ip
|
|
|
|
p.tun_src = tun_if.local_ip
|
|
|
|
else:
|
|
|
|
p.tun_dst = dst
|
|
|
|
p.tun_src = src
|
|
|
|
|
2022-01-04 15:53:43 +01:00
|
|
|
if p.nat_header:
|
2022-04-26 19:02:15 +02:00
|
|
|
is_default_port = p.nat_header.dport == 4500
|
2022-01-04 15:53:43 +01:00
|
|
|
else:
|
|
|
|
is_default_port = True
|
|
|
|
|
|
|
|
if is_default_port:
|
|
|
|
outbound_nat_header = p.nat_header
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
outbound_nat_header = UDP(sport=p.nat_header.dport, dport=p.nat_header.sport)
|
2022-01-04 15:53:43 +01:00
|
|
|
bind_layers(UDP, ESP, dport=p.nat_header.dport)
|
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
p.scapy_tun_sa = SecurityAssociation(
|
2022-04-26 19:02:15 +02:00
|
|
|
encryption_type,
|
2022-11-16 18:45:24 +01:00
|
|
|
spi=p.scapy_tun_spi,
|
2019-09-26 16:20:19 +00:00
|
|
|
crypt_algo=p.crypt_algo,
|
|
|
|
crypt_key=crypt_key,
|
2022-04-26 19:02:15 +02:00
|
|
|
auth_algo=p.auth_algo,
|
|
|
|
auth_key=p.auth_key,
|
|
|
|
tunnel_header=ip_class_by_addr_type[p.addr_type](src=p.tun_dst, dst=p.tun_src),
|
2022-01-04 15:53:43 +01:00
|
|
|
nat_t_header=outbound_nat_header,
|
2022-04-26 19:02:15 +02:00
|
|
|
esn_en=esn_en,
|
|
|
|
)
|
2019-09-26 16:20:19 +00:00
|
|
|
p.vpp_tun_sa = SecurityAssociation(
|
2022-04-26 19:02:15 +02:00
|
|
|
encryption_type,
|
2022-11-16 18:45:24 +01:00
|
|
|
spi=p.vpp_tun_spi,
|
2019-09-26 16:20:19 +00:00
|
|
|
crypt_algo=p.crypt_algo,
|
|
|
|
crypt_key=crypt_key,
|
2022-04-26 19:02:15 +02:00
|
|
|
auth_algo=p.auth_algo,
|
|
|
|
auth_key=p.auth_key,
|
|
|
|
tunnel_header=ip_class_by_addr_type[p.addr_type](dst=p.tun_dst, src=p.tun_src),
|
2019-09-26 16:20:19 +00:00
|
|
|
nat_t_header=p.nat_header,
|
2022-04-26 19:02:15 +02:00
|
|
|
esn_en=esn_en,
|
|
|
|
)
|
2019-09-26 16:20:19 +00:00
|
|
|
|
|
|
|
|
2019-12-18 05:54:40 +00:00
|
|
|
def config_tra_params(p, encryption_type, tun_if):
|
|
|
|
ip_class_by_addr_type = {socket.AF_INET: IP, socket.AF_INET6: IPv6}
|
2022-04-26 19:02:15 +02:00
|
|
|
esn_en = bool(
|
|
|
|
p.flags & (VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN)
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
crypt_key = mk_scapy_crypt_key(p)
|
2020-01-02 05:04:00 +00:00
|
|
|
p.tun_dst = tun_if.remote_ip
|
|
|
|
p.tun_src = tun_if.local_ip
|
2022-01-04 15:53:43 +01:00
|
|
|
|
|
|
|
if p.nat_header:
|
2022-04-26 19:02:15 +02:00
|
|
|
is_default_port = p.nat_header.dport == 4500
|
2022-01-04 15:53:43 +01:00
|
|
|
else:
|
|
|
|
is_default_port = True
|
|
|
|
|
|
|
|
if is_default_port:
|
|
|
|
outbound_nat_header = p.nat_header
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
outbound_nat_header = UDP(sport=p.nat_header.dport, dport=p.nat_header.sport)
|
2022-01-04 15:53:43 +01:00
|
|
|
bind_layers(UDP, ESP, dport=p.nat_header.dport)
|
|
|
|
|
2019-12-18 05:54:40 +00:00
|
|
|
p.scapy_tun_sa = SecurityAssociation(
|
2022-04-26 19:02:15 +02:00
|
|
|
encryption_type,
|
2022-11-16 18:45:24 +01:00
|
|
|
spi=p.scapy_tun_spi,
|
2019-12-18 05:54:40 +00:00
|
|
|
crypt_algo=p.crypt_algo,
|
|
|
|
crypt_key=crypt_key,
|
2022-04-26 19:02:15 +02:00
|
|
|
auth_algo=p.auth_algo,
|
|
|
|
auth_key=p.auth_key,
|
2020-04-01 09:45:23 +00:00
|
|
|
esn_en=esn_en,
|
2022-04-26 19:02:15 +02:00
|
|
|
nat_t_header=outbound_nat_header,
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
p.vpp_tun_sa = SecurityAssociation(
|
2022-04-26 19:02:15 +02:00
|
|
|
encryption_type,
|
2022-11-16 18:45:24 +01:00
|
|
|
spi=p.vpp_tun_spi,
|
2019-12-18 05:54:40 +00:00
|
|
|
crypt_algo=p.crypt_algo,
|
|
|
|
crypt_key=crypt_key,
|
2022-04-26 19:02:15 +02:00
|
|
|
auth_algo=p.auth_algo,
|
|
|
|
auth_key=p.auth_key,
|
2020-04-01 09:45:23 +00:00
|
|
|
esn_en=esn_en,
|
2022-04-26 19:02:15 +02:00
|
|
|
nat_t_header=p.nat_header,
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
class TemplateIpsec4TunProtect(object):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPsec IPv4 Tunnel protect"""
|
2020-12-23 16:22:28 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2020-12-23 16:22:28 +00:00
|
|
|
tun4_input_node = "ipsec4-tun-input"
|
|
|
|
|
|
|
|
def config_sa_tra(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def config_sa_tun(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.tun_if.local_addr[p.addr_type],
|
|
|
|
self.tun_if.remote_addr[p.addr_type],
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.tun_if.remote_addr[p.addr_type],
|
|
|
|
self.tun_if.local_addr[p.addr_type],
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def config_protect(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
def config_network(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
if hasattr(p, "tun_dst"):
|
2020-12-23 16:22:28 +00:00
|
|
|
tun_dst = p.tun_dst
|
|
|
|
else:
|
|
|
|
tun_dst = self.pg0.remote_ip4
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppIpIpTunInterface(self, self.pg0, self.pg0.local_ip4, tun_dst)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.route = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)],
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.route.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host6,
|
|
|
|
128,
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, 0xFFFFFFFF, proto=DpoProto.DPO_PROTO_IP6
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
r.add_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_network(self, p):
|
|
|
|
p.route.remove_vpp_config()
|
|
|
|
p.tun_if.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_protect(self, p):
|
|
|
|
p.tun_protect.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_sa(self, p):
|
|
|
|
p.tun_sa_out.remove_vpp_config()
|
|
|
|
p.tun_sa_in.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TemplateIpsec4TunIfEsp(TemplateIpsec4TunProtect, TemplateIpsec):
|
|
|
|
"""IPsec tunnel interface tests"""
|
2018-06-24 22:49:55 +02:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TemplateIpsec4TunIfEsp, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TemplateIpsec4TunIfEsp, cls).tearDownClass()
|
|
|
|
|
2018-06-24 22:49:55 +02:00
|
|
|
def setUp(self):
|
2019-03-20 07:21:58 -04:00
|
|
|
super(TemplateIpsec4TunIfEsp, self).setUp()
|
2019-01-23 08:16:17 -08:00
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
2018-09-26 11:19:00 +02:00
|
|
|
p = self.ipv4_params
|
2019-03-28 08:56:10 +00:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2018-06-24 22:49:55 +02:00
|
|
|
|
|
|
|
def tearDown(self):
|
2019-03-20 07:21:58 -04:00
|
|
|
super(TemplateIpsec4TunIfEsp, self).tearDown()
|
2018-06-24 22:49:55 +02:00
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TemplateIpsec4TunIfEspUdp(TemplateIpsec4TunProtect, TemplateIpsec):
|
|
|
|
"""IPsec UDP tunnel interface tests"""
|
2019-07-16 06:19:35 -07:00
|
|
|
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-07-16 06:19:35 -07:00
|
|
|
encryption_type = ESP
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TemplateIpsec4TunIfEspUdp, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TemplateIpsec4TunIfEspUdp, cls).tearDownClass()
|
|
|
|
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
# ensure the UDP ports are correct before we decrypt
|
|
|
|
# which strips them
|
|
|
|
self.assertTrue(rx.haslayer(UDP))
|
2020-12-23 16:22:28 +00:00
|
|
|
self.assert_equal(rx[UDP].sport, p.nat_header.sport)
|
2022-08-31 19:13:03 +02:00
|
|
|
self.assert_equal(rx[UDP].dport, p.nat_header.dport)
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, "1.1.1.1")
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg1.remote_ip4)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
def config_sa_tra(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
udp_src=p.nat_header.sport,
|
|
|
|
udp_dst=p.nat_header.dport,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
2022-08-31 19:13:03 +02:00
|
|
|
flags=p.flags
|
|
|
|
| VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_IS_INBOUND,
|
2022-04-26 19:02:15 +02:00
|
|
|
udp_src=p.nat_header.sport,
|
|
|
|
udp_dst=p.nat_header.dport,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2019-07-16 06:19:35 -07:00
|
|
|
def setUp(self):
|
|
|
|
super(TemplateIpsec4TunIfEspUdp, self).setUp()
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.flags = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_UDP_ENCAP
|
2019-07-16 06:19:35 -07:00
|
|
|
p.nat_header = UDP(sport=5454, dport=4500)
|
|
|
|
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
self.tun_if = self.pg0
|
2019-07-16 06:19:35 -07:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2019-07-16 06:19:35 -07:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TemplateIpsec4TunIfEspUdp, self).tearDown()
|
|
|
|
|
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
class TemplateIpsec4TunTfc:
|
|
|
|
"""IPsec IPv4 tunnel with TFC"""
|
|
|
|
|
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=54):
|
|
|
|
pkt = (
|
|
|
|
IP(src=src, dst=dst, len=28 + payload_size)
|
|
|
|
/ ICMP()
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
/ Padding(b"Y" * 100)
|
|
|
|
)
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac) / sa.encrypt(pkt)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[IP].src, p.remote_tun_if_host)
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
self.assert_equal(rx[IP].len, len(rx[IP]))
|
|
|
|
self.assert_packet_checksums_valid(rx)
|
|
|
|
|
|
|
|
|
2019-03-20 07:21:58 -04:00
|
|
|
class TestIpsec4TunIfEsp1(TemplateIpsec4TunIfEsp, IpsecTun4Tests):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec ESP - TUN tests"""
|
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2018-06-24 22:49:55 +02:00
|
|
|
|
2019-03-27 13:40:35 +00:00
|
|
|
def test_tun_basic64(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ipsec 6o4 tunnel basic test"""
|
2019-09-26 16:20:19 +00:00
|
|
|
self.tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2019-03-27 13:40:35 +00:00
|
|
|
self.verify_tun_64(self.params[socket.AF_INET], count=1)
|
|
|
|
|
|
|
|
def test_tun_burst64(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ipsec 6o4 tunnel basic test"""
|
2019-09-26 16:20:19 +00:00
|
|
|
self.tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2019-05-16 14:34:55 +02:00
|
|
|
|
2019-03-27 13:40:35 +00:00
|
|
|
self.verify_tun_64(self.params[socket.AF_INET], count=257)
|
|
|
|
|
2019-03-28 08:56:10 +00:00
|
|
|
def test_tun_basic_frag44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ipsec 4o4 tunnel frag basic test"""
|
2019-05-16 14:34:55 +02:00
|
|
|
self.tun4_encrypt_node_name = "esp4-encrypt-tun"
|
|
|
|
|
2019-03-28 08:56:10 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.vapi.sw_interface_set_mtu(p.tun_if.sw_if_index, [1500, 0, 0, 0])
|
|
|
|
self.verify_tun_44(
|
|
|
|
self.params[socket.AF_INET], count=1, payload_size=1800, n_rx=2
|
|
|
|
)
|
|
|
|
self.vapi.sw_interface_set_mtu(p.tun_if.sw_if_index, [9000, 0, 0, 0])
|
2019-03-28 08:56:10 +00:00
|
|
|
|
2018-06-24 22:49:55 +02:00
|
|
|
|
2019-07-16 06:19:35 -07:00
|
|
|
class TestIpsec4TunIfEspUdp(TemplateIpsec4TunIfEspUdp, IpsecTun4Tests):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec ESP UDP tests"""
|
2019-07-16 06:19:35 -07:00
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
tun4_input_node = "ipsec4-tun-input"
|
2019-07-16 06:19:35 -07:00
|
|
|
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
def setUp(self):
|
2020-12-23 16:22:28 +00:00
|
|
|
super(TestIpsec4TunIfEspUdp, self).setUp()
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
|
2019-07-16 06:19:35 -07:00
|
|
|
def test_keepalive(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC NAT Keepalive"""
|
2019-07-16 06:19:35 -07:00
|
|
|
self.verify_keepalive(self.ipv4_params)
|
|
|
|
|
|
|
|
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
class TestIpsec4TunIfEspUdpGCM(TemplateIpsec4TunIfEspUdp, IpsecTun4Tests):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec ESP UDP GCM tests"""
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
|
|
|
|
tun4_input_node = "ipsec4-tun-input"
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-12-23 16:22:28 +00:00
|
|
|
super(TestIpsec4TunIfEspUdpGCM, self).setUp()
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id = VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
p.crypt_algo_vpp_id = (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_GCM_256
|
|
|
|
)
|
ipsec: fix udp-encap in transport mode
Now UDP enacapsulation doesn't work in transport mode with crypto
algorithms that have iv_sz=8 like AES GCM or 3DES CBC. That happens
because the inserted UDP header overlaps with the old IP header and
gets filled before the information from the old IP header can be
copied to a new IP header. The result is a broken packet:
00:03:39:620863: esp4-encrypt-tun
esp: sa-index 3 spi 3464048590 (0xce792fce) seq 31 sa-seq-hi 0
crypto aes-gcm-128 integrity none udp-encap-enabled
00:03:39:620867: adj-midchain-tx
...
00:03:39:620868: ip4-rewrite
...
00:03:39:620869: GigabitEthernet0/8/0-output
GigabitEthernet0/8/0
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
00:03:39:620870: GigabitEthernet0/8/0-tx
GigabitEthernet0/8/0 tx queue 0
...
IP4: 08:00:27:a9:6b:d6 -> 08:00:27:5a:dd:0c
UDP: 10.255.0.10 -> 10.255.0.20
version 0, header length 0
tos 0x80, ttl 63, length 0, checksum 0x653e (should be 0xffff)
dscp CS4 ecn NON_ECN
fragment id 0x0000
UDP: 128 -> 0
length 0, checksum 0x0000
With this commit, fill UDP header after copying the IP headers in
transport mode.
Type: fix
Change-Id: Ie9a6e562aa05a8378114329d6a9ff395189fa6a8
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2020-03-25 10:56:52 -04:00
|
|
|
p.crypt_algo = "AES-GCM"
|
|
|
|
p.auth_algo = "NULL"
|
|
|
|
p.crypt_key = b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"
|
|
|
|
p.salt = 0
|
|
|
|
|
|
|
|
|
2022-08-31 19:13:03 +02:00
|
|
|
class TestIpsec4TunIfEspUdpUpdate(TemplateIpsec4TunIfEspUdp, IpsecTun4Tests):
|
|
|
|
"""Ipsec ESP UDP update tests"""
|
|
|
|
|
|
|
|
tun4_input_node = "ipsec4-tun-input"
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunIfEspUdpUpdate, self).setUp()
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.nat_header = UDP(sport=6565, dport=7676)
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
p.tun_sa_in.update_vpp_config(
|
|
|
|
udp_src=p.nat_header.dport, udp_dst=p.nat_header.sport
|
|
|
|
)
|
|
|
|
p.tun_sa_out.update_vpp_config(
|
|
|
|
udp_src=p.nat_header.sport, udp_dst=p.nat_header.dport
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-20 07:21:58 -04:00
|
|
|
class TestIpsec4TunIfEsp2(TemplateIpsec4TunIfEsp, IpsecTcpTests):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec ESP - TCP tests"""
|
|
|
|
|
2018-06-24 22:49:55 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
class TemplateIpsec6TunProtect(object):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPsec IPv6 Tunnel protect"""
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
def config_sa_tra(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
def config_sa_tun(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.tun_if.local_addr[p.addr_type],
|
|
|
|
self.tun_if.remote_addr[p.addr_type],
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.tun_if.remote_addr[p.addr_type],
|
|
|
|
self.tun_if.local_addr[p.addr_type],
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def config_protect(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
def config_network(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
if hasattr(p, "tun_dst"):
|
2020-12-23 16:22:28 +00:00
|
|
|
tun_dst = p.tun_dst
|
|
|
|
else:
|
|
|
|
tun_dst = self.pg0.remote_ip6
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppIpIpTunInterface(self, self.pg0, self.pg0.local_ip6, tun_dst)
|
2019-09-26 16:20:19 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
p.tun_if.config_ip4()
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.route = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
128,
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, 0xFFFFFFFF, proto=DpoProto.DPO_PROTO_IP6
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2020-12-23 16:22:28 +00:00
|
|
|
p.route.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host4,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)],
|
|
|
|
)
|
2018-05-01 05:17:55 -07:00
|
|
|
r.add_vpp_config()
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
def unconfig_network(self, p):
|
|
|
|
p.route.remove_vpp_config()
|
|
|
|
p.tun_if.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_protect(self, p):
|
|
|
|
p.tun_protect.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_sa(self, p):
|
|
|
|
p.tun_sa_out.remove_vpp_config()
|
|
|
|
p.tun_sa_in.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TemplateIpsec6TunIfEsp(TemplateIpsec6TunProtect, TemplateIpsec):
|
|
|
|
"""IPsec tunnel interface tests"""
|
2020-12-23 16:22:28 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TemplateIpsec6TunIfEsp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
2019-03-20 07:21:58 -04:00
|
|
|
def tearDown(self):
|
|
|
|
super(TemplateIpsec6TunIfEsp, self).tearDown()
|
|
|
|
|
|
|
|
|
2022-08-09 22:19:38 +00:00
|
|
|
class TemplateIpsec6TunIfEspUdp(TemplateIpsec6TunProtect, TemplateIpsec):
|
|
|
|
"""IPsec6 UDP tunnel interface tests"""
|
|
|
|
|
|
|
|
tun4_encrypt_node_name = "esp6-encrypt-tun"
|
|
|
|
tun4_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
|
|
|
encryption_type = ESP
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TemplateIpsec6TunIfEspUdp, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TemplateIpsec6TunIfEspUdp, cls).tearDownClass()
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
# ensure the UDP ports are correct before we decrypt
|
|
|
|
# which strips them
|
|
|
|
self.assertTrue(rx.haslayer(UDP))
|
|
|
|
self.assert_equal(rx[UDP].sport, p.nat_header.sport)
|
2022-08-31 19:13:03 +02:00
|
|
|
self.assert_equal(rx[UDP].dport, p.nat_header.dport)
|
2022-08-09 22:19:38 +00:00
|
|
|
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(
|
|
|
|
pkt[IP].dst, "1111:1111:1111:1111:1111:1111:1111:1111"
|
|
|
|
)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg1.remote_ip6)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def config_sa_tra(self, p):
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-08-09 22:19:38 +00:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
udp_src=p.nat_header.sport,
|
|
|
|
udp_dst=p.nat_header.dport,
|
|
|
|
)
|
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-08-09 22:19:38 +00:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
2022-08-31 19:13:03 +02:00
|
|
|
flags=p.flags
|
|
|
|
| VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_IS_INBOUND,
|
2022-08-09 22:19:38 +00:00
|
|
|
udp_src=p.nat_header.sport,
|
|
|
|
udp_dst=p.nat_header.dport,
|
|
|
|
)
|
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TemplateIpsec6TunIfEspUdp, self).setUp()
|
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
p.flags = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_UDP_ENCAP
|
|
|
|
p.nat_header = UDP(sport=5454, dport=4500)
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TemplateIpsec6TunIfEspUdp, self).tearDown()
|
|
|
|
|
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
class TemplateIpsec6TunTfc:
|
|
|
|
"""IPsec IPv6 tunnel with TFC"""
|
|
|
|
|
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=54):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IPv6(src=src, dst=dst, hlim=p.inner_hop_limit, fl=p.inner_flow_label)
|
|
|
|
/ ICMPv6EchoRequest(id=0, seq=1, data="X" * payload_size)
|
|
|
|
/ Padding(b"Y" * 100)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def verify_decrypted6(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[IPv6].src, p.remote_tun_if_host)
|
|
|
|
self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
|
|
|
|
self.assert_equal(rx[IPv6].plen, len(rx[IPv6].payload))
|
|
|
|
self.assert_packet_checksums_valid(rx)
|
|
|
|
|
|
|
|
|
2022-08-09 22:19:38 +00:00
|
|
|
class TestIpsec6TunIfEspUdp(TemplateIpsec6TunIfEspUdp, IpsecTun6Tests):
|
|
|
|
"""Ipsec ESP 6 UDP tests"""
|
|
|
|
|
|
|
|
tun6_input_node = "ipsec6-tun-input"
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6TunIfEspUdp, self).setUp()
|
|
|
|
|
|
|
|
def test_keepalive(self):
|
|
|
|
"""IPSEC6 NAT Keepalive"""
|
|
|
|
self.verify_keepalive(self.ipv6_params)
|
|
|
|
|
|
|
|
|
|
|
|
class TestIpsec6TunIfEspUdpGCM(TemplateIpsec6TunIfEspUdp, IpsecTun6Tests):
|
|
|
|
"""Ipsec ESP 6 UDP GCM tests"""
|
|
|
|
|
|
|
|
tun6_input_node = "ipsec6-tun-input"
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6TunIfEspUdpGCM, self).setUp()
|
|
|
|
p = self.ipv6_params
|
|
|
|
p.auth_algo_vpp_id = VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
p.crypt_algo_vpp_id = (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_GCM_256
|
|
|
|
)
|
|
|
|
p.crypt_algo = "AES-GCM"
|
|
|
|
p.auth_algo = "NULL"
|
|
|
|
p.crypt_key = b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"
|
|
|
|
p.salt = 0
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6TunIfEsp1(TemplateIpsec6TunIfEsp, IpsecTun6Tests):
|
|
|
|
"""Ipsec ESP - TUN tests"""
|
|
|
|
|
2019-05-16 14:34:55 +02:00
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2019-03-27 13:40:35 +00:00
|
|
|
def test_tun_basic46(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ipsec 4o6 tunnel basic test"""
|
2019-09-26 16:20:19 +00:00
|
|
|
self.tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2019-03-27 13:40:35 +00:00
|
|
|
self.verify_tun_46(self.params[socket.AF_INET6], count=1)
|
|
|
|
|
|
|
|
def test_tun_burst46(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ipsec 4o6 tunnel burst test"""
|
2019-09-26 16:20:19 +00:00
|
|
|
self.tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2019-03-27 13:40:35 +00:00
|
|
|
self.verify_tun_46(self.params[socket.AF_INET6], count=257)
|
|
|
|
|
2019-03-20 07:21:58 -04:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6TunIfEspHandoff(TemplateIpsec6TunIfEsp, IpsecTun6HandoffTests):
|
|
|
|
"""Ipsec ESP 6 Handoff tests"""
|
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-12-23 04:10:25 +00:00
|
|
|
|
2021-02-22 18:42:24 +00:00
|
|
|
def test_tun_handoff_66_police(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ESP 6o6 tunnel with policer worker hand-off test"""
|
2021-02-22 18:42:24 +00:00
|
|
|
self.vapi.cli("clear errors")
|
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
|
|
|
|
N_PKTS = 15
|
|
|
|
p = self.params[socket.AF_INET6]
|
|
|
|
|
|
|
|
action_tx = PolicerAction(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0
|
|
|
|
)
|
|
|
|
policer = VppPolicer(
|
|
|
|
self,
|
|
|
|
"pol1",
|
|
|
|
80,
|
|
|
|
0,
|
|
|
|
1000,
|
|
|
|
0,
|
|
|
|
conform_action=action_tx,
|
|
|
|
exceed_action=action_tx,
|
|
|
|
violate_action=action_tx,
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.add_vpp_config()
|
|
|
|
|
|
|
|
# Start policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
for pol_bind in [1, 0]:
|
|
|
|
policer.bind_vpp_config(pol_bind, True)
|
|
|
|
|
|
|
|
# inject alternately on worker 0 and 1.
|
|
|
|
for worker in [0, 1, 0, 1]:
|
2022-04-26 19:02:15 +02:00
|
|
|
send_pkts = self.gen_encrypt_pkts6(
|
|
|
|
p,
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip6,
|
|
|
|
count=N_PKTS,
|
|
|
|
)
|
|
|
|
recv_pkts = self.send_and_expect(
|
|
|
|
self.tun_if, send_pkts, self.pg1, worker=worker
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.verify_decrypted6(p, recv_pkts)
|
|
|
|
self.logger.debug(self.vapi.cli("show trace max 100"))
|
|
|
|
|
|
|
|
stats = policer.get_stats()
|
|
|
|
stats0 = policer.get_stats(worker=0)
|
|
|
|
stats1 = policer.get_stats(worker=1)
|
|
|
|
|
2021-03-03 10:40:05 +01:00
|
|
|
if pol_bind == 1:
|
2021-02-22 18:42:24 +00:00
|
|
|
# First pass: Worker 1, should have done all the policing
|
|
|
|
self.assertEqual(stats, stats1)
|
|
|
|
|
|
|
|
# Worker 0, should have handed everything off
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(stats0["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats0["exceed_packets"], 0)
|
|
|
|
self.assertEqual(stats0["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
else:
|
|
|
|
# Second pass: both workers should have policed equal amounts
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats1["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats1["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats1["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats0["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats0["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats0["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
stats0["conform_packets"] + stats0["violate_packets"],
|
|
|
|
stats1["conform_packets"] + stats1["violate_packets"],
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.remove_vpp_config()
|
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunIfEspHandoff(TemplateIpsec4TunIfEsp, IpsecTun4HandoffTests):
|
|
|
|
"""Ipsec ESP 4 Handoff tests"""
|
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-23 04:10:25 +00:00
|
|
|
|
2021-02-22 18:42:24 +00:00
|
|
|
def test_tun_handoff_44_police(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""ESP 4o4 tunnel with policer worker hand-off test"""
|
2021-02-22 18:42:24 +00:00
|
|
|
self.vapi.cli("clear errors")
|
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
|
|
|
|
N_PKTS = 15
|
|
|
|
p = self.params[socket.AF_INET]
|
|
|
|
|
|
|
|
action_tx = PolicerAction(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0
|
|
|
|
)
|
|
|
|
policer = VppPolicer(
|
|
|
|
self,
|
|
|
|
"pol1",
|
|
|
|
80,
|
|
|
|
0,
|
|
|
|
1000,
|
|
|
|
0,
|
|
|
|
conform_action=action_tx,
|
|
|
|
exceed_action=action_tx,
|
|
|
|
violate_action=action_tx,
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.add_vpp_config()
|
|
|
|
|
|
|
|
# Start policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
for pol_bind in [1, 0]:
|
|
|
|
policer.bind_vpp_config(pol_bind, True)
|
|
|
|
|
|
|
|
# inject alternately on worker 0 and 1.
|
|
|
|
for worker in [0, 1, 0, 1]:
|
2022-04-26 19:02:15 +02:00
|
|
|
send_pkts = self.gen_encrypt_pkts(
|
|
|
|
p,
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip4,
|
|
|
|
count=N_PKTS,
|
|
|
|
)
|
|
|
|
recv_pkts = self.send_and_expect(
|
|
|
|
self.tun_if, send_pkts, self.pg1, worker=worker
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.verify_decrypted(p, recv_pkts)
|
|
|
|
self.logger.debug(self.vapi.cli("show trace max 100"))
|
|
|
|
|
|
|
|
stats = policer.get_stats()
|
|
|
|
stats0 = policer.get_stats(worker=0)
|
|
|
|
stats1 = policer.get_stats(worker=1)
|
|
|
|
|
2021-03-03 10:40:05 +01:00
|
|
|
if pol_bind == 1:
|
2021-02-22 18:42:24 +00:00
|
|
|
# First pass: Worker 1, should have done all the policing
|
|
|
|
self.assertEqual(stats, stats1)
|
|
|
|
|
|
|
|
# Worker 0, should have handed everything off
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(stats0["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats0["exceed_packets"], 0)
|
|
|
|
self.assertEqual(stats0["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
else:
|
|
|
|
# Second pass: both workers should have policed equal amounts
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats1["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats1["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats1["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats0["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats0["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats0["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
stats0["conform_packets"] + stats0["violate_packets"],
|
|
|
|
stats1["conform_packets"] + stats1["violate_packets"],
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.remove_vpp_config()
|
|
|
|
|
2019-12-23 04:10:25 +00:00
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4MultiTunIfEsp(TemplateIpsec4TunProtect, TemplateIpsec, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Multi Tunnel interface"""
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
2019-05-16 14:34:55 +02:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4MultiTunIfEsp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
self.multi_params = []
|
2019-09-26 16:20:19 +00:00
|
|
|
self.pg0.generate_remote_hosts(10)
|
|
|
|
self.pg0.configure_ipv4_neighbors()
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
for ii in range(10):
|
|
|
|
p = copy.copy(self.ipv4_params)
|
|
|
|
|
|
|
|
p.remote_tun_if_host = "1.1.1.%d" % (ii + 1)
|
|
|
|
p.scapy_tun_sa_id = p.scapy_tun_sa_id + ii
|
|
|
|
p.scapy_tun_spi = p.scapy_tun_spi + ii
|
|
|
|
p.vpp_tun_sa_id = p.vpp_tun_sa_id + ii
|
|
|
|
p.vpp_tun_spi = p.vpp_tun_spi + ii
|
|
|
|
|
|
|
|
p.scapy_tra_sa_id = p.scapy_tra_sa_id + ii
|
|
|
|
p.scapy_tra_spi = p.scapy_tra_spi + ii
|
|
|
|
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
|
|
|
|
p.vpp_tra_spi = p.vpp_tra_spi + ii
|
2019-12-20 00:54:57 +00:00
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip4
|
2019-03-20 18:24:43 +00:00
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
self.multi_params.append(p)
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec4MultiTunIfEsp, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multiple IPSEC tunnel interfaces"""
|
2019-03-20 18:24:43 +00:00
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_44(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-03-20 18:24:43 +00:00
|
|
|
|
2019-12-20 00:54:57 +00:00
|
|
|
def test_tun_rr_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Round-robin packets acrros multiple interface"""
|
2019-12-20 00:54:57 +00:00
|
|
|
tx = []
|
|
|
|
for p in self.multi_params:
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = tx + self.gen_encrypt_pkts(
|
|
|
|
p,
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip4,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
rxs = self.send_and_expect(self.tun_if, tx, self.pg1)
|
|
|
|
|
|
|
|
for rx, p in zip(rxs, self.multi_params):
|
|
|
|
self.verify_decrypted(p, [rx])
|
|
|
|
|
|
|
|
tx = []
|
|
|
|
for p in self.multi_params:
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = tx + self.gen_pkts(
|
|
|
|
self.pg1, src=self.pg1.remote_ip4, dst=p.remote_tun_if_host
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
rxs = self.send_and_expect(self.pg1, tx, self.tun_if)
|
|
|
|
|
|
|
|
for rx, p in zip(rxs, self.multi_params):
|
|
|
|
self.verify_encrypted(p, p.vpp_tun_sa, [rx])
|
|
|
|
|
2019-03-20 18:24:43 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunIfEspAll(TemplateIpsec4TunProtect, TemplateIpsec, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Tunnel interface all Algos"""
|
2019-04-11 15:14:07 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
2019-05-16 14:34:55 +02:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-04-11 15:14:07 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunIfEspAll, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
2020-12-23 16:22:28 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2019-04-11 15:14:07 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2020-12-23 16:22:28 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
2019-04-11 15:14:07 +00:00
|
|
|
super(TestIpsec4TunIfEspAll, self).tearDown()
|
|
|
|
|
2019-04-17 16:29:00 -07:00
|
|
|
def rekey(self, p):
|
|
|
|
#
|
|
|
|
# change the key and the SPI
|
|
|
|
#
|
2020-12-23 16:22:28 +00:00
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
p.crypt_key = b"X" + p.crypt_key[1:]
|
2019-04-17 16:29:00 -07:00
|
|
|
p.scapy_tun_spi += 1
|
|
|
|
p.scapy_tun_sa_id += 1
|
|
|
|
p.vpp_tun_spi += 1
|
|
|
|
p.vpp_tun_sa_id += 1
|
|
|
|
p.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
p.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
2019-04-17 16:29:00 -07:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
salt=p.salt,
|
|
|
|
)
|
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
salt=p.salt,
|
|
|
|
)
|
2019-04-17 16:29:00 -07:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
np.tun_sa_out.remove_vpp_config()
|
|
|
|
np.tun_sa_in.remove_vpp_config()
|
2019-04-17 16:29:00 -07:00
|
|
|
self.logger.info(self.vapi.cli("sh ipsec sa"))
|
|
|
|
|
2019-04-11 15:14:07 +00:00
|
|
|
def test_tun_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC tunnel all algos"""
|
2019-04-11 15:14:07 +00:00
|
|
|
|
|
|
|
# foreach VPP crypto engine
|
|
|
|
engines = ["ia32", "ipsecmb", "openssl"]
|
|
|
|
|
|
|
|
# foreach crypto algorithm
|
2022-04-26 19:02:15 +02:00
|
|
|
algos = [
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_GCM_128
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-GCM",
|
|
|
|
"scapy-integ": "NULL",
|
|
|
|
"key": b"JPjyOWBeVEQiMe7h",
|
|
|
|
"salt": 3333,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_GCM_192
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-GCM",
|
|
|
|
"scapy-integ": "NULL",
|
|
|
|
"key": b"JPjyOWBeVEQiMe7hJPjyOWBe",
|
|
|
|
"salt": 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_GCM_256
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-GCM",
|
|
|
|
"scapy-integ": "NULL",
|
|
|
|
"key": b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
|
|
|
|
"salt": 9999,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CBC_128
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA1_96
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-CBC",
|
|
|
|
"scapy-integ": "HMAC-SHA1-96",
|
|
|
|
"salt": 0,
|
|
|
|
"key": b"JPjyOWBeVEQiMe7h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CBC_192
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA_512_256
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-CBC",
|
|
|
|
"scapy-integ": "SHA2-512-256",
|
|
|
|
"salt": 0,
|
|
|
|
"key": b"JPjyOWBeVEQiMe7hJPjyOWBe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CBC_256
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA_256_128
|
|
|
|
),
|
|
|
|
"scapy-crypto": "AES-CBC",
|
|
|
|
"scapy-integ": "SHA2-256-128",
|
|
|
|
"salt": 0,
|
|
|
|
"key": b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vpp-crypto": (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_NONE
|
|
|
|
),
|
|
|
|
"vpp-integ": (
|
|
|
|
VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA1_96
|
|
|
|
),
|
|
|
|
"scapy-crypto": "NULL",
|
|
|
|
"scapy-integ": "HMAC-SHA1-96",
|
|
|
|
"salt": 0,
|
|
|
|
"key": b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h",
|
|
|
|
},
|
|
|
|
]
|
2019-04-11 15:14:07 +00:00
|
|
|
|
|
|
|
for engine in engines:
|
|
|
|
self.vapi.cli("set crypto handler all %s" % engine)
|
|
|
|
|
|
|
|
#
|
|
|
|
# loop through each of the algorithms
|
|
|
|
#
|
|
|
|
for algo in algos:
|
|
|
|
# with self.subTest(algo=algo['scapy']):
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id = algo["vpp-integ"]
|
|
|
|
p.crypt_algo_vpp_id = algo["vpp-crypto"]
|
|
|
|
p.crypt_algo = algo["scapy-crypto"]
|
|
|
|
p.auth_algo = algo["scapy-integ"]
|
|
|
|
p.crypt_key = algo["key"]
|
|
|
|
p.salt = algo["salt"]
|
2019-04-11 15:14:07 +00:00
|
|
|
|
2019-04-17 16:29:00 -07:00
|
|
|
#
|
|
|
|
# rekey the tunnel
|
|
|
|
#
|
|
|
|
self.rekey(p)
|
|
|
|
self.verify_tun_44(p, count=127)
|
|
|
|
|
2019-04-11 15:14:07 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunIfEspNoAlgo(TemplateIpsec4TunProtect, TemplateIpsec, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Tunnel interface no Algos"""
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunIfEspNoAlgo, self).setUp()
|
2019-12-20 00:54:57 +00:00
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
self.tun_if = self.pg0
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id = VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
p.auth_algo = "NULL"
|
2019-12-20 00:54:57 +00:00
|
|
|
p.auth_key = []
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.crypt_algo_vpp_id = (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_NONE
|
|
|
|
)
|
|
|
|
p.crypt_algo = "NULL"
|
2019-12-20 00:54:57 +00:00
|
|
|
p.crypt_key = []
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec4TunIfEspNoAlgo, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSec SA with NULL algos"""
|
2019-12-20 00:54:57 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2019-12-20 00:54:57 +00:00
|
|
|
|
2024-02-12 18:39:21 +00:00
|
|
|
tx = self.gen_pkts(
|
|
|
|
self.pg1, src=self.pg1.remote_ip4, dst=p.remote_tun_if_host, count=127
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
self.send_and_assert_no_replies(self.pg1, tx)
|
|
|
|
|
2020-12-23 16:22:28 +00:00
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
2019-12-20 00:54:57 +00:00
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2024-02-12 18:39:21 +00:00
|
|
|
def test_tun_44_async(self):
|
|
|
|
"""IPSec SA with NULL algos using async crypto"""
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.vapi.ipsec_set_async_mode(async_enable=True)
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
tx = self.gen_pkts(
|
|
|
|
self.pg1, src=self.pg1.remote_ip4, dst=p.remote_tun_if_host, count=127
|
|
|
|
)
|
|
|
|
self.send_and_assert_no_replies(self.pg1, tx)
|
|
|
|
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
self.vapi.ipsec_set_async_mode(async_enable=False)
|
|
|
|
|
2019-12-20 00:54:57 +00:00
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6MultiTunIfEsp(TemplateIpsec6TunProtect, TemplateIpsec, IpsecTun6):
|
|
|
|
"""IPsec IPv6 Multi Tunnel interface"""
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
2019-05-16 14:34:55 +02:00
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6MultiTunIfEsp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
self.multi_params = []
|
2019-09-26 16:20:19 +00:00
|
|
|
self.pg0.generate_remote_hosts(10)
|
|
|
|
self.pg0.configure_ipv6_neighbors()
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
for ii in range(10):
|
|
|
|
p = copy.copy(self.ipv6_params)
|
|
|
|
|
|
|
|
p.remote_tun_if_host = "1111::%d" % (ii + 1)
|
|
|
|
p.scapy_tun_sa_id = p.scapy_tun_sa_id + ii
|
|
|
|
p.scapy_tun_spi = p.scapy_tun_spi + ii
|
|
|
|
p.vpp_tun_sa_id = p.vpp_tun_sa_id + ii
|
|
|
|
p.vpp_tun_spi = p.vpp_tun_spi + ii
|
|
|
|
|
|
|
|
p.scapy_tra_sa_id = p.scapy_tra_sa_id + ii
|
|
|
|
p.scapy_tra_spi = p.scapy_tra_spi + ii
|
|
|
|
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
|
|
|
|
p.vpp_tra_spi = p.vpp_tra_spi + ii
|
2020-12-23 16:22:28 +00:00
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip6
|
2019-03-20 18:24:43 +00:00
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
self.multi_params.append(p)
|
2020-12-23 16:22:28 +00:00
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec6MultiTunIfEsp, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_66(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multiple IPSEC tunnel interfaces"""
|
2019-03-20 18:24:43 +00:00
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_66(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-03-20 18:24:43 +00:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreTebIfEsp(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE TEB ESP - TUN tests"""
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-03-29 20:23:58 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
omac = "00:11:22:33:44:55"
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-03-29 20:23:58 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.omac)
|
|
|
|
self.assert_equal(rx[IP].dst, "1.1.1.2")
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[Ether]
|
|
|
|
self.assertEqual(e[Ether].dst, self.omac)
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
2019-02-07 07:26:12 -08:00
|
|
|
super(TestIpsecGreTebIfEsp, self).setUp()
|
2019-03-29 20:23:58 +00:00
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
)
|
2019-03-29 20:23:58 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
)
|
2019-03-29 20:23:58 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_TEB),
|
|
|
|
)
|
2019-09-26 16:20:19 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
2019-03-29 20:23:58 +00:00
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
|
2019-03-29 20:23:58 +00:00
|
|
|
VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
self.vapi.cli("clear ipsec sa")
|
2019-12-16 00:53:11 +00:00
|
|
|
self.vapi.cli("sh adj")
|
|
|
|
self.vapi.cli("sh ipsec tun")
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2019-03-29 20:23:58 +00:00
|
|
|
def tearDown(self):
|
2019-09-26 16:20:19 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
2019-02-07 07:26:12 -08:00
|
|
|
super(TestIpsecGreTebIfEsp, self).tearDown()
|
2019-03-29 20:23:58 +00:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreTebVlanIfEsp(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE TEB ESP - TUN tests"""
|
|
|
|
|
2020-01-31 23:48:30 -05:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2020-01-31 23:48:30 -05:00
|
|
|
encryption_type = ESP
|
|
|
|
omac = "00:11:22:33:44:55"
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(dst=self.omac)
|
|
|
|
/ Dot1Q(vlan=11)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2020-01-31 23:48:30 -05:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.omac)
|
|
|
|
self.assert_equal(rx[Dot1Q].vlan, 11)
|
|
|
|
self.assert_equal(rx[IP].dst, "1.1.1.2")
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[Ether]
|
|
|
|
self.assertEqual(e[Ether].dst, self.omac)
|
|
|
|
self.assertFalse(e.haslayer(Dot1Q))
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGreTebVlanIfEsp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
|
|
|
self.pg1_11 = VppDot1QSubint(self, self.pg1, 11)
|
|
|
|
self.vapi.l2_interface_vlan_tag_rewrite(
|
2022-04-26 19:02:15 +02:00
|
|
|
sw_if_index=self.pg1_11.sw_if_index,
|
|
|
|
vtr_op=L2_VTR_OP.L2_POP_1,
|
|
|
|
push_dot1q=11,
|
|
|
|
)
|
2020-01-31 23:48:30 -05:00
|
|
|
self.pg1_11.admin_up()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
)
|
2020-01-31 23:48:30 -05:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
)
|
2020-01-31 23:48:30 -05:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_TEB),
|
|
|
|
)
|
2020-01-31 23:48:30 -05:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-01-31 23:48:30 -05:00
|
|
|
|
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
|
|
|
VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
|
|
|
|
VppBridgeDomainPort(self, bd1, self.pg1_11).add_vpp_config()
|
|
|
|
|
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecGreTebVlanIfEsp, self).tearDown()
|
|
|
|
self.pg1_11.admin_down()
|
|
|
|
self.pg1_11.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreTebIfEspTra(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE TEB ESP - Tra tests"""
|
|
|
|
|
2019-12-18 05:54:40 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-18 05:54:40 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
omac = "00:11:22:33:44:55"
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-18 05:54:40 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.omac)
|
|
|
|
self.assert_equal(rx[IP].dst, "1.1.1.2")
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[Ether]
|
|
|
|
self.assertEqual(e[Ether].dst, self.omac)
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGreTebIfEspTra, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_TEB),
|
|
|
|
)
|
2019-12-18 05:54:40 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2019-12-18 05:54:40 +00:00
|
|
|
|
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
|
|
|
VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
|
|
|
|
VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
|
|
|
|
|
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecGreTebIfEspTra, self).tearDown()
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreTebUdpIfEspTra(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE TEB UDP ESP - Tra tests"""
|
|
|
|
|
2020-04-01 09:45:23 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2020-04-01 09:45:23 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
omac = "00:11:22:33:44:55"
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(dst=self.omac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2020-04-01 09:45:23 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.omac)
|
|
|
|
self.assert_equal(rx[IP].dst, "1.1.1.2")
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assertTrue(rx.haslayer(UDP))
|
|
|
|
self.assertEqual(rx[UDP].dport, 4545)
|
|
|
|
self.assertEqual(rx[UDP].sport, 5454)
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[Ether]
|
|
|
|
self.assertEqual(e[Ether].dst, self.omac)
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGreTebUdpIfEspTra, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.flags = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_UDP_ENCAP
|
2020-04-01 09:45:23 +00:00
|
|
|
p.nat_header = UDP(sport=5454, dport=4545)
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=p.flags,
|
|
|
|
udp_src=5454,
|
|
|
|
udp_dst=4545,
|
|
|
|
)
|
2020-04-01 09:45:23 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
flags=(
|
|
|
|
p.flags | VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_IS_INBOUND
|
|
|
|
),
|
|
|
|
udp_src=4545,
|
|
|
|
udp_dst=5454,
|
|
|
|
)
|
2020-04-01 09:45:23 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_TEB),
|
|
|
|
)
|
2020-04-01 09:45:23 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-04-01 09:45:23 +00:00
|
|
|
|
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
|
|
|
VppBridgeDomainPort(self, bd1, p.tun_if).add_vpp_config()
|
|
|
|
VppBridgeDomainPort(self, bd1, self.pg1).add_vpp_config()
|
|
|
|
|
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
self.logger.info(self.vapi.cli("sh ipsec sa 0"))
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecGreTebUdpIfEspTra, self).tearDown()
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreIfEsp(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE ESP - TUN tests"""
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-02-07 07:26:12 -08:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ IP(src=self.pg1.local_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[GRE]
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGreIfEsp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
)
|
2019-02-07 07:26:12 -08:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
)
|
2019-02-07 07:26:12 -08:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2019-09-26 16:20:19 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2019-02-07 07:26:12 -08:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
2019-09-26 16:20:19 +00:00
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
config_tun_params(p, self.encryption_type, p.tun_if)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
VppIpRoute(
|
|
|
|
self, "1.1.1.2", 32, [VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)]
|
|
|
|
).add_vpp_config()
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def tearDown(self):
|
2019-09-26 16:20:19 +00:00
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
2019-02-07 07:26:12 -08:00
|
|
|
super(TestIpsecGreIfEsp, self).tearDown()
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGreIfEspTra(TemplateIpsec, IpsecTun4Tests):
|
|
|
|
"""Ipsec GRE ESP - TRA tests"""
|
|
|
|
|
2019-12-02 22:32:05 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-02 22:32:05 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ IP(src=self.pg1.local_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_encrypt_non_ip_pkts(self, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-02 22:32:05 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[GRE]
|
|
|
|
self.assertEqual(e[IP].dst, "1.1.1.2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGreIfEspTra, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-02 22:32:05 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-02 22:32:05 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2019-12-02 22:32:05 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2019-12-02 22:32:05 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
2019-12-18 05:54:40 +00:00
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
2019-12-02 22:32:05 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
VppIpRoute(
|
|
|
|
self, "1.1.1.2", 32, [VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)]
|
|
|
|
).add_vpp_config()
|
2019-12-02 22:32:05 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecGreIfEspTra, self).tearDown()
|
|
|
|
|
2019-12-20 00:54:57 +00:00
|
|
|
def test_gre_non_ip(self):
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = self.gen_encrypt_non_ip_pkts(
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip6,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
self.send_and_assert_no_replies(self.tun_if, tx)
|
2022-08-09 03:34:51 +00:00
|
|
|
node_name = "/err/%s/unsup_payload" % self.tun4_decrypt_node_name[0]
|
2019-12-20 00:54:57 +00:00
|
|
|
self.assertEqual(1, self.statistics.get_err_counter(node_name))
|
2022-11-16 19:12:05 +01:00
|
|
|
err = p.tun_sa_in.get_err("unsup_payload")
|
|
|
|
self.assertEqual(err, 1)
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecGre6IfEspTra(TemplateIpsec, IpsecTun6Tests):
|
|
|
|
"""Ipsec GRE ESP - TRA tests"""
|
|
|
|
|
2019-12-20 00:54:57 +00:00
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-12-20 00:54:57 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
|
|
|
|
/ GRE()
|
|
|
|
/ IPv6(src=self.pg1.local_ip6, dst=self.pg1.remote_ip6)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts6(self, p, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IPv6(src="1::1", dst="1::2")
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
def verify_decrypted6(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
|
|
|
|
|
|
|
|
def verify_encrypted6(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IPv6])
|
|
|
|
if not pkt.haslayer(IPv6):
|
|
|
|
pkt = IPv6(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[GRE]
|
|
|
|
self.assertEqual(e[IPv6].dst, "1::2")
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecGre6IfEspTra, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
|
|
|
|
bd1 = VppBridgeDomain(self, 1)
|
|
|
|
bd1.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(self, self.pg0.local_ip6, self.pg0.remote_ip6)
|
2019-12-20 00:54:57 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2019-12-20 00:54:57 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppIpRoute(
|
|
|
|
self,
|
|
|
|
"1::2",
|
|
|
|
128,
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, 0xFFFFFFFF, proto=DpoProto.DPO_PROTO_IP6
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
r.add_vpp_config()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv6_params
|
|
|
|
p.tun_if.unconfig_ip6()
|
|
|
|
super(TestIpsecGre6IfEspTra, self).tearDown()
|
|
|
|
|
2019-12-02 22:32:05 +00:00
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
class TestIpsecMGreIfEspTra4(TemplateIpsec, IpsecTun4):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec mGRE ESP v4 TRA tests"""
|
|
|
|
|
2019-12-16 00:53:11 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-16 00:53:11 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=p.tun_dst, dst=self.pg0.local_ip4)
|
|
|
|
/ GRE()
|
|
|
|
/ IP(src=self.pg1.local_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IP(src="1.1.1.1", dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-16 00:53:11 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[GRE]
|
|
|
|
self.assertEqual(e[IP].dst, p.remote_tun_if_host)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecMGreIfEspTra4, self).setUp()
|
|
|
|
|
|
|
|
N_NHS = 16
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
"0.0.0.0",
|
|
|
|
mode=(VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_MP),
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
p.tun_if.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.configure_ipv4_neighbors()
|
|
|
|
|
|
|
|
# setup some SAs for several next-hops on the interface
|
|
|
|
self.multi_params = []
|
|
|
|
|
2020-10-19 09:59:41 +00:00
|
|
|
for ii in range(N_NHS):
|
2019-12-16 00:53:11 +00:00
|
|
|
p = copy.copy(self.ipv4_params)
|
|
|
|
|
|
|
|
p.remote_tun_if_host = "1.1.1.%d" % (ii + 1)
|
|
|
|
p.scapy_tun_sa_id = p.scapy_tun_sa_id + ii
|
|
|
|
p.scapy_tun_spi = p.scapy_tun_spi + ii
|
|
|
|
p.vpp_tun_sa_id = p.vpp_tun_sa_id + ii
|
|
|
|
p.vpp_tun_spi = p.vpp_tun_spi + ii
|
|
|
|
|
|
|
|
p.scapy_tra_sa_id = p.scapy_tra_sa_id + ii
|
|
|
|
p.scapy_tra_spi = p.scapy_tra_spi + ii
|
|
|
|
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
|
|
|
|
p.vpp_tra_spi = p.vpp_tra_spi + ii
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_protect = VppIpsecTunProtect(
|
|
|
|
self,
|
|
|
|
p.tun_if,
|
|
|
|
p.tun_sa_out,
|
|
|
|
[p.tun_sa_in],
|
2022-04-26 19:02:15 +02:00
|
|
|
nh=p.tun_if.remote_hosts[ii].ip4,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
|
|
|
self.multi_params.append(p)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_hosts[ii].ip4, p.tun_if.sw_if_index)],
|
|
|
|
).add_vpp_config()
|
2019-12-16 00:53:11 +00:00
|
|
|
|
|
|
|
# in this v4 variant add the teibs after the protect
|
2022-04-26 19:02:15 +02:00
|
|
|
p.teib = VppTeib(
|
|
|
|
self,
|
|
|
|
p.tun_if,
|
|
|
|
p.tun_if.remote_hosts[ii].ip4,
|
|
|
|
self.pg0.remote_hosts[ii].ip4,
|
|
|
|
).add_vpp_config()
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip4
|
|
|
|
self.logger.info(self.vapi.cli("sh ipsec protect-hash"))
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecMGreIfEspTra4, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
|
|
|
"""mGRE IPSEC 44"""
|
|
|
|
N_PKTS = 63
|
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_44(p, count=N_PKTS)
|
|
|
|
p.teib.remove_vpp_config()
|
|
|
|
self.verify_tun_dropped_44(p, count=N_PKTS)
|
|
|
|
p.teib.add_vpp_config()
|
|
|
|
self.verify_tun_44(p, count=N_PKTS)
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"gre" in config.excluded_plugins, "Exclude tests depending on GRE plugin"
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
class TestIpsecMGreIfEspTra6(TemplateIpsec, IpsecTun6):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec mGRE ESP v6 TRA tests"""
|
|
|
|
|
2019-12-16 00:53:11 +00:00
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-12-16 00:53:11 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IPv6(src=p.tun_dst, dst=self.pg0.local_ip6)
|
|
|
|
/ GRE()
|
|
|
|
/ IPv6(src=self.pg1.local_ip6, dst=self.pg1.remote_ip6)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts6(self, p, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IPv6(src="1::1", dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-16 00:53:11 +00:00
|
|
|
|
|
|
|
def verify_decrypted6(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
|
|
|
|
|
|
|
|
def verify_encrypted6(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IPv6])
|
|
|
|
if not pkt.haslayer(IPv6):
|
|
|
|
pkt = IPv6(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assertTrue(pkt.haslayer(GRE))
|
|
|
|
e = pkt[GRE]
|
|
|
|
self.assertEqual(e[IPv6].dst, p.remote_tun_if_host)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecMGreIfEspTra6, self).setUp()
|
|
|
|
|
|
|
|
self.vapi.cli("set logging class ipsec level debug")
|
|
|
|
|
|
|
|
N_NHS = 16
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
p = self.ipv6_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppGreInterface(
|
|
|
|
self,
|
|
|
|
self.pg0.local_ip6,
|
|
|
|
"::",
|
|
|
|
mode=(VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_MP),
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
p.tun_if.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.configure_ipv6_neighbors()
|
|
|
|
|
|
|
|
# setup some SAs for several next-hops on the interface
|
|
|
|
self.multi_params = []
|
|
|
|
|
|
|
|
for ii in range(N_NHS):
|
|
|
|
p = copy.copy(self.ipv6_params)
|
|
|
|
|
|
|
|
p.remote_tun_if_host = "1::%d" % (ii + 1)
|
|
|
|
p.scapy_tun_sa_id = p.scapy_tun_sa_id + ii
|
|
|
|
p.scapy_tun_spi = p.scapy_tun_spi + ii
|
|
|
|
p.vpp_tun_sa_id = p.vpp_tun_sa_id + ii
|
|
|
|
p.vpp_tun_spi = p.vpp_tun_spi + ii
|
|
|
|
|
|
|
|
p.scapy_tra_sa_id = p.scapy_tra_sa_id + ii
|
|
|
|
p.scapy_tra_spi = p.scapy_tra_spi + ii
|
|
|
|
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
|
|
|
|
p.vpp_tra_spi = p.vpp_tra_spi + ii
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
# in this v6 variant add the teibs first then the protection
|
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip6
|
2022-04-26 19:02:15 +02:00
|
|
|
VppTeib(
|
|
|
|
self, p.tun_if, p.tun_if.remote_hosts[ii].ip6, p.tun_dst
|
|
|
|
).add_vpp_config()
|
2019-12-16 00:53:11 +00:00
|
|
|
|
|
|
|
p.tun_protect = VppIpsecTunProtect(
|
|
|
|
self,
|
|
|
|
p.tun_if,
|
|
|
|
p.tun_sa_out,
|
|
|
|
[p.tun_sa_in],
|
2022-04-26 19:02:15 +02:00
|
|
|
nh=p.tun_if.remote_hosts[ii].ip6,
|
|
|
|
)
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
config_tra_params(p, self.encryption_type, p.tun_if)
|
|
|
|
self.multi_params.append(p)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
128,
|
|
|
|
[VppRoutePath(p.tun_if.remote_hosts[ii].ip6, p.tun_if.sw_if_index)],
|
|
|
|
).add_vpp_config()
|
2019-12-16 00:53:11 +00:00
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip6
|
|
|
|
|
|
|
|
self.logger.info(self.vapi.cli("sh log"))
|
|
|
|
self.logger.info(self.vapi.cli("sh ipsec protect-hash"))
|
|
|
|
self.logger.info(self.vapi.cli("sh adj 41"))
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv6_params
|
|
|
|
p.tun_if.unconfig_ip6()
|
|
|
|
super(TestIpsecMGreIfEspTra6, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_66(self):
|
|
|
|
"""mGRE IPSec 66"""
|
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_66(p, count=63)
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunProtect(TemplateIpsec, TemplateIpsec4TunProtect, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Tunnel protect - transport mode"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunProtect, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec4TunProtect, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
|
|
|
"""IPSEC tunnel protect"""
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2019-09-27 13:32:02 +00:00
|
|
|
self.vapi.cli("clear ipsec sa")
|
|
|
|
self.verify_tun_64(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 254)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 254)
|
2019-09-27 13:32:02 +00:00
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2019-02-07 07:26:12 -08:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
|
|
|
self.config_sa_tra(np)
|
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(np, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 381)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 381)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np)
|
|
|
|
self.unconfig_sa(np)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
@tag_fixme_vpp_workers
|
|
|
|
class TestIpsec4TunProtectTfc(TemplateIpsec4TunTfc, TestIpsec4TunProtect):
|
|
|
|
"""IPsec IPv4 Tunnel protect with TFC - transport mode"""
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunProtectUdp(TemplateIpsec, TemplateIpsec4TunProtect, IpsecTun4):
|
2023-06-16 09:48:52 +02:00
|
|
|
"""IPsec IPv4 UDP Tunnel protect - transport mode"""
|
2019-07-16 06:19:35 -07:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunProtectUdp, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.flags = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_UDP_ENCAP
|
2020-04-01 09:45:23 +00:00
|
|
|
p.nat_header = UDP(sport=4500, dport=4500)
|
2019-07-16 06:19:35 -07:00
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
super(TestIpsec4TunProtectUdp, self).tearDown()
|
|
|
|
|
2020-04-01 09:45:23 +00:00
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
# ensure encrypted packets are recieved with the default UDP ports
|
|
|
|
for rx in rxs:
|
|
|
|
self.assertEqual(rx[UDP].sport, 4500)
|
|
|
|
self.assertEqual(rx[UDP].dport, 4500)
|
|
|
|
super(TestIpsec4TunProtectUdp, self).verify_encrypted(p, sa, rxs)
|
|
|
|
|
2019-07-16 06:19:35 -07:00
|
|
|
def test_tun_44(self):
|
|
|
|
"""IPSEC UDP tunnel protect"""
|
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.verify_tun_44(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-07-16 06:19:35 -07:00
|
|
|
|
|
|
|
def test_keepalive(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC NAT Keepalive"""
|
2019-07-16 06:19:35 -07:00
|
|
|
self.verify_keepalive(self.ipv4_params)
|
|
|
|
|
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
@tag_fixme_vpp_workers
|
|
|
|
class TestIpsec4TunProtectUdpTfc(TemplateIpsec4TunTfc, TestIpsec4TunProtectUdp):
|
|
|
|
"""IPsec IPv4 UDP Tunnel protect with TFC - transport mode"""
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"acl" in config.excluded_plugins, "Exclude tests depending on ACL plugin"
|
|
|
|
)
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunProtectTun(TemplateIpsec, TemplateIpsec4TunProtect, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Tunnel protect - tunnel mode"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunProtectTun, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec4TunProtectTun, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=sw_intf.remote_ip4, dst=sw_intf.local_ip4)
|
|
|
|
/ IP(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IP(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
self.assert_equal(rx[IP].src, p.remote_tun_if_host)
|
|
|
|
self.assert_packet_checksums_valid(rx)
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
self.assert_equal(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
inner = pkt[IP].payload
|
|
|
|
self.assertEqual(inner[IP][IP].dst, p.remote_tun_if_host)
|
|
|
|
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC tunnel protect"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tun(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
2020-05-12 08:51:02 +00:00
|
|
|
# also add an output features on the tunnel and physical interface
|
|
|
|
# so we test they still work
|
2022-04-26 19:02:15 +02:00
|
|
|
r_all = AclRule(True, src_prefix="0.0.0.0/0", dst_prefix="0.0.0.0/0", proto=0)
|
2020-05-12 08:51:02 +00:00
|
|
|
a = VppAcl(self, [r_all]).add_vpp_config()
|
|
|
|
|
|
|
|
VppAclInterface(self, self.pg0.sw_if_index, [a]).add_vpp_config()
|
|
|
|
VppAclInterface(self, p.tun_if.sw_if_index, [a]).add_vpp_config()
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
self.verify_tun_44(p, count=127)
|
|
|
|
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2019-02-07 07:26:12 -08:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
|
|
|
self.config_sa_tun(np)
|
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(np, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 254)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 254)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np)
|
|
|
|
self.unconfig_sa(np)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec4TunProtectTunDrop(TemplateIpsec, TemplateIpsec4TunProtect, IpsecTun4):
|
|
|
|
"""IPsec IPv4 Tunnel protect - tunnel mode - drop"""
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec4TunProtectTunDrop, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec4TunProtectTunDrop, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=sw_intf.remote_ip4, dst="5.5.5.5")
|
|
|
|
/ IP(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
def test_tun_drop_44(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC tunnel protect bogus tunnel header"""
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tun(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = self.gen_encrypt_pkts(
|
|
|
|
p,
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip4,
|
|
|
|
count=63,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
self.send_and_assert_no_replies(self.tun_if, tx)
|
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6TunProtect(TemplateIpsec, TemplateIpsec6TunProtect, IpsecTun6):
|
|
|
|
"""IPsec IPv6 Tunnel protect - transport mode"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6TunProtect, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec6TunProtect, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_66(self):
|
2019-12-20 00:54:57 +00:00
|
|
|
"""IPSEC tunnel protect 6o6"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2019-02-07 07:26:12 -08:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
|
|
|
self.config_sa_tra(np)
|
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(np, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 254)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 254)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2019-12-20 00:54:57 +00:00
|
|
|
# bounce the interface state
|
|
|
|
p.tun_if.admin_down()
|
|
|
|
self.verify_drop_tun_66(np, count=127)
|
2022-08-09 03:34:51 +00:00
|
|
|
node = "/err/ipsec6-tun-input/disabled"
|
2019-12-20 00:54:57 +00:00
|
|
|
self.assertEqual(127, self.statistics.get_err_counter(node))
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
self.verify_tun_66(np, count=127)
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
# 3 phase rekey
|
|
|
|
# 1) add two input SAs [old, new]
|
|
|
|
# 2) swap output SA to [new]
|
|
|
|
# 3) use only [new] input SA
|
|
|
|
np3 = copy.copy(np)
|
2022-04-26 19:02:15 +02:00
|
|
|
np3.crypt_key = b"Z" + p.crypt_key[1:]
|
2019-02-07 07:26:12 -08:00
|
|
|
np3.scapy_tun_spi += 100
|
|
|
|
np3.scapy_tun_sa_id += 1
|
|
|
|
np3.vpp_tun_spi += 100
|
|
|
|
np3.vpp_tun_sa_id += 1
|
|
|
|
np3.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np3.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
|
|
|
self.config_sa_tra(np3)
|
|
|
|
|
|
|
|
# step 1;
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect.update_vpp_config(np.tun_sa_out, [np.tun_sa_in, np3.tun_sa_in])
|
2019-02-07 07:26:12 -08:00
|
|
|
self.verify_tun_66(np, np, count=127)
|
|
|
|
self.verify_tun_66(np3, np, count=127)
|
|
|
|
|
|
|
|
# step 2;
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect.update_vpp_config(np3.tun_sa_out, [np.tun_sa_in, np3.tun_sa_in])
|
2019-02-07 07:26:12 -08:00
|
|
|
self.verify_tun_66(np, np3, count=127)
|
|
|
|
self.verify_tun_66(np3, np3, count=127)
|
|
|
|
|
|
|
|
# step 1;
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect.update_vpp_config(np3.tun_sa_out, [np3.tun_sa_in])
|
2019-02-07 07:26:12 -08:00
|
|
|
self.verify_tun_66(np3, np3, count=127)
|
ipsec: IPSec interface correct drop w/ no protection
Type: improvement
When an IPSec interface is first constructed, the end node of the feature arc is not changed, which means it is interface-output.
This means that traffic directed into adjacencies on the link, that do not have protection (w/ an SA), drop like this:
...
00:00:01:111710: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:6 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111829: local0-output
ipsec0
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 5858585858585858585858585858585858585858585858585858585858585858
00000040: 58585858585858585858585858585858585858585858585858585858c2cf08c0
00000060: 2a2c103cd0126bd8b03c4ec20ce2bd02dd77b3e3a4f49664
00:00:01:112017: error-drop
rx:pg1
00:00:01:112034: drop
local0-output: interface is down
although that's a drop, no packets should go to local0, and we want all IPvX packets to go through ipX-drop.
This change sets the interface's end-arc node to the appropriate drop node when the interface is created, and when the last protection is removed.
The resulting drop is:
...
00:00:01:111504: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:0 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111533: ip4-drop
ICMP: 172.16.2.2 -> 1.1.1.1
tos 0x00, ttl 63, length 92, checksum 0xcb8c dscp CS0 ecn NON_ECN
fragment id 0x0001
ICMP echo_request checksum 0xecf4 id 0
00:00:01:111620: error-drop
rx:pg1
00:00:01:111640: drop
null-node: blackholed packets
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I7e7de23c541d9f1210a05e6984a688f1f821a155
2022-01-10 10:38:43 +00:00
|
|
|
self.verify_drop_tun_rx_66(np, count=127)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127 * 9)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127 * 8)
|
2019-02-07 07:26:12 -08:00
|
|
|
self.unconfig_sa(np)
|
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np3)
|
|
|
|
self.unconfig_sa(np3)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2019-09-27 13:32:02 +00:00
|
|
|
def test_tun_46(self):
|
2019-12-20 00:54:57 +00:00
|
|
|
"""IPSEC tunnel protect 4o6"""
|
2019-09-27 13:32:02 +00:00
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tra(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_46(p, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-09-27 13:32:02 +00:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2019-02-07 07:26:12 -08:00
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
@tag_fixme_vpp_workers
|
|
|
|
class TestIpsec6TunProtectTfc(TemplateIpsec6TunTfc, TestIpsec6TunProtect):
|
|
|
|
"""IPsec IPv6 Tunnel protect with TFC - transport mode"""
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6TunProtectTun(TemplateIpsec, TemplateIpsec6TunProtect, IpsecTun6):
|
|
|
|
"""IPsec IPv6 Tunnel protect - tunnel mode"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6TunProtectTun, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec6TunProtectTun, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IPv6(src=sw_intf.remote_ip6, dst=sw_intf.local_ip6)
|
|
|
|
/ IPv6(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1166, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts6(self, p, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IPv6(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1166, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
def verify_decrypted6(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[IPv6].dst, self.pg1.remote_ip6)
|
|
|
|
self.assert_equal(rx[IPv6].src, p.remote_tun_if_host)
|
|
|
|
self.assert_packet_checksums_valid(rx)
|
|
|
|
|
|
|
|
def verify_encrypted6(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IPv6])
|
|
|
|
if not pkt.haslayer(IPv6):
|
|
|
|
pkt = IPv6(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[IPv6].dst, self.pg0.remote_ip6)
|
|
|
|
self.assert_equal(pkt[IPv6].src, self.pg0.local_ip6)
|
|
|
|
inner = pkt[IPv6].payload
|
|
|
|
self.assertEqual(inner[IPv6][IPv6].dst, p.remote_tun_if_host)
|
|
|
|
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_tun_66(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC tunnel protect"""
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tun(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(p, count=127)
|
|
|
|
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 127)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 127)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2019-02-07 07:26:12 -08:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
|
|
|
self.config_sa_tun(np)
|
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(np, count=127)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 254)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 254)
|
2019-02-07 07:26:12 -08:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np)
|
|
|
|
self.unconfig_sa(np)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2019-03-29 20:23:58 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsec6TunProtectTunDrop(TemplateIpsec, TemplateIpsec6TunProtect, IpsecTun6):
|
|
|
|
"""IPsec IPv6 Tunnel protect - tunnel mode - drop"""
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsec6TunProtectTunDrop, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsec6TunProtectTunDrop, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
2019-12-20 00:54:57 +00:00
|
|
|
# the IP destination of the revelaed packet does not match
|
|
|
|
# that assigned to the tunnel
|
2022-04-26 19:02:15 +02:00
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IPv6(src=sw_intf.remote_ip6, dst="5::5")
|
|
|
|
/ IPv6(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
def test_tun_drop_66(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPSEC 6 tunnel protect bogus tunnel header"""
|
2019-12-20 00:54:57 +00:00
|
|
|
|
|
|
|
p = self.ipv6_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
self.config_sa_tun(p)
|
|
|
|
self.config_protect(p)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = self.gen_encrypt_pkts6(
|
|
|
|
p,
|
|
|
|
p.scapy_tun_sa,
|
|
|
|
self.tun_if,
|
|
|
|
src=p.remote_tun_if_host,
|
|
|
|
dst=self.pg1.remote_ip6,
|
|
|
|
count=63,
|
|
|
|
)
|
2019-12-20 00:54:57 +00:00
|
|
|
self.send_and_assert_no_replies(self.tun_if, tx)
|
|
|
|
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
class TemplateIpsecItf4(object):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPsec Interface IPv4"""
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2020-06-30 07:47:14 +00:00
|
|
|
tun4_input_node = "ipsec4-tun-input"
|
|
|
|
|
|
|
|
def config_sa_tun(self, p, src, dst):
|
|
|
|
config_tun_params(p, self.encryption_type, None, src, dst)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
src,
|
|
|
|
dst,
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
dst,
|
|
|
|
src,
|
2022-08-31 19:13:03 +02:00
|
|
|
flags=p.flags
|
|
|
|
| VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_IS_INBOUND,
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def config_protect(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def config_network(self, p, instance=0xFFFFFFFF):
|
2020-10-13 20:02:11 -04:00
|
|
|
p.tun_if = VppIpsecInterface(self, instance=instance)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.route = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)],
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.route.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host6,
|
|
|
|
128,
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, 0xFFFFFFFF, proto=DpoProto.DPO_PROTO_IP6
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
r.add_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_network(self, p):
|
|
|
|
p.route.remove_vpp_config()
|
|
|
|
p.tun_if.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_protect(self, p):
|
|
|
|
p.tun_protect.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_sa(self, p):
|
|
|
|
p.tun_sa_out.remove_vpp_config()
|
|
|
|
p.tun_sa_in.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecItf4(TemplateIpsec, TemplateIpsecItf4, IpsecTun4):
|
|
|
|
"""IPsec Interface IPv4"""
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecItf4, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsecItf4, self).tearDown()
|
|
|
|
|
2020-10-13 20:02:11 -04:00
|
|
|
def test_tun_instance_44(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
self.config_network(p, instance=3)
|
|
|
|
|
|
|
|
with self.assertRaises(CliFailedCommandError):
|
|
|
|
self.vapi.cli("show interface ipsec0")
|
|
|
|
|
|
|
|
output = self.vapi.cli("show interface ipsec3")
|
|
|
|
self.assertTrue("unknown" not in output)
|
|
|
|
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
def test_tun_44(self):
|
|
|
|
"""IPSEC interface IPv4"""
|
|
|
|
|
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
config_tun_params(
|
|
|
|
p, self.encryption_type, None, self.pg0.local_ip4, self.pg0.remote_ip4
|
|
|
|
)
|
ipsec: IPSec interface correct drop w/ no protection
Type: improvement
When an IPSec interface is first constructed, the end node of the feature arc is not changed, which means it is interface-output.
This means that traffic directed into adjacencies on the link, that do not have protection (w/ an SA), drop like this:
...
00:00:01:111710: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:6 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111829: local0-output
ipsec0
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 5858585858585858585858585858585858585858585858585858585858585858
00000040: 58585858585858585858585858585858585858585858585858585858c2cf08c0
00000060: 2a2c103cd0126bd8b03c4ec20ce2bd02dd77b3e3a4f49664
00:00:01:112017: error-drop
rx:pg1
00:00:01:112034: drop
local0-output: interface is down
although that's a drop, no packets should go to local0, and we want all IPvX packets to go through ipX-drop.
This change sets the interface's end-arc node to the appropriate drop node when the interface is created, and when the last protection is removed.
The resulting drop is:
...
00:00:01:111504: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:0 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111533: ip4-drop
ICMP: 172.16.2.2 -> 1.1.1.1
tos 0x00, ttl 63, length 92, checksum 0xcb8c dscp CS0 ecn NON_ECN
fragment id 0x0001
ICMP echo_request checksum 0xecf4 id 0
00:00:01:111620: error-drop
rx:pg1
00:00:01:111640: drop
null-node: blackholed packets
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I7e7de23c541d9f1210a05e6984a688f1f821a155
2022-01-10 10:38:43 +00:00
|
|
|
self.verify_tun_dropped_44(p, count=n_pkts)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2020-06-30 07:47:14 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
p.tun_if.admin_down()
|
|
|
|
self.verify_tun_dropped_44(p, count=n_pkts)
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 3 * n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 2 * n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
# it's a v6 packet when its encrypted
|
|
|
|
self.tun4_encrypt_node_name = "esp6-encrypt-tun"
|
|
|
|
|
|
|
|
self.verify_tun_64(p, count=n_pkts)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 4 * n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 3 * n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
self.tun4_encrypt_node_name = "esp4-encrypt-tun"
|
|
|
|
|
2022-08-31 19:13:03 +02:00
|
|
|
# update the SA tunnel
|
|
|
|
config_tun_params(
|
|
|
|
p, self.encryption_type, None, self.pg2.local_ip4, self.pg2.remote_ip4
|
|
|
|
)
|
|
|
|
p.tun_sa_in.update_vpp_config(
|
|
|
|
is_tun=True, tun_src=self.pg2.remote_ip4, tun_dst=self.pg2.local_ip4
|
|
|
|
)
|
|
|
|
p.tun_sa_out.update_vpp_config(
|
|
|
|
is_tun=True, tun_src=self.pg2.local_ip4, tun_dst=self.pg2.remote_ip4
|
|
|
|
)
|
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 5 * n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 4 * n_pkts)
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
self.vapi.cli("clear interfaces")
|
|
|
|
|
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2020-06-30 07:47:14 +00:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(np, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2020-06-30 07:47:14 +00:00
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(np, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np)
|
|
|
|
self.unconfig_sa(np)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2020-10-07 13:58:56 +00:00
|
|
|
def test_tun_44_null(self):
|
|
|
|
"""IPSEC interface IPv4 NULL auth/crypto"""
|
|
|
|
|
|
|
|
n_pkts = 127
|
|
|
|
p = copy.copy(self.ipv4_params)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id = VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_NONE
|
|
|
|
p.crypt_algo_vpp_id = (
|
|
|
|
VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_NONE
|
|
|
|
)
|
2020-10-07 13:58:56 +00:00
|
|
|
p.crypt_algo = "NULL"
|
|
|
|
p.auth_algo = "NULL"
|
|
|
|
|
|
|
|
self.config_network(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2020-10-07 13:58:56 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
ipsec: IPSec interface correct drop w/ no protection
Type: improvement
When an IPSec interface is first constructed, the end node of the feature arc is not changed, which means it is interface-output.
This means that traffic directed into adjacencies on the link, that do not have protection (w/ an SA), drop like this:
...
00:00:01:111710: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:6 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111829: local0-output
ipsec0
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 5858585858585858585858585858585858585858585858585858585858585858
00000040: 58585858585858585858585858585858585858585858585858585858c2cf08c0
00000060: 2a2c103cd0126bd8b03c4ec20ce2bd02dd77b3e3a4f49664
00:00:01:112017: error-drop
rx:pg1
00:00:01:112034: drop
local0-output: interface is down
although that's a drop, no packets should go to local0, and we want all IPvX packets to go through ipX-drop.
This change sets the interface's end-arc node to the appropriate drop node when the interface is created, and when the last protection is removed.
The resulting drop is:
...
00:00:01:111504: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:0 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111533: ip4-drop
ICMP: 172.16.2.2 -> 1.1.1.1
tos 0x00, ttl 63, length 92, checksum 0xcb8c dscp CS0 ecn NON_ECN
fragment id 0x0001
ICMP echo_request checksum 0xecf4 id 0
00:00:01:111620: error-drop
rx:pg1
00:00:01:111640: drop
null-node: blackholed packets
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I7e7de23c541d9f1210a05e6984a688f1f821a155
2022-01-10 10:38:43 +00:00
|
|
|
self.logger.info(self.vapi.cli("sh ipsec sa"))
|
2020-10-07 13:58:56 +00:00
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
|
|
|
|
2020-10-13 20:02:11 -04:00
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2021-02-22 18:42:24 +00:00
|
|
|
def test_tun_44_police(self):
|
|
|
|
"""IPSEC interface IPv4 with input policer"""
|
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv4_params
|
|
|
|
|
|
|
|
self.config_network(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
action_tx = PolicerAction(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0
|
|
|
|
)
|
|
|
|
policer = VppPolicer(
|
|
|
|
self,
|
|
|
|
"pol1",
|
|
|
|
80,
|
|
|
|
0,
|
|
|
|
1000,
|
|
|
|
0,
|
|
|
|
conform_action=action_tx,
|
|
|
|
exceed_action=action_tx,
|
|
|
|
violate_action=action_tx,
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.add_vpp_config()
|
|
|
|
|
|
|
|
# Start policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
stats = policer.get_stats()
|
|
|
|
|
|
|
|
# Single rate, 2 colour policer - expect conform, violate but no exceed
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
# Stop policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
|
|
|
|
|
|
|
# No new policer stats
|
|
|
|
statsnew = policer.get_stats()
|
|
|
|
self.assertEqual(stats, statsnew)
|
|
|
|
|
|
|
|
# teardown
|
|
|
|
policer.remove_vpp_config()
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
@tag_fixme_vpp_workers
|
|
|
|
class TestIpsecItf4Tfc(TemplateIpsec4TunTfc, TestIpsecItf4):
|
|
|
|
"""IPsec Interface IPv4 with TFC"""
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecItf4MPLS(TemplateIpsec, TemplateIpsecItf4, IpsecTun4):
|
|
|
|
"""IPsec Interface MPLSoIPv4"""
|
2020-12-21 13:19:10 +00:00
|
|
|
|
|
|
|
tun4_encrypt_node_name = "esp-mpls-encrypt-tun"
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecItf4MPLS, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsecItf4MPLS, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
MPLS(label=44, ttl=3)
|
|
|
|
/ IP(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1166, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2020-12-21 13:19:10 +00:00
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[MPLS].label, 44)
|
|
|
|
self.assert_equal(pkt[IP].dst, p.remote_tun_if_host)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_tun_mpls_o_ip4(self):
|
|
|
|
"""IPSEC interface MPLS over IPv4"""
|
|
|
|
|
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv4_params
|
|
|
|
f = FibPathProto
|
|
|
|
|
|
|
|
tbl = VppMplsTable(self, 0)
|
|
|
|
tbl.add_vpp_config()
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
# deag MPLS routes from the tunnel
|
2022-04-26 19:02:15 +02:00
|
|
|
r4 = VppMplsRoute(
|
|
|
|
self, 44, 1, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)]
|
|
|
|
).add_vpp_config()
|
|
|
|
p.route.modify(
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip4, p.tun_if.sw_if_index, labels=[VppMplsLabel(44)]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2020-12-21 13:19:10 +00:00
|
|
|
p.tun_if.enable_mpls()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip4, self.pg0.remote_ip4)
|
2020-12-21 13:19:10 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_44(p, count=n_pkts)
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
p.tun_if.disable_mpls()
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
class TemplateIpsecItf6(object):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPsec Interface IPv6"""
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
encryption_type = ESP
|
|
|
|
tun6_encrypt_node_name = "esp6-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun6_decrypt_node_name = ["esp6-decrypt-tun", "esp6-decrypt-tun-post"]
|
2020-06-30 07:47:14 +00:00
|
|
|
tun6_input_node = "ipsec6-tun-input"
|
|
|
|
|
|
|
|
def config_sa_tun(self, p, src, dst):
|
|
|
|
config_tun_params(p, self.encryption_type, None, src, dst)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if not hasattr(p, "tun_flags"):
|
2021-02-09 14:04:02 +00:00
|
|
|
p.tun_flags = None
|
2022-04-26 19:02:15 +02:00
|
|
|
if not hasattr(p, "hop_limit"):
|
2021-02-09 14:04:02 +00:00
|
|
|
p.hop_limit = 255
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
src,
|
|
|
|
dst,
|
|
|
|
flags=p.flags,
|
|
|
|
tun_flags=p.tun_flags,
|
|
|
|
hop_limit=p.hop_limit,
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
|
|
|
self.vpp_esp_protocol,
|
|
|
|
dst,
|
|
|
|
src,
|
|
|
|
flags=p.flags,
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
def config_protect(self, p):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_protect = VppIpsecTunProtect(self, p.tun_if, p.tun_sa_out, [p.tun_sa_in])
|
2020-06-30 07:47:14 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
|
|
|
|
|
|
|
def config_network(self, p):
|
|
|
|
p.tun_if = VppIpsecInterface(self)
|
|
|
|
|
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
|
|
|
p.tun_if.config_ip6()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host4,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_ip4, 0xFFFFFFFF)],
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
r.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.route = VppIpRoute(
|
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
128,
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, 0xFFFFFFFF, proto=DpoProto.DPO_PROTO_IP6
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2020-06-30 07:47:14 +00:00
|
|
|
p.route.add_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_network(self, p):
|
|
|
|
p.route.remove_vpp_config()
|
|
|
|
p.tun_if.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_protect(self, p):
|
|
|
|
p.tun_protect.remove_vpp_config()
|
|
|
|
|
|
|
|
def unconfig_sa(self, p):
|
|
|
|
p.tun_sa_out.remove_vpp_config()
|
|
|
|
p.tun_sa_in.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2021-01-29 13:17:19 +00:00
|
|
|
@tag_fixme_vpp_workers
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecItf6(TemplateIpsec, TemplateIpsecItf6, IpsecTun6):
|
|
|
|
"""IPsec Interface IPv6"""
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecItf6, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsecItf6, self).tearDown()
|
|
|
|
|
ipsec: IPSec interface correct drop w/ no protection
Type: improvement
When an IPSec interface is first constructed, the end node of the feature arc is not changed, which means it is interface-output.
This means that traffic directed into adjacencies on the link, that do not have protection (w/ an SA), drop like this:
...
00:00:01:111710: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:6 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111829: local0-output
ipsec0
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 5858585858585858585858585858585858585858585858585858585858585858
00000040: 58585858585858585858585858585858585858585858585858585858c2cf08c0
00000060: 2a2c103cd0126bd8b03c4ec20ce2bd02dd77b3e3a4f49664
00:00:01:112017: error-drop
rx:pg1
00:00:01:112034: drop
local0-output: interface is down
although that's a drop, no packets should go to local0, and we want all IPvX packets to go through ipX-drop.
This change sets the interface's end-arc node to the appropriate drop node when the interface is created, and when the last protection is removed.
The resulting drop is:
...
00:00:01:111504: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:0 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111533: ip4-drop
ICMP: 172.16.2.2 -> 1.1.1.1
tos 0x00, ttl 63, length 92, checksum 0xcb8c dscp CS0 ecn NON_ECN
fragment id 0x0001
ICMP echo_request checksum 0xecf4 id 0
00:00:01:111620: error-drop
rx:pg1
00:00:01:111640: drop
null-node: blackholed packets
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I7e7de23c541d9f1210a05e6984a688f1f821a155
2022-01-10 10:38:43 +00:00
|
|
|
def test_tun_66(self):
|
2020-06-30 07:47:14 +00:00
|
|
|
"""IPSEC interface IPv6"""
|
|
|
|
|
2021-02-09 14:04:02 +00:00
|
|
|
tf = VppEnum.vl_api_tunnel_encap_decap_flags_t
|
2020-06-30 07:47:14 +00:00
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv6_params
|
2021-02-09 14:04:02 +00:00
|
|
|
p.inner_hop_limit = 24
|
|
|
|
p.outer_hop_limit = 23
|
|
|
|
p.outer_flow_label = 243224
|
|
|
|
p.tun_flags = tf.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
self.config_network(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
config_tun_params(
|
|
|
|
p, self.encryption_type, None, self.pg0.local_ip6, self.pg0.remote_ip6
|
|
|
|
)
|
ipsec: IPSec interface correct drop w/ no protection
Type: improvement
When an IPSec interface is first constructed, the end node of the feature arc is not changed, which means it is interface-output.
This means that traffic directed into adjacencies on the link, that do not have protection (w/ an SA), drop like this:
...
00:00:01:111710: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:6 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111829: local0-output
ipsec0
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 5858585858585858585858585858585858585858585858585858585858585858
00000040: 58585858585858585858585858585858585858585858585858585858c2cf08c0
00000060: 2a2c103cd0126bd8b03c4ec20ce2bd02dd77b3e3a4f49664
00:00:01:112017: error-drop
rx:pg1
00:00:01:112034: drop
local0-output: interface is down
although that's a drop, no packets should go to local0, and we want all IPvX packets to go through ipX-drop.
This change sets the interface's end-arc node to the appropriate drop node when the interface is created, and when the last protection is removed.
The resulting drop is:
...
00:00:01:111504: ip4-midchain
tx_sw_if_index 4 dpo-idx 24 : ipv4 via 0.0.0.0 ipsec0: mtu:9000 next:0 flags:[]
stacked-on:
[@1]: dpo-drop ip4 flow hash: 0x00000000
00000000: 4500005c000100003f01cb8cac100202010101010800ecf40000000058585858
00000020: 58585858585858585858585858585858585858585858585858585858
00:00:01:111533: ip4-drop
ICMP: 172.16.2.2 -> 1.1.1.1
tos 0x00, ttl 63, length 92, checksum 0xcb8c dscp CS0 ecn NON_ECN
fragment id 0x0001
ICMP echo_request checksum 0xecf4 id 0
00:00:01:111620: error-drop
rx:pg1
00:00:01:111640: drop
null-node: blackholed packets
Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I7e7de23c541d9f1210a05e6984a688f1f821a155
2022-01-10 10:38:43 +00:00
|
|
|
self.verify_drop_tun_66(p, count=n_pkts)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip6, self.pg0.remote_ip6)
|
2020-06-30 07:47:14 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(p, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
p.tun_if.admin_down()
|
|
|
|
self.verify_drop_tun_66(p, count=n_pkts)
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
self.verify_tun_66(p, count=n_pkts)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 3 * n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 2 * n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
# it's a v4 packet when its encrypted
|
|
|
|
self.tun6_encrypt_node_name = "esp4-encrypt-tun"
|
|
|
|
|
|
|
|
self.verify_tun_46(p, count=n_pkts)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), 4 * n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), 3 * n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
self.tun6_encrypt_node_name = "esp6-encrypt-tun"
|
|
|
|
|
|
|
|
self.vapi.cli("clear interfaces")
|
|
|
|
|
|
|
|
# rekey - create new SAs and update the tunnel protection
|
|
|
|
np = copy.copy(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
np.crypt_key = b"X" + p.crypt_key[1:]
|
2020-06-30 07:47:14 +00:00
|
|
|
np.scapy_tun_spi += 100
|
|
|
|
np.scapy_tun_sa_id += 1
|
|
|
|
np.vpp_tun_spi += 100
|
|
|
|
np.vpp_tun_sa_id += 1
|
|
|
|
np.tun_if.local_spi = p.vpp_tun_spi
|
|
|
|
np.tun_if.remote_spi = p.scapy_tun_spi
|
2021-02-09 14:04:02 +00:00
|
|
|
np.inner_hop_limit = 24
|
|
|
|
np.outer_hop_limit = 128
|
2022-04-26 19:02:15 +02:00
|
|
|
np.inner_flow_label = 0xABCDE
|
|
|
|
np.outer_flow_label = 0xABCDE
|
2021-02-09 14:04:02 +00:00
|
|
|
np.hop_limit = 128
|
|
|
|
np.tun_flags = tf.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_FLOW_LABEL
|
2020-06-30 07:47:14 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(np, self.pg0.local_ip6, self.pg0.remote_ip6)
|
2020-06-30 07:47:14 +00:00
|
|
|
self.config_protect(np)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(np, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2020-06-30 07:47:14 +00:00
|
|
|
|
|
|
|
# teardown
|
|
|
|
self.unconfig_protect(np)
|
|
|
|
self.unconfig_sa(np)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2021-02-22 18:42:24 +00:00
|
|
|
def test_tun_66_police(self):
|
|
|
|
"""IPSEC interface IPv6 with input policer"""
|
|
|
|
tf = VppEnum.vl_api_tunnel_encap_decap_flags_t
|
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv6_params
|
|
|
|
p.inner_hop_limit = 24
|
|
|
|
p.outer_hop_limit = 23
|
|
|
|
p.outer_flow_label = 243224
|
|
|
|
p.tun_flags = tf.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_HOP_LIMIT
|
|
|
|
|
|
|
|
self.config_network(p)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip6, self.pg0.remote_ip6)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
action_tx = PolicerAction(
|
2022-04-26 19:02:15 +02:00
|
|
|
VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0
|
|
|
|
)
|
|
|
|
policer = VppPolicer(
|
|
|
|
self,
|
|
|
|
"pol1",
|
|
|
|
80,
|
|
|
|
0,
|
|
|
|
1000,
|
|
|
|
0,
|
|
|
|
conform_action=action_tx,
|
|
|
|
exceed_action=action_tx,
|
|
|
|
violate_action=action_tx,
|
|
|
|
)
|
2021-02-22 18:42:24 +00:00
|
|
|
policer.add_vpp_config()
|
|
|
|
|
|
|
|
# Start policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
self.verify_tun_66(p, count=n_pkts)
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
|
|
|
|
self.assertEqual(p.tun_if.get_tx_stats(), n_pkts)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
stats = policer.get_stats()
|
|
|
|
|
|
|
|
# Single rate, 2 colour policer - expect conform, violate but no exceed
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertGreater(stats["conform_packets"], 0)
|
|
|
|
self.assertEqual(stats["exceed_packets"], 0)
|
|
|
|
self.assertGreater(stats["violate_packets"], 0)
|
2021-02-22 18:42:24 +00:00
|
|
|
|
|
|
|
# Stop policing on tun
|
2022-04-05 19:23:12 +02:00
|
|
|
policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
|
2021-02-22 18:42:24 +00:00
|
|
|
self.verify_tun_66(p, count=n_pkts)
|
|
|
|
|
|
|
|
# No new policer stats
|
|
|
|
statsnew = policer.get_stats()
|
|
|
|
self.assertEqual(stats, statsnew)
|
|
|
|
|
|
|
|
# teardown
|
|
|
|
policer.remove_vpp_config()
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
2020-06-30 07:47:14 +00:00
|
|
|
|
2023-06-16 09:48:52 +02:00
|
|
|
@tag_fixme_vpp_workers
|
|
|
|
class TestIpsecItf6Tfc(TemplateIpsec6TunTfc, TestIpsecItf6):
|
|
|
|
"""IPsec Interface IPv6 with TFC"""
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"acl" in config.excluded_plugins, "Exclude tests depending on ACL plugin"
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
class TestIpsecMIfEsp4(TemplateIpsec, IpsecTun4):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Ipsec P2MP ESP v4 tests"""
|
|
|
|
|
2020-10-19 09:59:41 +00:00
|
|
|
tun4_encrypt_node_name = "esp4-encrypt-tun"
|
2021-02-25 10:05:32 +00:00
|
|
|
tun4_decrypt_node_name = ["esp4-decrypt-tun", "esp4-decrypt-tun-post"]
|
2020-10-19 09:59:41 +00:00
|
|
|
encryption_type = ESP
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
IP(src=self.pg1.local_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
|
|
|
|
|
|
|
def gen_pkts(self, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ IP(src="1.1.1.1", dst=dst)
|
|
|
|
/ UDP(sport=1144, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2020-10-19 09:59:41 +00:00
|
|
|
|
|
|
|
def verify_decrypted(self, p, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
self.assert_equal(rx[Ether].dst, self.pg1.remote_mac)
|
|
|
|
self.assert_equal(rx[IP].dst, self.pg1.remote_ip4)
|
|
|
|
|
|
|
|
def verify_encrypted(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
rx[IP].tos, VppEnum.vl_api_ip_dscp_t.IP_API_DSCP_EF << 2
|
|
|
|
)
|
2021-02-09 14:04:02 +00:00
|
|
|
self.assertEqual(rx[IP].ttl, p.hop_limit)
|
2020-10-19 09:59:41 +00:00
|
|
|
pkt = sa.decrypt(rx[IP])
|
|
|
|
if not pkt.haslayer(IP):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
e = pkt[IP]
|
|
|
|
self.assertEqual(e[IP].dst, p.remote_tun_if_host)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecMIfEsp4, self).setUp()
|
|
|
|
|
|
|
|
N_NHS = 16
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
p = self.ipv4_params
|
2022-04-26 19:02:15 +02:00
|
|
|
p.tun_if = VppIpsecInterface(
|
|
|
|
self, mode=(VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_MP)
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
p.tun_if.add_vpp_config()
|
|
|
|
p.tun_if.admin_up()
|
|
|
|
p.tun_if.config_ip4()
|
2020-11-25 19:35:38 +00:00
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
p.tun_if.config_ip4()
|
2020-10-19 09:59:41 +00:00
|
|
|
p.tun_if.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.generate_remote_hosts(N_NHS)
|
|
|
|
self.pg0.configure_ipv4_neighbors()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
r_all = AclRule(True, src_prefix="0.0.0.0/0", dst_prefix="0.0.0.0/0", proto=0)
|
2021-10-08 07:30:47 +00:00
|
|
|
a = VppAcl(self, [r_all]).add_vpp_config()
|
|
|
|
|
|
|
|
VppAclInterface(self, self.pg0.sw_if_index, [a]).add_vpp_config()
|
|
|
|
VppAclInterface(self, p.tun_if.sw_if_index, [a]).add_vpp_config()
|
|
|
|
|
2020-10-19 09:59:41 +00:00
|
|
|
# setup some SAs for several next-hops on the interface
|
|
|
|
self.multi_params = []
|
|
|
|
|
|
|
|
for ii in range(N_NHS):
|
|
|
|
p = copy.copy(self.ipv4_params)
|
|
|
|
|
|
|
|
p.remote_tun_if_host = "1.1.1.%d" % (ii + 1)
|
|
|
|
p.scapy_tun_sa_id = p.scapy_tun_sa_id + ii
|
|
|
|
p.scapy_tun_spi = p.scapy_tun_spi + ii
|
|
|
|
p.vpp_tun_sa_id = p.vpp_tun_sa_id + ii
|
|
|
|
p.vpp_tun_spi = p.vpp_tun_spi + ii
|
|
|
|
|
|
|
|
p.scapy_tra_sa_id = p.scapy_tra_sa_id + ii
|
|
|
|
p.scapy_tra_spi = p.scapy_tra_spi + ii
|
|
|
|
p.vpp_tra_sa_id = p.vpp_tra_sa_id + ii
|
|
|
|
p.vpp_tra_spi = p.vpp_tra_spi + ii
|
2022-04-26 19:02:15 +02:00
|
|
|
p.hop_limit = ii + 10
|
2020-01-02 04:06:10 +00:00
|
|
|
p.tun_sa_out = VppIpsecSA(
|
2022-04-26 19:02:15 +02:00
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.vpp_tun_sa_id,
|
|
|
|
p.vpp_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
2020-01-02 04:06:10 +00:00
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_hosts[ii].ip4,
|
2021-02-09 14:04:02 +00:00
|
|
|
dscp=VppEnum.vl_api_ip_dscp_t.IP_API_DSCP_EF,
|
2022-04-26 19:02:15 +02:00
|
|
|
hop_limit=p.hop_limit,
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
p.tun_sa_out.add_vpp_config()
|
|
|
|
|
2020-01-02 04:06:10 +00:00
|
|
|
p.tun_sa_in = VppIpsecSA(
|
2022-04-26 19:02:15 +02:00
|
|
|
self,
|
2022-11-16 18:45:24 +01:00
|
|
|
p.scapy_tun_sa_id,
|
|
|
|
p.scapy_tun_spi,
|
2022-04-26 19:02:15 +02:00
|
|
|
p.auth_algo_vpp_id,
|
|
|
|
p.auth_key,
|
|
|
|
p.crypt_algo_vpp_id,
|
|
|
|
p.crypt_key,
|
2020-01-02 04:06:10 +00:00
|
|
|
self.vpp_esp_protocol,
|
|
|
|
self.pg0.remote_hosts[ii].ip4,
|
|
|
|
self.pg0.local_ip4,
|
2021-02-09 14:04:02 +00:00
|
|
|
dscp=VppEnum.vl_api_ip_dscp_t.IP_API_DSCP_EF,
|
2022-04-26 19:02:15 +02:00
|
|
|
hop_limit=p.hop_limit,
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
p.tun_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
p.tun_protect = VppIpsecTunProtect(
|
|
|
|
self,
|
|
|
|
p.tun_if,
|
|
|
|
p.tun_sa_out,
|
|
|
|
[p.tun_sa_in],
|
2022-04-26 19:02:15 +02:00
|
|
|
nh=p.tun_if.remote_hosts[ii].ip4,
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
p.tun_protect.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
config_tun_params(
|
|
|
|
p,
|
|
|
|
self.encryption_type,
|
|
|
|
None,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_hosts[ii].ip4,
|
|
|
|
)
|
2020-10-19 09:59:41 +00:00
|
|
|
self.multi_params.append(p)
|
|
|
|
|
2021-10-08 07:30:47 +00:00
|
|
|
p.via_tun_route = VppIpRoute(
|
2022-04-26 19:02:15 +02:00
|
|
|
self,
|
|
|
|
p.remote_tun_if_host,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(p.tun_if.remote_hosts[ii].ip4, p.tun_if.sw_if_index)],
|
|
|
|
).add_vpp_config()
|
2020-10-19 09:59:41 +00:00
|
|
|
|
|
|
|
p.tun_dst = self.pg0.remote_hosts[ii].ip4
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
p = self.ipv4_params
|
|
|
|
p.tun_if.unconfig_ip4()
|
|
|
|
super(TestIpsecMIfEsp4, self).tearDown()
|
|
|
|
|
|
|
|
def test_tun_44(self):
|
|
|
|
"""P2MP IPSEC 44"""
|
|
|
|
N_PKTS = 63
|
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_44(p, count=N_PKTS)
|
|
|
|
|
2021-10-08 07:30:47 +00:00
|
|
|
# remove one tunnel protect, the rest should still work
|
|
|
|
self.multi_params[0].tun_protect.remove_vpp_config()
|
|
|
|
self.verify_tun_dropped_44(self.multi_params[0], count=N_PKTS)
|
|
|
|
self.multi_params[0].via_tun_route.remove_vpp_config()
|
|
|
|
self.verify_tun_dropped_44(self.multi_params[0], count=N_PKTS)
|
|
|
|
|
|
|
|
for p in self.multi_params[1:]:
|
|
|
|
self.verify_tun_44(p, count=N_PKTS)
|
|
|
|
|
|
|
|
self.multi_params[0].tun_protect.add_vpp_config()
|
|
|
|
self.multi_params[0].via_tun_route.add_vpp_config()
|
|
|
|
|
|
|
|
for p in self.multi_params:
|
|
|
|
self.verify_tun_44(p, count=N_PKTS)
|
|
|
|
|
2020-10-19 09:59:41 +00:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
class TestIpsecItf6MPLS(TemplateIpsec, TemplateIpsecItf6, IpsecTun6):
|
|
|
|
"""IPsec Interface MPLSoIPv6"""
|
2020-12-21 13:19:10 +00:00
|
|
|
|
|
|
|
tun6_encrypt_node_name = "esp-mpls-encrypt-tun"
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestIpsecItf6MPLS, self).setUp()
|
|
|
|
|
|
|
|
self.tun_if = self.pg0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestIpsecItf6MPLS, self).tearDown()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def gen_encrypt_pkts6(self, p, sa, sw_intf, src, dst, count=1, payload_size=100):
|
|
|
|
return [
|
|
|
|
Ether(src=sw_intf.remote_mac, dst=sw_intf.local_mac)
|
|
|
|
/ sa.encrypt(
|
|
|
|
MPLS(label=66, ttl=3)
|
|
|
|
/ IPv6(src=src, dst=dst)
|
|
|
|
/ UDP(sport=1166, dport=2233)
|
|
|
|
/ Raw(b"X" * payload_size)
|
|
|
|
)
|
|
|
|
for i in range(count)
|
|
|
|
]
|
2020-12-21 13:19:10 +00:00
|
|
|
|
|
|
|
def verify_encrypted6(self, p, sa, rxs):
|
|
|
|
for rx in rxs:
|
|
|
|
try:
|
|
|
|
pkt = sa.decrypt(rx[IPv6])
|
|
|
|
if not pkt.haslayer(IPv6):
|
|
|
|
pkt = IP(pkt[Raw].load)
|
|
|
|
self.assert_packet_checksums_valid(pkt)
|
|
|
|
self.assert_equal(pkt[MPLS].label, 66)
|
|
|
|
self.assert_equal(pkt[IPv6].dst, p.remote_tun_if_host)
|
|
|
|
except (IndexError, AssertionError):
|
|
|
|
self.logger.debug(ppp("Unexpected packet:", rx))
|
|
|
|
try:
|
|
|
|
self.logger.debug(ppp("Decrypted packet:", pkt))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_tun_mpls_o_ip6(self):
|
|
|
|
"""IPSEC interface MPLS over IPv6"""
|
|
|
|
|
|
|
|
n_pkts = 127
|
|
|
|
p = self.ipv6_params
|
|
|
|
f = FibPathProto
|
|
|
|
|
|
|
|
tbl = VppMplsTable(self, 0)
|
|
|
|
tbl.add_vpp_config()
|
|
|
|
|
|
|
|
self.config_network(p)
|
|
|
|
# deag MPLS routes from the tunnel
|
2022-04-26 19:02:15 +02:00
|
|
|
r6 = VppMplsRoute(
|
|
|
|
self,
|
|
|
|
66,
|
|
|
|
1,
|
|
|
|
[VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)],
|
|
|
|
eos_proto=f.FIB_PATH_NH_PROTO_IP6,
|
|
|
|
).add_vpp_config()
|
|
|
|
p.route.modify(
|
|
|
|
[
|
|
|
|
VppRoutePath(
|
|
|
|
p.tun_if.remote_ip6, p.tun_if.sw_if_index, labels=[VppMplsLabel(66)]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2020-12-21 13:19:10 +00:00
|
|
|
p.tun_if.enable_mpls()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.config_sa_tun(p, self.pg0.local_ip6, self.pg0.remote_ip6)
|
2020-12-21 13:19:10 +00:00
|
|
|
self.config_protect(p)
|
|
|
|
|
|
|
|
self.verify_tun_66(p, count=n_pkts)
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
p.tun_if.disable_mpls()
|
|
|
|
self.unconfig_protect(p)
|
|
|
|
self.unconfig_sa(p)
|
|
|
|
self.unconfig_network(p)
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2018-06-24 22:49:55 +02:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|