pf tests: properly destroy renamed interfaces

The pfsync:pbr tests leaves  lot of interfaces when they finish, making
other tests slower due to long time of loading scapy from pft_ping.py
when more interfaces are present. When both sides of epair are assigned
to jails, they are both removed from created_interfaces.lst and thus
won't be removed during cleanup from this file. An interface assigned to
jail is stored in created_jails.lst but if it is renamed, it won't be
cleaned up either. Furthermore this test uses identical names for
multiple interfaces across multiple jails which after destroying those
jails adds to overall confusion.

To address this issue a new function is provided for renaming interfaces
in jails and storing their new names in created_jails.lst for deletion
during cleanup.

MFC after:	1 week
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38024
This commit is contained in:
Kajetan Staszkiewicz 2023-01-16 07:19:41 +01:00 committed by Kristof Provost
parent 0f80d5ebc8
commit ddcdb534b7
2 changed files with 31 additions and 56 deletions

View File

@ -73,6 +73,16 @@ vnet_ifmove()
sed -i "" "/^${jailname}/s/\$/ ${ifname}/" created_jails.lst
}
vnet_ifrename_jail()
{
jailname=$1
ifname=$2
ifnewname=$3
jexec ${jailname} ifconfig $ifname name $ifnewname
sed -i "" "/^${jailname}/s/${ifname}/${ifnewname}/" created_jails.lst
}
vnet_cleanup()
{
if [ -f created_jails.lst ]; then

View File

@ -417,12 +417,11 @@ pbr_common_body()
alias 198.18.1.10/32 vhid 11 pass 3WjvVVw7 advskew 50
jexec gw_route_to_master sysctl net.inet.ip.forwarding=1
jexec gw_route_to_master sysctl net.inet.carp.preempt=1
jexec gw_route_to_master ifconfig ${epair_sync_gw_route_to}a name if_pfsync
sed -i '' -e 's/'${epair_sync_gw_route_to}'a/if_pfsync/g' created_interfaces.lst
jexec gw_route_to_master ifconfig ${epair_gw_route_to_master_bridge0}a name if_br0
sed -i '' -e 's/'${epair_gw_route_to_master_bridge0}'a/if_br0/g' created_interfaces.lst
jexec gw_route_to_master ifconfig ${epair_gw_route_to_master_bridge1}a name if_br1
sed -i '' -e 's/'${epair_gw_route_to_master_bridge1}'a/if_br1/g' created_interfaces.lst
vnet_ifrename_jail gw_route_to_master ${epair_sync_gw_route_to}a if_pfsync
vnet_ifrename_jail gw_route_to_master ${epair_gw_route_to_master_bridge0}a if_br0
vnet_ifrename_jail gw_route_to_master ${epair_gw_route_to_master_bridge1}a if_br1
jexec gw_route_to_master ifconfig pfsync0 \
syncpeer 198.19.10.2 \
syncdev if_pfsync \
@ -451,12 +450,11 @@ pbr_common_body()
alias 198.18.1.10/32 vhid 11 pass 3WjvVVw7 advskew 100
jexec gw_route_to_backup sysctl net.inet.ip.forwarding=1
jexec gw_route_to_backup sysctl net.inet.carp.preempt=1
jexec gw_route_to_backup ifconfig ${epair_sync_gw_route_to}b name if_pfsync
sed -i '' -e 's/'${epair_sync_gw_route_to}'b/if_pfsync/g' created_interfaces.lst
jexec gw_route_to_backup ifconfig ${epair_gw_route_to_backup_bridge0}a name if_br0
sed -i '' -e 's/'${epair_gw_route_to_backup_bridge0}'a/if_br0/g' created_interfaces.lst
jexec gw_route_to_backup ifconfig ${epair_gw_route_to_backup_bridge1}a name if_br1
sed -i '' -e 's/'${epair_gw_route_to_backup_bridge1}'a/if_br1/g' created_interfaces.lst
vnet_ifrename_jail gw_route_to_backup ${epair_sync_gw_route_to}b if_pfsync
vnet_ifrename_jail gw_route_to_backup ${epair_gw_route_to_backup_bridge0}a if_br0
vnet_ifrename_jail gw_route_to_backup ${epair_gw_route_to_backup_bridge1}a if_br1
jexec gw_route_to_backup ifconfig pfsync0 \
syncpeer 198.19.10.1 \
syncdev if_pfsync \
@ -484,12 +482,11 @@ pbr_common_body()
alias 198.18.2.20/32 vhid 22 pass 3WjvVVw7 advskew 50
jexec gw_reply_to_master sysctl net.inet.ip.forwarding=1
jexec gw_reply_to_master sysctl net.inet.carp.preempt=1
jexec gw_reply_to_master ifconfig ${epair_sync_gw_reply_to}a name if_pfsync
sed -i '' -e 's/'${epair_sync_gw_reply_to}'a/if_pfsync/g' created_interfaces.lst
jexec gw_reply_to_master ifconfig ${epair_gw_reply_to_master_bridge1}a name if_br1
sed -i '' -e 's/'${epair_gw_reply_to_master_bridge1}'a/if_br1/g' created_interfaces.lst
jexec gw_reply_to_master ifconfig ${epair_gw_reply_to_master_bridge2}a name if_br2
sed -i '' -e 's/'${epair_gw_reply_to_master_bridge2}'a/if_br2/g' created_interfaces.lst
vnet_ifrename_jail gw_reply_to_master ${epair_sync_gw_reply_to}a if_pfsync
vnet_ifrename_jail gw_reply_to_master ${epair_gw_reply_to_master_bridge1}a if_br1
vnet_ifrename_jail gw_reply_to_master ${epair_gw_reply_to_master_bridge2}a if_br2
jexec gw_reply_to_master ifconfig pfsync0 \
syncpeer 198.19.20.2 \
syncdev if_pfsync \
@ -517,12 +514,11 @@ pbr_common_body()
alias 198.18.2.20/32 vhid 22 pass 3WjvVVw7 advskew 100
jexec gw_reply_to_backup sysctl net.inet.ip.forwarding=1
jexec gw_reply_to_backup sysctl net.inet.carp.preempt=1
jexec gw_reply_to_backup ifconfig ${epair_sync_gw_reply_to}b name if_pfsync
sed -i '' -e 's/'${epair_sync_gw_reply_to}'b/if_pfsync/g' created_interfaces.lst
jexec gw_reply_to_backup ifconfig ${epair_gw_reply_to_backup_bridge1}a name if_br1
sed -i '' -e 's/'${epair_gw_reply_to_backup_bridge1}'a/if_br1/g' created_interfaces.lst
jexec gw_reply_to_backup ifconfig ${epair_gw_reply_to_backup_bridge2}a name if_br2
sed -i '' -e 's/'${epair_gw_reply_to_backup_bridge2}'a/if_br2/g' created_interfaces.lst
vnet_ifrename_jail gw_reply_to_backup ${epair_sync_gw_reply_to}b if_pfsync
vnet_ifrename_jail gw_reply_to_backup ${epair_gw_reply_to_backup_bridge1}a if_br1
vnet_ifrename_jail gw_reply_to_backup ${epair_gw_reply_to_backup_bridge2}a if_br2
jexec gw_reply_to_backup ifconfig pfsync0 \
syncpeer 198.19.20.1 \
syncdev if_pfsync \
@ -584,43 +580,12 @@ pbr_common_body()
sleep 1
done
# As cleanup is long and may lead to a timeout,
# it's run directly into the body part.
# (as cleanup timeout is not settable)
jail -r \
client \
gw_route_to_master \
gw_route_to_backup \
gw_reply_to_master \
gw_reply_to_backup \
server
for ifname in $(grep -E -e 'if_' -e 'epair.*a' -e 'bridge' created_interfaces.lst)
do
ifconfig $ifname >/dev/null 2>&1 && ifconfig $ifname destroy
done
atf_check -s exit:0 -e ignore -o ignore grep ', 0.0% packet loss' ping.stdout
}
pbr_common_cleanup()
{
for jailname in client gw_route_to_master gw_route_to_backup gw_reply_to_master gw_reply_to_backup server
do
if $(jls | grep -q $jailname); then
jail -r $jailname
else
echo "$jailname already cleaned"
fi
done
for ifname in $(grep -E -e 'if_' -e 'epair.*a' -e 'bridge' created_interfaces.lst)
do
ifconfig $ifname >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
ifconfig $ifname destroy
else
echo "$ifname already destroyed"
fi
done
pft_cleanup
}
atf_init_test_cases()