3 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2012-2021 Alexander Bluhm <bluhm@openbsd.org>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 from fragcommon import *
21 # index boundary 4096 |
29 # this should trigger "frag tail overlap %d" and "frag head overlap %d"
31 def send(src, dst, send_if, recv_if):
34 payload = b"ABCDEFGHIJKLMNOP"
38 fragnum = int(boundary / fragsize)
39 packet = sp.IP(src=src, dst=dst)/ \
40 sp.ICMP(type='echo-request', id=eid)/ \
41 (int((boundary + fragsize) / len(payload)) * payload)
45 for i in range(fragnum - 1):
46 frag.append(sp.IP(src=src, dst=dst, proto=1, id=fid,
47 frag=(i * fragsize) >> 3, flags='MF') /
48 bytes(packet)[20 + i * fragsize:20 + (i + 1) * fragsize])
49 frag.append(sp.IP(src=src, dst=dst, proto=1, id=fid,
50 frag=(boundary - 8) >> 3, flags='MF') /
51 (dummy + bytes(packet)[20 + boundary:20 + boundary + 8]))
52 frag.append(sp.IP(src=src, dst=dst, proto=1, id=fid,
53 frag=(boundary - fragsize) >> 3, flags='MF') /
54 bytes(packet)[20 + boundary - fragsize:20 + boundary])
55 frag.append(sp.IP(src=src, dst=dst, proto=1, id=fid,
56 frag=(boundary) >> 3)/bytes(packet)[20 + boundary:])
60 eth.append(sp.Ether() / f)
65 sp.sendp(e, iface=send_if)
69 ans = sp.sniff(iface=recv_if, timeout=3, filter="")
71 if a and a.type == sp.ETH_P_IP and \
72 a.payload.proto == 1 and \
73 a.payload.frag == 0 and \
74 sp.icmptypes[a.payload.payload.type] == 'echo-reply':
75 id=a.payload.payload.id
77 print("WRONG ECHO REPLY ID")
80 print("NO ECHO REPLY")
83 if __name__ == '__main__':