2019-12-04 17:19:12 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import unittest
|
2023-07-11 09:45:56 +02:00
|
|
|
import secrets
|
|
|
|
import socket
|
2019-12-04 17:19:12 -05:00
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import VppTestRunner
|
2023-07-11 09:45:56 +02:00
|
|
|
from vpp_papi import VppEnum
|
|
|
|
from vpp_ipsec import VppIpsecSA, VppIpsecSpd, VppIpsecSpdItfBinding, VppIpsecSpdEntry
|
2019-12-04 17:19:12 -05:00
|
|
|
|
2019-12-17 18:02:54 -05:00
|
|
|
from scapy.contrib.geneve import GENEVE
|
2019-12-10 12:48:26 +01:00
|
|
|
from scapy.packet import Raw
|
|
|
|
from scapy.layers.l2 import Ether
|
2023-07-11 09:45:56 +02:00
|
|
|
from scapy.layers.inet import IP, UDP, TCP
|
2019-12-10 12:48:26 +01:00
|
|
|
from scapy.layers.vxlan import VXLAN
|
2023-07-11 09:45:56 +02:00
|
|
|
from scapy.layers.ipsec import ESP, SecurityAssociation
|
2019-12-10 12:48:26 +01:00
|
|
|
from scapy.compat import raw
|
2021-02-26 13:47:41 +01:00
|
|
|
from scapy.utils import rdpcap
|
2019-12-10 12:48:26 +01:00
|
|
|
|
2019-12-04 17:19:12 -05:00
|
|
|
|
2023-07-11 09:45:56 +02:00
|
|
|
class TemplateTraceFilter(VppTestCase):
|
2019-12-04 17:19:12 -05:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2023-07-11 09:45:56 +02:00
|
|
|
super().setUpClass()
|
2019-12-04 17:19:12 -05:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
2023-07-11 09:45:56 +02:00
|
|
|
super().tearDownClass()
|
2019-12-04 17:19:12 -05:00
|
|
|
|
|
|
|
def setUp(self):
|
2023-07-11 09:45:56 +02:00
|
|
|
super().setUp()
|
2021-02-19 16:39:13 +01:00
|
|
|
self.create_pg_interfaces(range(2))
|
|
|
|
self.pg0.generate_remote_hosts(11)
|
2019-12-10 12:48:26 +01:00
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
2021-02-19 16:39:13 +01:00
|
|
|
i.resolve_arp()
|
2019-12-04 17:19:12 -05:00
|
|
|
|
|
|
|
def tearDown(self):
|
2023-07-11 09:45:56 +02:00
|
|
|
super().tearDown()
|
2019-12-10 12:48:26 +01:00
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.unconfig()
|
|
|
|
i.admin_down()
|
|
|
|
|
|
|
|
def cli(self, cmd):
|
|
|
|
r = self.vapi.cli_return_response(cmd)
|
|
|
|
if r.retval != 0:
|
2022-04-26 19:02:15 +02:00
|
|
|
s = (
|
|
|
|
"reply '%s'" % r.reply
|
|
|
|
if hasattr(r, "reply")
|
|
|
|
else "retval '%s'" % r.retval
|
|
|
|
)
|
2021-02-19 16:39:13 +01:00
|
|
|
raise RuntimeError("cli command '%s' FAIL with %s" % (cmd, s))
|
2019-12-10 12:48:26 +01:00
|
|
|
return r
|
|
|
|
|
|
|
|
# check number of hits for classifier
|
|
|
|
def assert_hits(self, n):
|
2021-02-26 13:47:41 +01:00
|
|
|
r = self.cli("show classify table verbose")
|
2019-12-10 12:48:26 +01:00
|
|
|
self.assertTrue(r.reply.find("hits %i" % n) != -1)
|
2019-12-04 17:19:12 -05:00
|
|
|
|
2023-07-11 09:45:56 +02:00
|
|
|
def clear(self):
|
|
|
|
self.cli("clear trace")
|
|
|
|
|
2021-02-26 13:47:41 +01:00
|
|
|
def add_trace_filter(self, mask, match):
|
|
|
|
self.cli("classify filter trace mask %s match %s" % (mask, match))
|
2023-07-11 09:45:56 +02:00
|
|
|
self.clear()
|
2021-02-26 13:47:41 +01:00
|
|
|
self.cli("trace add pg-input 1000 filter")
|
2021-02-19 16:39:13 +01:00
|
|
|
|
2021-02-26 13:47:41 +01:00
|
|
|
def del_trace_filters(self):
|
2021-02-19 16:39:13 +01:00
|
|
|
self.cli("classify filter trace del")
|
|
|
|
r = self.cli("show classify filter")
|
|
|
|
s = "packet tracer: first table none"
|
|
|
|
self.assertTrue(r.reply.find(s) != -1)
|
|
|
|
|
2021-02-26 13:47:41 +01:00
|
|
|
def del_pcap_filters(self):
|
|
|
|
self.cli("classify filter pcap del")
|
|
|
|
r = self.cli("show classify filter")
|
|
|
|
s = "pcap rx/tx/drop: first table none"
|
|
|
|
self.assertTrue(r.reply.find(s) != -1)
|
|
|
|
|
2023-07-11 09:45:56 +02:00
|
|
|
# install a classify rule, inject traffic and check for hits
|
|
|
|
def assert_classify(self, mask, match, packets, n=None):
|
|
|
|
self.add_trace_filter("hex %s" % mask, "hex %s" % match)
|
|
|
|
self.send_and_expect(self.pg0, packets, self.pg1, trace=False)
|
|
|
|
self.assert_hits(n if n is not None else len(packets))
|
|
|
|
self.del_trace_filters()
|
|
|
|
|
|
|
|
|
|
|
|
class TestTracefilter(TemplateTraceFilter):
|
|
|
|
"""Packet Tracer Filter Test"""
|
|
|
|
|
2021-02-19 16:39:13 +01:00
|
|
|
def test_basic(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Packet Tracer Filter Test"""
|
2021-02-26 13:47:41 +01:00
|
|
|
self.add_trace_filter(
|
2022-04-26 19:02:15 +02:00
|
|
|
"l3 ip4 src", "l3 ip4 src %s" % self.pg0.remote_hosts[5].ip4
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
self.add_trace_filter(
|
2022-04-26 19:02:15 +02:00
|
|
|
"l3 ip4 proto l4 src_port", "l3 ip4 proto 17 l4 src_port 2345"
|
|
|
|
)
|
2021-02-19 16:39:13 +01:00
|
|
|
# the packet we are trying to match
|
|
|
|
p = list()
|
|
|
|
for i in range(100):
|
|
|
|
src = self.pg0.remote_hosts[i % len(self.pg0.remote_hosts)].ip4
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=src, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1234, dport=2345)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-02-19 16:39:13 +01:00
|
|
|
for i in range(17):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_hosts[0].ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=2345, dport=1234)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-02-19 16:39:13 +01:00
|
|
|
|
|
|
|
self.send_and_expect(self.pg0, p, self.pg1, trace=False)
|
|
|
|
|
|
|
|
# Check for 9 and 17 classifier hits, which is the right answer
|
2019-12-10 12:48:26 +01:00
|
|
|
self.assert_hits(9)
|
2021-02-19 16:39:13 +01:00
|
|
|
self.assert_hits(17)
|
2019-12-10 12:48:26 +01:00
|
|
|
|
2021-02-26 13:47:41 +01:00
|
|
|
self.del_trace_filters()
|
2019-12-10 12:48:26 +01:00
|
|
|
|
|
|
|
def test_encap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Packet Tracer Filter Test with encap"""
|
2019-12-10 12:48:26 +01:00
|
|
|
|
|
|
|
# the packet we are trying to match
|
2022-04-26 19:02:15 +02:00
|
|
|
p = (
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP()
|
|
|
|
/ VXLAN()
|
|
|
|
/ Ether()
|
|
|
|
/ IP()
|
|
|
|
/ UDP()
|
|
|
|
/ GENEVE(vni=1234)
|
|
|
|
/ Ether()
|
|
|
|
/ IP(src="192.168.4.167")
|
|
|
|
/ UDP()
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
2019-12-10 12:48:26 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# compute filter mask & value
|
|
|
|
# we compute it by XOR'ing a template packet with a modified packet
|
|
|
|
# we need to set checksums to 0 to make sure scapy will not recompute
|
|
|
|
# them
|
|
|
|
#
|
2022-04-26 19:02:15 +02:00
|
|
|
tmpl = (
|
|
|
|
Ether()
|
|
|
|
/ IP(chksum=0)
|
|
|
|
/ UDP(chksum=0)
|
|
|
|
/ VXLAN()
|
|
|
|
/ Ether()
|
|
|
|
/ IP(chksum=0)
|
|
|
|
/ UDP(chksum=0)
|
|
|
|
/ GENEVE(vni=0)
|
|
|
|
/ Ether()
|
|
|
|
/ IP(src="0.0.0.0", chksum=0)
|
|
|
|
)
|
2019-12-10 12:48:26 +01:00
|
|
|
ori = raw(tmpl)
|
|
|
|
|
|
|
|
# the mask
|
2022-04-26 19:02:15 +02:00
|
|
|
tmpl[GENEVE].vni = 0xFFFFFF
|
2019-12-10 12:48:26 +01:00
|
|
|
user = tmpl[GENEVE].payload
|
2022-04-26 19:02:15 +02:00
|
|
|
user[IP].src = "255.255.255.255"
|
2019-12-10 12:48:26 +01:00
|
|
|
new = raw(tmpl)
|
|
|
|
mask = "".join(("{:02x}".format(o ^ n) for o, n in zip(ori, new)))
|
|
|
|
|
|
|
|
# this does not match (wrong vni)
|
|
|
|
tmpl[GENEVE].vni = 1
|
|
|
|
user = tmpl[GENEVE].payload
|
2022-04-26 19:02:15 +02:00
|
|
|
user[IP].src = "192.168.4.167"
|
2019-12-10 12:48:26 +01:00
|
|
|
new = raw(tmpl)
|
|
|
|
match = "".join(("{:02x}".format(o ^ n) for o, n in zip(ori, new)))
|
|
|
|
self.assert_classify(mask, match, [p] * 11, 0)
|
|
|
|
|
|
|
|
# this must match
|
|
|
|
tmpl[GENEVE].vni = 1234
|
|
|
|
new = raw(tmpl)
|
|
|
|
match = "".join(("{:02x}".format(o ^ n) for o, n in zip(ori, new)))
|
|
|
|
self.assert_classify(mask, match, [p] * 17)
|
|
|
|
|
2021-02-26 13:47:41 +01:00
|
|
|
def test_pcap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Packet Capture Filter Test"""
|
2021-02-26 13:47:41 +01:00
|
|
|
self.cli(
|
2022-04-26 19:02:15 +02:00
|
|
|
"classify filter pcap mask l3 ip4 src match l3 ip4 src %s"
|
|
|
|
% self.pg0.remote_hosts[5].ip4
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
self.cli(
|
|
|
|
"classify filter pcap "
|
|
|
|
"mask l3 ip4 proto l4 src_port "
|
2022-04-26 19:02:15 +02:00
|
|
|
"match l3 ip4 proto 17 l4 src_port 2345"
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
self.cli(
|
|
|
|
"pcap trace rx tx max 1000 intfc pg0 "
|
2022-04-26 19:02:15 +02:00
|
|
|
"file vpp_test_trace_filter_test_pcap.pcap filter"
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
# the packet we are trying to match
|
|
|
|
p = list()
|
|
|
|
for i in range(100):
|
|
|
|
src = self.pg0.remote_hosts[i % len(self.pg0.remote_hosts)].ip4
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=src, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=1234, dport=2345)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
for i in range(17):
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_hosts[0].ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=2345, dport=1234)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-02-26 13:47:41 +01:00
|
|
|
|
|
|
|
self.send_and_expect(self.pg0, p, self.pg1, trace=False)
|
|
|
|
|
|
|
|
# Check for 9 and 17 classifier hits, which is the right answer
|
|
|
|
self.assert_hits(9)
|
|
|
|
self.assert_hits(17)
|
|
|
|
|
|
|
|
self.cli("pcap trace rx tx off")
|
|
|
|
self.del_pcap_filters()
|
|
|
|
|
|
|
|
# check captured pcap
|
2021-03-03 17:37:25 +01:00
|
|
|
pcap = rdpcap("/tmp/vpp_test_trace_filter_test_pcap.pcap")
|
2021-02-26 13:47:41 +01:00
|
|
|
self.assertEqual(len(pcap), 9 + 17)
|
|
|
|
p_ = str(p[5])
|
|
|
|
for i in range(9):
|
|
|
|
self.assertEqual(str(pcap[i]), p_)
|
|
|
|
p_ = str(p[100])
|
|
|
|
for i in range(9, 9 + 17):
|
|
|
|
self.assertEqual(str(pcap[i]), p_)
|
|
|
|
|
2021-03-03 17:37:25 +01:00
|
|
|
def test_pcap_drop(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Drop Packet Capture Filter Test"""
|
2021-03-03 17:37:25 +01:00
|
|
|
self.cli(
|
|
|
|
"pcap trace drop max 1000 "
|
2021-10-06 12:48:34 +00:00
|
|
|
"error {ip4-udp-lookup}.{no_listener} "
|
2022-04-26 19:02:15 +02:00
|
|
|
"file vpp_test_trace_filter_test_pcap_drop.pcap"
|
|
|
|
)
|
2021-03-03 17:37:25 +01:00
|
|
|
# the packet we are trying to match
|
|
|
|
p = list()
|
|
|
|
for i in range(17):
|
|
|
|
# this packet should be forwarded
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_hosts[0].ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ UDP(sport=2345, dport=1234)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-03-03 17:37:25 +01:00
|
|
|
# this packet should be captured (no listener)
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_hosts[0].ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ UDP(sport=2345, dport=1234)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-03-03 17:37:25 +01:00
|
|
|
# this packet will be blackholed but not captured
|
2022-04-26 19:02:15 +02:00
|
|
|
p.append(
|
|
|
|
(
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src=self.pg0.remote_hosts[0].ip4, dst="0.0.0.0")
|
|
|
|
/ UDP(sport=2345, dport=1234)
|
|
|
|
/ Raw("\xa5" * 100)
|
|
|
|
)
|
|
|
|
)
|
2021-03-03 17:37:25 +01:00
|
|
|
|
|
|
|
self.send_and_expect(self.pg0, p, self.pg1, n_rx=17, trace=False)
|
|
|
|
|
|
|
|
self.cli("pcap trace drop off")
|
|
|
|
|
|
|
|
# check captured pcap
|
|
|
|
pcap = rdpcap("/tmp/vpp_test_trace_filter_test_pcap_drop.pcap")
|
|
|
|
self.assertEqual(len(pcap), 17)
|
|
|
|
|
2019-12-04 17:19:12 -05:00
|
|
|
|
2023-07-11 09:45:56 +02:00
|
|
|
class TestTraceFilterInner(TemplateTraceFilter):
|
|
|
|
"""Packet Tracer Filter Inner Test"""
|
|
|
|
|
|
|
|
extra_vpp_plugin_config = [
|
|
|
|
"plugin tracenode_plugin.so {enable}",
|
|
|
|
]
|
|
|
|
|
|
|
|
def add_trace_filter(self, mask, match, tn_feature_intfc_index=None):
|
|
|
|
if tn_feature_intfc_index is not None:
|
|
|
|
self.logger.info("fffff")
|
|
|
|
self.vapi.tracenode_enable_disable(sw_if_index=tn_feature_intfc_index)
|
|
|
|
super().add_trace_filter(mask, match)
|
|
|
|
|
|
|
|
def del_trace_filters(self, tn_feature_intfc_index=None):
|
|
|
|
if tn_feature_intfc_index is not None:
|
|
|
|
self.vapi.tracenode_enable_disable(
|
|
|
|
sw_if_index=tn_feature_intfc_index, enable=False
|
|
|
|
)
|
|
|
|
super().del_trace_filters()
|
|
|
|
|
|
|
|
def __add_sa(self, id_, tun_src, tun_dst):
|
|
|
|
# AES-CTR-128 / SHA2-256
|
|
|
|
crypto_key_length = 16
|
|
|
|
salt_length = 4
|
|
|
|
integ_key_lenght = 16
|
|
|
|
crypto_key = secrets.token_bytes(crypto_key_length)
|
|
|
|
salt = secrets.randbits(salt_length * 8)
|
|
|
|
integ_key = secrets.token_bytes(integ_key_lenght)
|
|
|
|
|
|
|
|
flags = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_UDP_ENCAP
|
|
|
|
|
|
|
|
vpp_sa_in = VppIpsecSA(
|
|
|
|
test=self,
|
|
|
|
id=id_,
|
|
|
|
spi=id_,
|
|
|
|
integ_alg=VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA_256_128,
|
|
|
|
integ_key=integ_key,
|
|
|
|
crypto_alg=VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CTR_128,
|
|
|
|
crypto_key=crypto_key,
|
|
|
|
proto=VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
|
|
|
|
flags=flags,
|
|
|
|
salt=salt,
|
|
|
|
tun_src=tun_src,
|
|
|
|
tun_dst=tun_dst,
|
|
|
|
udp_src=4500,
|
|
|
|
udp_dst=4500,
|
|
|
|
)
|
|
|
|
vpp_sa_in.add_vpp_config()
|
|
|
|
|
|
|
|
scapy_sa_in = SecurityAssociation(
|
|
|
|
ESP,
|
|
|
|
spi=id_,
|
|
|
|
crypt_algo="AES-CTR",
|
|
|
|
crypt_key=crypto_key + salt.to_bytes(salt_length, "big"),
|
|
|
|
auth_algo="SHA2-256-128",
|
|
|
|
auth_key=integ_key,
|
|
|
|
tunnel_header=IP(src=tun_src, dst=tun_dst),
|
|
|
|
nat_t_header=UDP(sport=4500, dport=4500),
|
|
|
|
)
|
|
|
|
|
|
|
|
id_ += 1
|
|
|
|
|
|
|
|
vpp_sa_out = VppIpsecSA(
|
|
|
|
test=self,
|
|
|
|
id=id_,
|
|
|
|
spi=id_,
|
|
|
|
integ_alg=VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA_256_128,
|
|
|
|
integ_key=integ_key,
|
|
|
|
crypto_alg=VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CTR_128,
|
|
|
|
crypto_key=crypto_key,
|
|
|
|
proto=VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
|
|
|
|
flags=flags,
|
|
|
|
salt=salt,
|
|
|
|
tun_src=tun_dst,
|
|
|
|
tun_dst=tun_src,
|
|
|
|
udp_src=4500,
|
|
|
|
udp_dst=4500,
|
|
|
|
)
|
|
|
|
vpp_sa_out.add_vpp_config()
|
|
|
|
|
|
|
|
scapy_sa_out = SecurityAssociation(
|
|
|
|
ESP,
|
|
|
|
spi=id_,
|
|
|
|
crypt_algo="AES-CTR",
|
|
|
|
crypt_key=crypto_key + salt.to_bytes(salt_length, "big"),
|
|
|
|
auth_algo="SHA2-256-128",
|
|
|
|
auth_key=integ_key,
|
|
|
|
tunnel_header=IP(src=tun_dst, dst=tun_src),
|
|
|
|
nat_t_header=UDP(sport=4500, dport=4500),
|
|
|
|
)
|
|
|
|
|
|
|
|
return vpp_sa_in, scapy_sa_in, vpp_sa_out, scapy_sa_out
|
|
|
|
|
|
|
|
def __gen_encrypt_pkt(self, scapy_sa, pkt):
|
|
|
|
return Ether(
|
ethernet: check destination mac for L3 in ethernet-input node
When the NIC does not support mac filter, we rely on ethernet-input
node to do the destination mac check, ie, when the interface is in L3,
the mac address for the packet must be the mac address of the
interface where the packet arrives. This works fine in ethernet-input
node when all packets in the frame might have different interfaces, ie,
ETH_INPUT_FRAME_F_SINGLE_SW_IF_ID is not set in the frame. However,
when all packets are having the same interface,
ETH_INPUT_FRAME_F_SINGLE_SW_IF_ID is set, ethernet-input node goes
through the optimized routine eth_input_single_int -> eth_input_process_frame.
That is where dmac check has a bug when all packets in the frame are
either, ip4, ip6, or mpls without vlan tags. Because without vlan tags,
the code handles all packets in fast path and ignores dmac check.
With vlan tags, the code goes to slow path where dmac check is handled
properly.
The fix is to check if we have a bad dmac in the fast path and force the
code to go to slow path which will handle dmac check properly.
Also do a wholesale correction on all the testcases which do not use
the proper dmac when sending L3 packets.
Type: fix
Change-Id: I73153a805cecdc24c4eefcc781676de04737ae2c
Signed-off-by: Steven Luong <sluong@cisco.com>
2024-04-19 09:49:20 -07:00
|
|
|
src=self.pg0.remote_mac, dst=self.pg0.local_mac
|
2023-07-11 09:45:56 +02:00
|
|
|
) / scapy_sa.encrypt(pkt)
|
|
|
|
|
|
|
|
def test_encrypted_encap(self):
|
|
|
|
"""Packet Tracer Filter Test with encrypted encap"""
|
|
|
|
|
|
|
|
vpp_sa_in, scapy_sa_in, vpp_sa_out, _ = self.__add_sa(
|
|
|
|
1, self.pg0.local_ip4, self.pg0.remote_ip4
|
|
|
|
)
|
|
|
|
|
|
|
|
spd = VppIpsecSpd(self, 1)
|
|
|
|
spd.add_vpp_config()
|
|
|
|
|
|
|
|
spd_binding = VppIpsecSpdItfBinding(self, spd, self.pg0)
|
|
|
|
spd_binding.add_vpp_config()
|
|
|
|
|
|
|
|
spd_entry = VppIpsecSpdEntry(
|
|
|
|
self,
|
|
|
|
spd,
|
|
|
|
1,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.local_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
self.pg0.remote_ip4,
|
|
|
|
socket.IPPROTO_ESP,
|
|
|
|
policy=VppEnum.vl_api_ipsec_spd_action_t.IPSEC_API_SPD_ACTION_PROTECT,
|
|
|
|
is_outbound=0,
|
|
|
|
).add_vpp_config()
|
|
|
|
|
|
|
|
# the inner packet we are trying to match
|
|
|
|
inner_pkt = (
|
|
|
|
IP(src=self.pg1.local_ip4, dst=self.pg1.remote_ip4)
|
|
|
|
/ TCP(sport=1234, dport=4321)
|
|
|
|
/ Raw(b"\xa5" * 100)
|
|
|
|
)
|
|
|
|
pkt = self.__gen_encrypt_pkt(scapy_sa_in, inner_pkt)
|
|
|
|
|
|
|
|
# self.add_trace_filter("l3 ip4 src", f"l3 ip4 src {self.pg0.local_ip4}")
|
|
|
|
|
|
|
|
self.add_trace_filter(
|
|
|
|
"l2 none l3 ip4 src proto l4 dst_port",
|
|
|
|
f"l2 none l3 ip4 src {self.pg1.local_ip4} proto 6 l4 dst_port 4321",
|
|
|
|
tn_feature_intfc_index=self.pg0.sw_if_index,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.logger.info("Sending packet with matching inner")
|
|
|
|
self.send_and_expect(self.pg0, pkt * 67, self.pg1, trace=False)
|
|
|
|
self.assert_hits(67)
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
self.logger.info("Sending packet with wrong inner port")
|
|
|
|
inner_pkt[TCP].dport = 1111
|
|
|
|
pkt = self.__gen_encrypt_pkt(scapy_sa_in, inner_pkt)
|
|
|
|
self.send_and_expect(self.pg0, pkt * 67, self.pg1, trace=False)
|
|
|
|
# the classify session should still have the 67 previous hits.
|
|
|
|
# In another way, the delta is 0
|
|
|
|
self.assert_hits(67)
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
self.logger.info("Sending packet with wrong source address")
|
|
|
|
inner_pkt[IP].src = "1.2.3.4"
|
|
|
|
inner_pkt[TCP].dport = 4321
|
|
|
|
pkt = self.__gen_encrypt_pkt(scapy_sa_in, inner_pkt)
|
|
|
|
self.send_and_expect(self.pg0, pkt * 67, self.pg1, trace=False)
|
|
|
|
self.assert_hits(67)
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
self.del_trace_filters(tn_feature_intfc_index=self.pg0.sw_if_index)
|
|
|
|
|
|
|
|
spd_entry.remove_vpp_config()
|
|
|
|
spd_binding.remove_vpp_config()
|
|
|
|
spd.remove_vpp_config()
|
|
|
|
vpp_sa_in.remove_vpp_config()
|
|
|
|
vpp_sa_out.remove_vpp_config()
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2019-12-04 17:19:12 -05:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|