1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz> 4# Copyright (c) International Business Machines Corp., 2006 5# Author: Petr Vorel <pvorel@suse.cz> 6# 7# Setup script for multicast stress tests. 8 9. tst_net_stress.sh 10 11mcast_setup4() 12{ 13 local igmp_max_memberships="$1" 14 15 SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships) 16 SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf) 17 SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version) 18 SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version) 19 20 [ "$igmp_max_memberships" -gt 5459 ] && tst_res TWARN \ 21 "\$1 shouldn't be set higher than 5459 as it's used to set /proc/sys/net/ipv4/igmp_max_memberships" 22 23 ROD sysctl -q -w net.ipv4.igmp_max_memberships=$igmp_max_memberships 24 ROD sysctl -q -w net.ipv4.igmp_max_msf=10 25 ROD sysctl -q -w net.ipv4.conf.$(tst_iface).force_igmp_version=0 26 ROD sysctl -q -w net.ipv4.conf.all.force_igmp_version=0 27} 28 29mcast_setup6() 30{ 31 local default_mld_max_msf=64 32 tst_kvcmp -lt '2.6.15' && default_mld_max_msf=10 33 34 SYSCTL_ALL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.all.force_mld_version) 35 SYSCTL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.$(tst_iface).force_mld_version) 36 SYSCTL_MLD_MAX_MSF=$(sysctl -b net.ipv6.mld_max_msf) 37 38 ROD sysctl -q -w net.ipv6.conf.all.force_mld_version=0 39 ROD sysctl -q -w net.ipv6.conf.$(tst_iface).force_mld_version=0 40 ROD sysctl -q -w net.ipv6.mld_max_msf=$default_mld_max_msf 41} 42 43mcast_setup() 44{ 45 local max="$1" 46 47 MCAST_LCMD="ns-mcast_join -f $TST_IPVER -I $(tst_iface)" 48 49 local cmd="ns-igmp_querier" 50 [ "$TST_IPV6" ] && cmd="ns-icmpv6_sender" 51 MCAST_RCMD="$cmd -I $(tst_iface rhost)" 52 53 netstress_setup 54 55 [ "$TST_IPV6" ] && mcast_setup6 || mcast_setup4 $max 56} 57 58mcast_setup_normal() 59{ 60 mcast_setup $MCASTNUM_NORMAL 61} 62 63mcast_setup_normal_udp() 64{ 65 mcast_setup_normal 66 MCAST_LCMD="ns-mcast_receiver" 67 MCAST_RCMD="ns-udpsender" 68} 69 70mcast_cleanup4() 71{ 72 [ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -q -w net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS 73 [ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -q -w net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF 74 [ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -q -w net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION 75 [ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -q -w net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION 76} 77 78mcast_cleanup6() 79{ 80 [ -n "$SYSCTL_ALL_FORCE_MLD_VERSION" ] && sysctl -q -w net.ipv6.conf.all.force_mld_version=$SYSCTL_ALL_FORCE_MLD_VERSION 81 [ -n "$SYSCTL_FORCE_MLD_VERSION" ] && sysctl -q -w net.ipv6.conf.$(tst_iface).force_mld_version=$SYSCTL_FORCE_MLD_VERSION 82 [ -n "$SYSCTL_MLD_MAX_MSF" ] && sysctl -q -w net.ipv6.mld_max_msf=$SYSCTL_MLD_MAX_MSF 83} 84 85mcast_cleanup() 86{ 87 [ "$TST_IPV6" ] && mcast_cleanup6 || mcast_cleanup4 88 89 pkill -SIGHUP -f "$MCAST_LCMD" 90 tst_sleep 10ms 91 pkill -9 -f "$MCAST_LCMD" 92 93 tst_rhost_run -c "pkill -SIGHUP -f '$MCAST_RCMD'" 94} 95 96do_multicast_test_multiple_join() 97{ 98 local num="$1" 99 local mprefix="$MCAST_IPV4_ADDR_PREFIX" 100 local param_multi_socket ret tmpfile 101 102 [ "${2:-}" = true ] && param_multi_socket="-m" 103 [ "$TST_IPV6" ] && mprefix="$MCAST_IPV6_ADDR_PREFIX" 104 105 # Run a multicast join tool 106 tmpfile=$$ 107 EXPECT_PASS $MCAST_LCMD $param_multi_socket -n $num -p $mprefix \> $tmpfile 108 tst_res TINFO "joined $(grep groups $tmpfile)" 109 110 # Send MLD / IGMP General Query from the remote host 111 if [ "$TST_IPV6" ]; then 112 EXPECT_RHOST_PASS $MCAST_RCMD -S $(tst_ipaddr) -m -o 113 else 114 EXPECT_RHOST_PASS $MCAST_RCMD -o -r 1 -m $MCAST_IPV4_ADDR 115 fi 116} 117 118do_multicast_test_join_leave() 119{ 120 local cnt define_src_addr filter params pid pids ret 121 local max="$1" 122 local maddr="$MCAST_IPV4_ADDR" 123 [ "$TST_IPV6" ] && maddr="$MCAST_IPV6_ADDR" 124 125 [ "$2" = true ] && define_src_addr=true 126 127 # Send MLD / IGMP General Query from the remote host 128 if [ "$TST_IPV6" ]; then 129 tst_rhost_run -s -c "$MCAST_RCMD -S $(tst_ipaddr) -m -w 1000000000 -r 1000 -b" 130 else 131 tst_rhost_run -s -c "$MCAST_RCMD -i 1000000000 -r 1 -b" 132 fi 133 134 # Run a multicast join tool 135 cnt=0 136 while [ $cnt -lt $max ]; do 137 if [ "$define_src_addr" ]; then 138 [ $((cnt % 5)) -ne 2 ] && filter="include" || filter="exclude" 139 params="-F $filter -s $(tst_ipaddr_un -c$cnt)" 140 fi 141 142 $MCAST_LCMD -l $NS_TIMES -a $maddr $params & 143 pids="$! $pids" 144 cnt=$((cnt + 1)) 145 done 146 147 for pid in $pids; do wait $pid; done 148 149 tst_res TPASS "test is finished successfully" 150} 151 152do_multicast_test_join_single_socket() 153{ 154 local extra="$1" 155 local prefix="$MCAST_IPV4_ADDR_PREFIX" 156 [ "$TST_IPV6" ] && prefix="$MCAST_IPV6_ADDR_PREFIX" 157 158 # Run a multicast join tool 159 local tmpfile=$$ 160 EXPECT_PASS $MCAST_LCMD -n 1 -p $prefix \> $tmpfile 161 tst_res TINFO "joined $(grep groups $tmpfile)" 162 163 local params 164 [ "$TST_IPV6" ] && params="-S $(tst_ipaddr) -m" 165 EXPECT_RHOST_PASS $MCAST_RCMD -t $NS_DURATION -r 0 $params $extra 166} 167