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