xref: /freebsd/tests/sys/netinet6/frag6/frag6_19.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
31*a26e895fSKristof Provostimport logging
32*a26e895fSKristof Provostlogging.getLogger("scapy").setLevel(logging.CRITICAL)
33f74e6e49SBjoern A. Zeebimport scapy.all as sp
34f74e6e49SBjoern A. Zeebimport socket
35f74e6e49SBjoern A. Zeebimport sys
36f74e6e49SBjoern A. Zeeb
37f74e6e49SBjoern A. Zeebdef main():
38f74e6e49SBjoern A. Zeeb	parser = argparse.ArgumentParser("frag6.py",
39f74e6e49SBjoern A. Zeeb		description="IPv6 fragementation test tool")
40f74e6e49SBjoern A. Zeeb	parser.add_argument('--sendif', nargs=1,
41f74e6e49SBjoern A. Zeeb		required=True,
42f74e6e49SBjoern A. Zeeb		help='The interface through which the packet will be sent')
43f74e6e49SBjoern A. Zeeb	parser.add_argument('--recvif', nargs=1,
44f74e6e49SBjoern A. Zeeb		required=True,
45f74e6e49SBjoern A. Zeeb		help='The interface on which to check for the packet')
46f74e6e49SBjoern A. Zeeb	parser.add_argument('--src', nargs=1,
47f74e6e49SBjoern A. Zeeb		required=True,
48f74e6e49SBjoern A. Zeeb		help='The source IP address')
49f74e6e49SBjoern A. Zeeb	parser.add_argument('--to', nargs=1,
50f74e6e49SBjoern A. Zeeb		required=True,
51f74e6e49SBjoern A. Zeeb		help='The destination IP address')
52f74e6e49SBjoern A. Zeeb	parser.add_argument('--debug',
53f74e6e49SBjoern A. Zeeb		required=False, action='store_true',
54f74e6e49SBjoern A. Zeeb		help='Enable test debugging')
55f74e6e49SBjoern A. Zeeb
56f74e6e49SBjoern A. Zeeb	args = parser.parse_args()
57f74e6e49SBjoern A. Zeeb
58f74e6e49SBjoern A. Zeeb
59f74e6e49SBjoern A. Zeeb	########################################################################
60f74e6e49SBjoern A. Zeeb	#
61f74e6e49SBjoern A. Zeeb	# Send a sample of sequeneced ID fragments into the system in order
62f74e6e49SBjoern A. Zeeb	# to test bucket distribution.
63f74e6e49SBjoern A. Zeeb	#
64f74e6e49SBjoern A. Zeeb	# A:  No overflow at V_ip6_maxfragsperpacket == 64.
65f74e6e49SBjoern A. Zeeb	# R:  Stats only, timeout and no ICMPv6 (all ignored).
66f74e6e49SBjoern A. Zeeb	#
67f74e6e49SBjoern A. Zeeb	packets = [];
68f74e6e49SBjoern A. Zeeb	data = "66666666"
69f74e6e49SBjoern A. Zeeb	for i in range(0,127):
70f74e6e49SBjoern A. Zeeb		ip6f01 = sp.Ether() / \
71f74e6e49SBjoern A. Zeeb			sp.IPv6(src=args.src[0], dst=args.to[0]) / \
72f74e6e49SBjoern A. Zeeb			sp.IPv6ExtHdrFragment(offset=1, m=1, id=i) / \
73f74e6e49SBjoern A. Zeeb			data
74f74e6e49SBjoern A. Zeeb		if args.debug:
75f74e6e49SBjoern A. Zeeb			ip6f01.display()
76f74e6e49SBjoern A. Zeeb		packets.append(ip6f01)
77f74e6e49SBjoern A. Zeeb
78f74e6e49SBjoern A. Zeeb	for p in packets:
79f74e6e49SBjoern A. Zeeb		sp.sendp(p, iface=args.sendif[0], verbose=False)
80f74e6e49SBjoern A. Zeeb
81f74e6e49SBjoern A. Zeeb	sys.exit(0)
82f74e6e49SBjoern A. Zeeb
83f74e6e49SBjoern A. Zeebif __name__ == '__main__':
84f74e6e49SBjoern A. Zeeb	main()
85