xref: /freebsd/tests/sys/netinet6/frag6/frag6_11.py (revision e32221a15f089282e5dfe18891c5312b26cbe3ba)
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# $FreeBSD$
29f74e6e49SBjoern A. Zeeb#
30f74e6e49SBjoern A. Zeeb
31f74e6e49SBjoern A. Zeebimport argparse
32a26e895fSKristof Provostimport logging
33a26e895fSKristof Provostlogging.getLogger("scapy").setLevel(logging.CRITICAL)
34f74e6e49SBjoern A. Zeebimport scapy.all as sp
35f74e6e49SBjoern A. Zeebimport socket
36f74e6e49SBjoern A. Zeebimport sys
37f74e6e49SBjoern A. Zeebfrom time import sleep
38f74e6e49SBjoern A. Zeeb
39f74e6e49SBjoern A. Zeebdef main():
40f74e6e49SBjoern A. Zeeb	parser = argparse.ArgumentParser("frag6.py",
41f74e6e49SBjoern A. Zeeb		description="IPv6 fragementation test tool")
42f74e6e49SBjoern A. Zeeb	parser.add_argument('--sendif', nargs=1,
43f74e6e49SBjoern A. Zeeb		required=True,
44f74e6e49SBjoern A. Zeeb		help='The interface through which the packet will be sent')
45f74e6e49SBjoern A. Zeeb	parser.add_argument('--recvif', nargs=1,
46f74e6e49SBjoern A. Zeeb		required=True,
47f74e6e49SBjoern A. Zeeb		help='The interface on which to check for the packet')
48f74e6e49SBjoern A. Zeeb	parser.add_argument('--src', nargs=1,
49f74e6e49SBjoern A. Zeeb		required=True,
50f74e6e49SBjoern A. Zeeb		help='The source IP address')
51f74e6e49SBjoern A. Zeeb	parser.add_argument('--to', nargs=1,
52f74e6e49SBjoern A. Zeeb		required=True,
53f74e6e49SBjoern A. Zeeb		help='The destination IP address')
54f74e6e49SBjoern A. Zeeb	parser.add_argument('--debug',
55f74e6e49SBjoern A. Zeeb		required=False, action='store_true',
56f74e6e49SBjoern A. Zeeb		help='Enable test debugging')
57f74e6e49SBjoern A. Zeeb
58f74e6e49SBjoern A. Zeeb	args = parser.parse_args()
59f74e6e49SBjoern A. Zeeb
60f74e6e49SBjoern A. Zeeb
61f74e6e49SBjoern A. Zeeb	########################################################################
62f74e6e49SBjoern A. Zeeb	#
63f74e6e49SBjoern A. Zeeb	# A single last fragment.
64f74e6e49SBjoern A. Zeeb	#
65f74e6e49SBjoern A. Zeeb	# A:  Waiting for more data.
66f74e6e49SBjoern A. Zeeb	# R:  Timeout / Expiry.
67f74e6e49SBjoern A. Zeeb	#
68f74e6e49SBjoern A. Zeeb	ip6f01 = sp.Ether() / \
69f74e6e49SBjoern A. Zeeb		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
70f74e6e49SBjoern A. Zeeb		sp.IPv6ExtHdrFragment(offset=321, m=0, id=8) / \
71f74e6e49SBjoern A. Zeeb		sp.UDP(dport=3456, sport=6543)
72f74e6e49SBjoern A. Zeeb	if args.debug :
73f74e6e49SBjoern A. Zeeb		ip6f01.display()
74f74e6e49SBjoern A. Zeeb	sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
75f74e6e49SBjoern A. Zeeb
76f74e6e49SBjoern A. Zeeb	# Wait for expiration to happen.  We will not see an ICMPv6 as there
77f74e6e49SBjoern A. Zeeb	# is no frag with offset=0.
78*e32221a1SAlexander V. Chernikov	sleep(3)
79f74e6e49SBjoern A. Zeeb
80f74e6e49SBjoern A. Zeeb	sys.exit(0)
81f74e6e49SBjoern A. Zeeb
82f74e6e49SBjoern A. Zeebif __name__ == '__main__':
83f74e6e49SBjoern A. Zeeb	main()
84