1#!/bin/ksh 2# $OpenBSD: carp_1.sh,v 1.3 2024/01/05 10:37:54 anton Exp $ 3 4 5cleanup() 6{ 7 for if in $ALL_IFS; do 8 ifconfig $if destroy 2>/dev/null 9 done 10 for i in $RDOMAINS; do 11 ifconfig lo$i destroy 2>/dev/null 12 done 13} 14 15CURDIR=$(cd $(dirname $0); pwd) 16 17. ${CURDIR}/carp_subr 18 19# rdomains 20set -- $RDOMAINS 21if [ $# -lt 2 ]; then 22 echo "2 rdomain(-R option) is required" >&2 23 exit 64 24fi 25RD1=$1 26RD2=$2 27IFGPREFIX=$(printf "regress%04x" $$) 28 29# interface minor numbers 30set -- $IFACE_NUMS 31if [ $# -lt 2 ]; then 32 echo "2 interface numbers(-I option) is required" >&2 33 exit 64 34fi 35IFNO1=$1 36IFNO2=$2 37 38ALL_IFS="carp$IFNO1 carp$IFNO2 pair$IFNO1 pair$IFNO2" 39 40[ $CLEANUP -gt 0 ] && cleanup 41# 42# Check pre-conditions 43# 44# interfaces are busy? 45for if in $ALL_IFS; do 46 if iface_exists $if; then 47 echo "Aborted. interface \`$if' is used already." >&2 48 exit 255 49 fi 50done 51# rdomains are busy? 52for rt in $RD1 $RD2; do 53 if ! rdomain_is_used $rt; then 54 echo "Aborted. rdomain \`$rt' is used already." >&2 55 exit 255 56 fi 57done 58 59# 60# Prepeare the test 61# 62[ $VERBOSE -gt 0 ] && set -x 63ifconfig pair$IFNO1 rdomain $RD1 192.168.0.2/24 64ifconfig pair$IFNO2 rdomain $RD2 192.168.0.3/24 patch pair$IFNO1 65 66# 67# Test config 68# 69ifconfig carp$IFNO1 rdomain $RD1 192.168.0.1/24 \ 70 vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \ 71 || abort_test 72ifconfig carp$IFNO2 rdomain $RD2 192.168.0.1/24 \ 73 vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b advskew 100 \ 74 || abort_test 75 76# 77# Test behavior 78# 79 80# IFNO1 must become master 81wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'" 82test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'" 83test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'" 84 85# carpdemote must work 86ifconfig -g ${IFGPREFIX}a carpdemote 87wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'" 88test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'" 89test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'" 90 91# Done 92cleanup 93exit $FAILS 94