1#!/usr/local/bin/python2.7
2# check wether path mtu to dst is 1300
3
4import os
5from addr import *
6from scapy.all import *
7
8dstaddr=sys.argv[1]
9pid=os.getpid() & 0xffff
10hdr=IPv6(src=SRC_OUT6, dst=dstaddr)/ICMPv6EchoRequest(id=pid)
11payload="a" * (1400 - len(str(hdr)))
12ip=hdr/payload
13eth=Ether(src=SRC_MAC, dst=PF_MAC)/ip
14
15# work around the broken sniffing of packages with bad checksum
16#a=srp1(eth, iface=SRC_IF, timeout=2)
17if os.fork() == 0:
18	time.sleep(1)
19	sendp(eth, iface=SRC_IF)
20	os._exit(0)
21ans=sniff(iface=SRC_IF, timeout=3, filter=
22    "ip6 and dst "+SRC_OUT6+" and icmp6")
23if len(ans) == 0:
24	print "no packet sniffed"
25	exit(2)
26a=ans[0]
27
28if a and a.type == ETH_P_IPV6 and \
29    ipv6nh[a.payload.nh] == 'ICMPv6' and \
30    icmp6types[a.payload.payload.type] == 'Packet too big':
31	mtu=a.payload.payload.mtu
32	print "mtu=%d" % (mtu)
33	if mtu == 1300:
34		exit(0)
35	print "MTU!=1300"
36	exit(1)
37print "MTU=UNKNOWN"
38exit(2)
39