summaryrefslogtreecommitdiffstats
path: root/regress/sys/net/pf_fragment/ping6_mtu_1300.py
blob: 8eac4ad72364cc5224cfe1824b078e544e8646eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/local/bin/python3
# check wether path mtu to dst is 1300

import os
import threading
from addr import *
from scapy.all import *

# work around the broken sniffing of packages with bad checksum
#a=srp1(eth, iface=SRC_IF, timeout=2)
class Sniff1(threading.Thread):
	filter = None
	captured = None
	packet = None
	def run(self):
		self.captured = sniff(iface=SRC_IF, filter=self.filter,
		    count=1, timeout=3)
		if self.captured:
			self.packet = self.captured[0]

dstaddr=sys.argv[1]
eid=os.getpid() & 0xffff
hdr=IPv6(src=SRC_OUT6, dst=dstaddr)/ICMPv6EchoRequest(id=eid)
payload=b"a" * (1400 - len(bytes(hdr)))
ip=hdr/payload
eth=Ether(src=SRC_MAC, dst=PF_MAC)/ip

sniffer = Sniff1();
# pcap cannot access icmp6, check for packet too big, avoid neighbor discovery
sniffer.filter = "ip6 and dst %s and icmp6 and ip6[40] = 2 and ip6[41] = 0" \
    % SRC_OUT6
sniffer.start()
time.sleep(1)
sendp(eth, iface=SRC_IF)
sniffer.join(timeout=5)
a = sniffer.packet

if a is None:
	print("no packet sniffed")
	exit(2)
if a and a.type == ETH_P_IPV6 and \
    ipv6nh[a.payload.nh] == 'ICMPv6' and \
    icmp6types[a.payload.payload.type] == 'Packet too big':
	mtu=a.payload.payload.mtu
	print("mtu=%d" % (mtu))
	if mtu == 1300:
		exit(0)
	print("MTU!=1300")
	exit(1)
print("MTU=UNKNOWN")
exit(2)