xref: /openbsd-src/regress/sys/netinet/carp/carp_2.sh (revision c24fef859b84213393d09cfc2c7bf9f73d5f0604)
1#!/bin/ksh
2#	$OpenBSD: carp_2.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
66lladdr1=$(ifconfig pair$IFNO1 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
67lladdr2=$(ifconfig pair$IFNO2 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
68
69#
70# Test config
71#
72ifconfig carp$IFNO1 rdomain $RD1 lladdr $lladdr1 192.168.0.1/24 \
73    vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \
74    || abort_test
75ifconfig carp$IFNO2 rdomain $RD2 lladdr $lladdr2 192.168.0.1/24 \
76    vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b \
77    advskew 100 || abort_test
78
79#
80# Test behavior
81#
82
83# IFNO1 must become master
84wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'"
85test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'"
86test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'"
87
88# carpdemote must work
89ifconfig -g ${IFGPREFIX}a carpdemote
90wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'"
91test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'"
92test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'"
93
94# Done
95cleanup
96exit $FAILS
97