xref: /freebsd/tests/sys/netinet6/mld.py (revision 32af08ecad3fe435ee646791e345526b5bcb7795)
1*32af08ecSBjoern A. Zeeb#!/usr/bin/env python
2*32af08ecSBjoern A. Zeeb#-
3*32af08ecSBjoern A. Zeeb# SPDX-License-Identifier: BSD-2-Clause
4*32af08ecSBjoern A. Zeeb#
5*32af08ecSBjoern A. Zeeb# Copyright (c) 2019 Netflix, Inc.
6*32af08ecSBjoern A. Zeeb#
7*32af08ecSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
8*32af08ecSBjoern A. Zeeb# modification, are permitted provided that the following conditions
9*32af08ecSBjoern A. Zeeb# are met:
10*32af08ecSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
11*32af08ecSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
12*32af08ecSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
13*32af08ecSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
14*32af08ecSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
15*32af08ecSBjoern A. Zeeb#
16*32af08ecSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*32af08ecSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*32af08ecSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*32af08ecSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*32af08ecSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*32af08ecSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*32af08ecSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*32af08ecSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*32af08ecSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*32af08ecSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*32af08ecSBjoern A. Zeeb# SUCH DAMAGE.
27*32af08ecSBjoern A. Zeeb#
28*32af08ecSBjoern A. Zeeb# $FreeBSD$
29*32af08ecSBjoern A. Zeeb#
30*32af08ecSBjoern A. Zeeb
31*32af08ecSBjoern A. Zeebimport argparse
32*32af08ecSBjoern A. Zeebimport scapy.all as sp
33*32af08ecSBjoern A. Zeebimport socket
34*32af08ecSBjoern A. Zeebimport sys
35*32af08ecSBjoern A. Zeebimport binascii
36*32af08ecSBjoern A. Zeeb
37*32af08ecSBjoern A. Zeebdef main():
38*32af08ecSBjoern A. Zeeb	parser = argparse.ArgumentParser("scapyi386.py",
39*32af08ecSBjoern A. Zeeb		description="IPv6 Ethernet Dest MAC test")
40*32af08ecSBjoern A. Zeeb	parser.add_argument('--sendif', nargs=1,
41*32af08ecSBjoern A. Zeeb		required=True,
42*32af08ecSBjoern A. Zeeb		help='The interface through which the packet will be sent')
43*32af08ecSBjoern A. Zeeb	parser.add_argument('--recvif', nargs=1,
44*32af08ecSBjoern A. Zeeb		required=True,
45*32af08ecSBjoern A. Zeeb		help='The interface on which to check for the packet')
46*32af08ecSBjoern A. Zeeb	parser.add_argument('--src', nargs=1,
47*32af08ecSBjoern A. Zeeb		required=True,
48*32af08ecSBjoern A. Zeeb		help='The source IP address')
49*32af08ecSBjoern A. Zeeb	parser.add_argument('--to', nargs=1,
50*32af08ecSBjoern A. Zeeb		required=True,
51*32af08ecSBjoern A. Zeeb		help='The destination IP address')
52*32af08ecSBjoern A. Zeeb	parser.add_argument('--debug',
53*32af08ecSBjoern A. Zeeb		required=False, action='store_true',
54*32af08ecSBjoern A. Zeeb		help='Enable test debugging')
55*32af08ecSBjoern A. Zeeb	parser.add_argument('--mldraw01',
56*32af08ecSBjoern A. Zeeb		required=False, action='store_true',
57*32af08ecSBjoern A. Zeeb		help='Multicast Listener Query Raw01')
58*32af08ecSBjoern A. Zeeb
59*32af08ecSBjoern A. Zeeb	args = parser.parse_args()
60*32af08ecSBjoern A. Zeeb
61*32af08ecSBjoern A. Zeeb	pkt = None
62*32af08ecSBjoern A. Zeeb	if args.mldraw01:
63*32af08ecSBjoern A. Zeeb		pkt = sp.Ether() / \
64*32af08ecSBjoern A. Zeeb			sp.IPv6(dst="ff02::1", hlim=1, nh=0) / \
65*32af08ecSBjoern A. Zeeb			sp.IPv6ExtHdrHopByHop(options = sp.RouterAlert(value=0)) / \
66*32af08ecSBjoern A. Zeeb			sp.ICMPv6MLQuery()
67*32af08ecSBjoern A. Zeeb	if pkt is None:
68*32af08ecSBjoern A. Zeeb		sys.exit(1)
69*32af08ecSBjoern A. Zeeb	if args.debug:
70*32af08ecSBjoern A. Zeeb		pkt.display()
71*32af08ecSBjoern A. Zeeb	sp.sendp(pkt, iface=args.sendif[0], verbose=False)
72*32af08ecSBjoern A. Zeeb
73*32af08ecSBjoern A. Zeeb	sys.exit(0)
74*32af08ecSBjoern A. Zeeb
75*32af08ecSBjoern A. Zeebif __name__ == '__main__':
76*32af08ecSBjoern A. Zeeb	main()
77