1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2006 International Business Machines  Corp.
4f08c3bdfSopenharmony_ci# Copyright (c) 2020 Joerg Vehlow <joerg.vehlow@aox-tech.de>
5f08c3bdfSopenharmony_ci# Author: Mitsuru Chinen <mitch@jp.ibm.com>
6f08c3bdfSopenharmony_ci#
7f08c3bdfSopenharmony_ci# Verify that the kernel is not crashed when joining multiple
8f08c3bdfSopenharmony_ci# multicast groups on separate sockets, then receiving a large number of
9f08c3bdfSopenharmony_ci# Multicast Address Specific Queries
10f08c3bdfSopenharmony_ci
11f08c3bdfSopenharmony_ciTST_NEEDS_ROOT=1
12f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1
13f08c3bdfSopenharmony_ciTST_SETUP="mcast_setup_normal"
14f08c3bdfSopenharmony_ciTST_CLEANUP="mcast_cleanup"
15f08c3bdfSopenharmony_ciTST_TESTFUNC="do_test"
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_cido_test()
18f08c3bdfSopenharmony_ci{
19f08c3bdfSopenharmony_ci	tst_res TINFO "joining $MCASTNUM_NORMAL IPv${TST_IPVER} multicast groups on separate sockets, then receiving a large number of Multicast Address Specific Queries in $NS_DURATION seconds"
20f08c3bdfSopenharmony_ci
21f08c3bdfSopenharmony_ci	local prefix="$MCAST_IPV4_ADDR_PREFIX"
22f08c3bdfSopenharmony_ci	[ "$TST_IPV6" ] && prefix="$MCAST_IPV6_ADDR_PREFIX"
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_ci	# Run a multicast join tool
25f08c3bdfSopenharmony_ci	local tmpfile=$$
26f08c3bdfSopenharmony_ci	EXPECT_PASS $MCAST_LCMD -n $MCASTNUM_NORMAL -p $prefix \> $tmpfile
27f08c3bdfSopenharmony_ci	tst_res TINFO "joined $(grep groups $tmpfile)"
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_ci	# Send IGMP Multicast Address Specific Query from the remote host
30f08c3bdfSopenharmony_ci	local n=0
31f08c3bdfSopenharmony_ci	while [ $n -lt $MCASTNUM_NORMAL ]; do
32f08c3bdfSopenharmony_ci		# Define the multicast address
33f08c3bdfSopenharmony_ci		if [ "$TST_IPV6" ]; then
34f08c3bdfSopenharmony_ci			local n_hex=$(printf "%x" $n)
35f08c3bdfSopenharmony_ci			local addr=${MCAST_IPV6_ADDR_PREFIX}:${n_hex}
36f08c3bdfSopenharmony_ci		else
37f08c3bdfSopenharmony_ci			local x=$((n / 254))
38f08c3bdfSopenharmony_ci			local y=$((n % 254 + 1))
39f08c3bdfSopenharmony_ci			local addr=${MCAST_IPV4_ADDR_PREFIX}.${x}.${y}
40f08c3bdfSopenharmony_ci		fi
41f08c3bdfSopenharmony_ci
42f08c3bdfSopenharmony_ci		local params="-m $addr"
43f08c3bdfSopenharmony_ci		[ "$TST_IPV6" ] && params="-S $(tst_ipaddr) -m -D $addr"
44f08c3bdfSopenharmony_ci		tst_rhost_run -c "$MCAST_RCMD -t $NS_DURATION -r 0 -b $params"
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_ci		n=$((n+1))
47f08c3bdfSopenharmony_ci	done
48f08c3bdfSopenharmony_ci
49f08c3bdfSopenharmony_ci	sleep $NS_DURATION
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci	tst_res TPASS "test finished successfully"
52f08c3bdfSopenharmony_ci}
53f08c3bdfSopenharmony_ci
54f08c3bdfSopenharmony_ci. mcast-lib.sh
55f08c3bdfSopenharmony_citst_run
56