xref: /openbsd-src/regress/sys/net/pf_fragment/frag_cutnew.py (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#!/usr/local/bin/python2.7
2# start of new fragment overlaps old one
3
4# |--------|
5#     |>>>>>----|
6
7# If the tail of an older fragment overlaps the beginning of the
8# current fragment, cut the newer fragment.
9#                 m_adj(frent->fe_m, precut);
10# Newer data wins.
11
12import os
13from addr import *
14from scapy.all import *
15
16dstaddr=sys.argv[1]
17pid=os.getpid() & 0xffff
18payload="ABCDEFGHIJKLOMNO"
19dummy="01234567"
20packet=IP(src=SRC_OUT, dst=dstaddr)/ICMP(id=pid)/payload
21frag0=str(packet)[20:36]
22frag1=dummy+str(packet)[36:44]
23pkt0=IP(src=SRC_OUT, dst=dstaddr, proto=1, id=pid, frag=0, flags='MF')/frag0
24pkt1=IP(src=SRC_OUT, dst=dstaddr, proto=1, id=pid, frag=1)/frag1
25eth=[]
26eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
27eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
28
29if os.fork() == 0:
30	time.sleep(1)
31	sendp(eth, iface=SRC_IF)
32	os._exit(0)
33
34ans=sniff(iface=SRC_IF, timeout=3, filter=
35    "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
36a=ans[0]
37if a and a.type == ETH_P_IP and \
38    a.payload.proto == 1 and \
39    a.payload.frag == 0 and a.payload.flags == 0 and \
40    icmptypes[a.payload.payload.type] == 'echo-reply':
41	id=a.payload.payload.id
42	print "id=%#x" % (id)
43	if id != pid:
44		print "WRONG ECHO REPLY ID"
45		exit(2)
46	load=a.payload.payload.payload.load
47	print "payload=%s" % (load)
48	if load == payload:
49		exit(0)
50	print "PAYLOAD!=%s" % (payload)
51	exit(1)
52print "NO ECHO REPLY"
53exit(2)
54