xref: /freebsd/tests/sys/netinet6/frag6/frag6_18.py (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1f74e6e49SBjoern A. Zeeb#!/usr/bin/env python
2f74e6e49SBjoern A. Zeeb#-
3f74e6e49SBjoern A. Zeeb# SPDX-License-Identifier: BSD-2-Clause
4f74e6e49SBjoern A. Zeeb#
5f74e6e49SBjoern A. Zeeb# Copyright (c) 2019 Netflix, Inc.
6f74e6e49SBjoern A. Zeeb#
7f74e6e49SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
8f74e6e49SBjoern A. Zeeb# modification, are permitted provided that the following conditions
9f74e6e49SBjoern A. Zeeb# are met:
10f74e6e49SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
11f74e6e49SBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
12f74e6e49SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
13f74e6e49SBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
14f74e6e49SBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
15f74e6e49SBjoern A. Zeeb#
16f74e6e49SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17f74e6e49SBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f74e6e49SBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f74e6e49SBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20f74e6e49SBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f74e6e49SBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f74e6e49SBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f74e6e49SBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f74e6e49SBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f74e6e49SBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f74e6e49SBjoern A. Zeeb# SUCH DAMAGE.
27f74e6e49SBjoern A. Zeeb#
28f74e6e49SBjoern A. Zeeb#
29f74e6e49SBjoern A. Zeeb
30f74e6e49SBjoern A. Zeebimport argparse
31f74e6e49SBjoern A. Zeebimport random as random
32*a26e895fSKristof Provostimport logging
33*a26e895fSKristof Provostlogging.getLogger("scapy").setLevel(logging.CRITICAL)
34f74e6e49SBjoern A. Zeebimport scapy.all as sp
35f74e6e49SBjoern A. Zeebimport socket
36f74e6e49SBjoern A. Zeebimport sys
37f74e6e49SBjoern A. Zeeb
38f74e6e49SBjoern A. Zeebdef main():
39f74e6e49SBjoern A. Zeeb	parser = argparse.ArgumentParser("frag6.py",
40f74e6e49SBjoern A. Zeeb		description="IPv6 fragementation test tool")
41f74e6e49SBjoern A. Zeeb	parser.add_argument('--sendif', nargs=1,
42f74e6e49SBjoern A. Zeeb		required=True,
43f74e6e49SBjoern A. Zeeb		help='The interface through which the packet will be sent')
44f74e6e49SBjoern A. Zeeb	parser.add_argument('--recvif', nargs=1,
45f74e6e49SBjoern A. Zeeb		required=True,
46f74e6e49SBjoern A. Zeeb		help='The interface on which to check for the packet')
47f74e6e49SBjoern A. Zeeb	parser.add_argument('--src', nargs=1,
48f74e6e49SBjoern A. Zeeb		required=True,
49f74e6e49SBjoern A. Zeeb		help='The source IP address')
50f74e6e49SBjoern A. Zeeb	parser.add_argument('--to', nargs=1,
51f74e6e49SBjoern A. Zeeb		required=True,
52f74e6e49SBjoern A. Zeeb		help='The destination IP address')
53f74e6e49SBjoern A. Zeeb	parser.add_argument('--debug',
54f74e6e49SBjoern A. Zeeb		required=False, action='store_true',
55f74e6e49SBjoern A. Zeeb		help='Enable test debugging')
56f74e6e49SBjoern A. Zeeb
57f74e6e49SBjoern A. Zeeb	args = parser.parse_args()
58f74e6e49SBjoern A. Zeeb
59f74e6e49SBjoern A. Zeeb
60f74e6e49SBjoern A. Zeeb	########################################################################
61f74e6e49SBjoern A. Zeeb	#
62f74e6e49SBjoern A. Zeeb	# Send a sample of pseudo-random fragments into the system in order
63f74e6e49SBjoern A. Zeeb	# to test vnet teardown.
64f74e6e49SBjoern A. Zeeb	#
65f74e6e49SBjoern A. Zeeb	# A:  Cleaned up and freed
66f74e6e49SBjoern A. Zeeb	# R:  No panic (ignoring everything else)
67f74e6e49SBjoern A. Zeeb	#
68f74e6e49SBjoern A. Zeeb
69f74e6e49SBjoern A. Zeeb	random.seed()
70f74e6e49SBjoern A. Zeeb	packets = [];
71f74e6e49SBjoern A. Zeeb
72f74e6e49SBjoern A. Zeeb	for i in range(0,127):
73f74e6e49SBjoern A. Zeeb		fid=random.randint(0,0xffff)
74f74e6e49SBjoern A. Zeeb		foffset=random.randint(0,0xffff)
75f74e6e49SBjoern A. Zeeb		fm=random.randint(0,1)
76f74e6e49SBjoern A. Zeeb		fsrc=sp.RandIP6()
77f74e6e49SBjoern A. Zeeb		ip6f01 = sp.Ether() / \
78f74e6e49SBjoern A. Zeeb			sp.IPv6(src=fsrc, dst=args.to[0]) / \
79f74e6e49SBjoern A. Zeeb			sp.IPv6ExtHdrFragment(offset=foffset, m=fm, id=fid) / \
80f74e6e49SBjoern A. Zeeb			sp.UDP(dport=3456, sport=6543)
81f74e6e49SBjoern A. Zeeb		if args.debug:
82f74e6e49SBjoern A. Zeeb			ip6f01.display()
83f74e6e49SBjoern A. Zeeb		packets.append(ip6f01)
84f74e6e49SBjoern A. Zeeb
85f74e6e49SBjoern A. Zeeb	for p in packets:
86f74e6e49SBjoern A. Zeeb		sp.sendp(p, iface=args.sendif[0], verbose=False)
87f74e6e49SBjoern A. Zeeb
88f74e6e49SBjoern A. Zeeb	sys.exit(0)
89f74e6e49SBjoern A. Zeeb
90f74e6e49SBjoern A. Zeebif __name__ == '__main__':
91f74e6e49SBjoern A. Zeeb	main()
92