From ec5371e3e31b7860d6b3996fd10420566a4377f2 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Fri, 4 Mar 2022 11:45:41 +0000 Subject: ip: Fixes for IPv6 and MPLS fragmentation Type: fix - IPv6 fragmentation did not work if the packet spaneed multiple buffers, because the 'len' calculation to did max out at the size of a buffer - IPv6 fragmentation did not work when the l2unfragmentable size was non-zero, it was not used in the correct places - IPv6oMPLS fragmentation would fragment all IPv6, it should do so only for link local - IPv6oMPLS should send back TooBig ICMP6 for non locally generated Signed-off-by: Neale Ranns Change-Id: Ie8f02cdfdd7b7e8474e62b6d0acda8f20c371184 --- test/test_ip6.py | 7 +++++++ test/test_ipip.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_mpls.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 115 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_ip6.py b/test/test_ip6.py index bac50a3df98..2e972db5dd3 100644 --- a/test/test_ip6.py +++ b/test/test_ip6.py @@ -3170,6 +3170,12 @@ class TestIPv6PathMTU(VppTestCase): self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2800, 0, 0, 0]) + p_6k = (Ether(dst=self.pg0.local_mac, + src=self.pg0.remote_mac) / + IPv6(src=self.pg0.remote_ip6, + dst=tun.remote_ip6) / + UDP(sport=1234, dport=5678) / + Raw(b'0xa' * 2000)) p_2k = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / IPv6(src=self.pg0.remote_ip6, @@ -3189,6 +3195,7 @@ class TestIPv6PathMTU(VppTestCase): self.pg1.remote_ip6).add_vpp_config() # this is now the interface MTU frags + self.send_and_expect(self.pg0, [p_6k], self.pg1, n_rx=4) self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) self.send_and_expect(self.pg0, [p_1k], self.pg1) diff --git a/test/test_ipip.py b/test/test_ipip.py index 83395e0bd72..8e16c80f05f 100644 --- a/test/test_ipip.py +++ b/test/test_ipip.py @@ -1150,6 +1150,59 @@ class TestIPIP6(VppTestCase): p6_reply.id = 256 self.validate(reass_pkt, p6_reply) + def test_ip6_mpls_frag(self): + """ Test fragmenting IPv6 over MPLS """ + + # IPv6 packets must be locally generated to be fragmented + # the use of tunnel encaps + tun_dst = VppIpRoute( + self, "1000::1", 128, + [VppRoutePath(self.pg1.remote_ip6, + self.pg1.sw_if_index, + labels=[VppMplsLabel(32)])]).add_vpp_config() + + tun = VppIpIpTunInterface( + self, + self.pg0, + self.pg0.local_ip6, + "1000::1").add_vpp_config() + + tun.admin_up() + tun.config_ip6() + tun.config_ip4() + + self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, + [2000, 0, 0, 0]) + + p_6k = (Ether(dst=self.pg0.local_mac, + src=self.pg0.remote_mac) / + IPv6(src=self.pg0.remote_ip6, + dst=tun.remote_ip6) / + UDP(sport=1234, dport=5678) / + Raw(b'0xa' * 2000)) + p_2k = (Ether(dst=self.pg0.local_mac, + src=self.pg0.remote_mac) / + IPv6(src=self.pg0.remote_ip6, + dst=tun.remote_ip6) / + UDP(sport=1234, dport=5678) / + Raw(b'0xa' * 1000)) + p_1k = (Ether(dst=self.pg0.local_mac, + src=self.pg0.remote_mac) / + IPv6(src=self.pg0.remote_ip6, + dst=tun.remote_ip6) / + UDP(sport=1234, dport=5678) / + Raw(b'0xa' * 600)) + + # this is now the interface MTU frags + rxs = self.send_and_expect(self.pg0, [p_6k], self.pg1, n_rx=4) + self.assertEqual(rxs[0][UDP].dport, 5678) + for rx in rxs: + self.assertEqual(rx[MPLS].label, 32) + self.assertEqual(rx[IPv6].dst, "1000::1") + self.assertEqual(rx[IPv6].dst, "1000::1") + self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) + self.send_and_expect(self.pg0, [p_1k], self.pg1) + def test_ipip_create(self): """ ipip create / delete interface test """ rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5') diff --git a/test/test_mpls.py b/test/test_mpls.py index 4cc7a0759f2..d94676b67da 100644 --- a/test/test_mpls.py +++ b/test/test_mpls.py @@ -18,7 +18,8 @@ import scapy.compat from scapy.packet import Raw from scapy.layers.l2 import Ether, ARP from scapy.layers.inet import IP, UDP, ICMP -from scapy.layers.inet6 import IPv6, ICMPv6TimeExceeded, ICMPv6EchoRequest +from scapy.layers.inet6 import IPv6, ICMPv6TimeExceeded, ICMPv6EchoRequest, \ + ICMPv6PacketTooBig from scapy.contrib.mpls import MPLS NUM_PKTS = 67 @@ -425,6 +426,31 @@ class TestMPLS(VppTestCase): except: raise + def verify_capture_fragmented_labelled_ip6(self, src_if, capture, sent, + mpls_labels, ip_ttl=None): + try: + capture = verify_filter(capture, sent) + + for i in range(len(capture)): + tx = sent[0] + rx = capture[i] + tx_ip = tx[IPv6] + rx.show() + rx_ip = IPv6(rx[MPLS].payload) + rx_ip.show() + + verify_mpls_stack(self, rx, mpls_labels) + + self.assertEqual(rx_ip.src, tx_ip.src) + self.assertEqual(rx_ip.dst, tx_ip.dst) + if not ip_ttl: + # IP processing post pop has decremented the hop-limit + self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim) + else: + self.assertEqual(rx_ip.hlim, ip_ttl) + except: + raise + def test_swap(self): """ MPLS label swap tests """ @@ -908,6 +934,11 @@ class TestMPLS(VppTestCase): self.pg0.sw_if_index, labels=[VppMplsLabel(32)])]) route_10_0_0_1.add_vpp_config() + route_1000_1 = VppIpRoute(self, "1000::1", 128, + [VppRoutePath(self.pg0.remote_ip6, + self.pg0.sw_if_index, + labels=[VppMplsLabel(32)])]) + route_1000_1.add_vpp_config() # # a stream that matches the route for 10.0.0.1 @@ -924,6 +955,29 @@ class TestMPLS(VppTestCase): self.verify_capture_fragmented_labelled_ip4(self.pg0, rx, tx, [VppMplsLabel(32)]) + # packets with DF bit set generate ICMP + for t in tx: + t[IP].flags = 'DF' + rxs = self.send_and_expect_some(self.pg0, tx, self.pg0) + + for rx in rxs: + rx[ICMP].code = "fragmentation-needed" + + self.assertEqual(self.statistics.get_err_counter( + "/err/mpls-frag/can't fragment this packet"), + len(tx)) + # + # a stream that matches the route for 1000::1/128 + # PG0 is in the default table + # + tx = self.create_stream_ip6(self.pg0, "1000::1") + for i in range(0, 257): + self.extend_packet(tx[i], 10000) + + rxs = self.send_and_expect_some(self.pg0, tx, self.pg0) + for rx in rxs: + rx[ICMPv6PacketTooBig].mtu = 9000 + # # cleanup # -- cgit 1.2.3-korg