git: 80fc25025ffc - main - tests/net*: destroy interface from inside a jail
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 25 Jan 2022 05:09:42 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=80fc25025ffcb0d369fc0b6d4d272ad6fd3f53c3
commit 80fc25025ffcb0d369fc0b6d4d272ad6fd3f53c3
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-01-25 05:08:03 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-01-25 05:08:03 +0000
tests/net*: destroy interface from inside a jail
There is no guarentee that upon return of 'jail -r' all jail resources
will be released. The test suite used to rely on that. Recent changes
to the PCB zones made jails delay releasing their resources, which ended
with interface leak in the test suite.
Fix that by executing 'ifconfig foo0 destroy' inside the jail, instead
of doing 'jail -r' and expecting interfaces to pop up back immediately
in the parent jail.
Reviewed by: kp
Differential revision: https://reviews.freebsd.org/D33942
---
tests/sys/common/vnet.subr | 44 ++++++++++++++++++++++++++++++----------
tests/sys/netpfil/pf/set_skip.sh | 2 +-
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/tests/sys/common/vnet.subr b/tests/sys/common/vnet.subr
index 590e8dea992e..cdd3d3f69709 100644
--- a/tests/sys/common/vnet.subr
+++ b/tests/sys/common/vnet.subr
@@ -1,7 +1,16 @@
-# $FreeBSD$
-# VNAT/jail utility functions
+# VNET/jail utility functions
##
+list_interface()
+{
+ echo $1 >> created_interfaces.lst
+}
+
+unlist_interface()
+{
+ sed -i "" /^$1\$/d created_interfaces.lst
+}
+
vnet_init()
{
if [ "`sysctl -i -n kern.features.vimage`" != 1 ]; then
@@ -12,29 +21,29 @@ vnet_init()
vnet_mkepair()
{
ifname=$(ifconfig epair create)
- echo $ifname >> created_interfaces.lst
- echo ${ifname%a}b >> created_interfaces.lst
+ list_interface $ifname
+ list_interface ${ifname%a}b
echo ${ifname%a}
}
vnet_mkbridge()
{
ifname=$(ifconfig bridge create)
- echo $ifname >> created_interfaces.lst
+ list_interface $ifname
echo ${ifname}
}
vnet_mkvlan()
{
ifname=$(ifconfig vlan create)
- echo ${ifname} >> created_interfaces.lst
+ list_interface $ifname
echo ${ifname}
}
vnet_mkloopback()
{
ifname=$(ifconfig lo create)
- echo $ifname >> created_interfaces.lst
+ list_interface $ifname
echo ${ifname}
}
@@ -47,19 +56,32 @@ vnet_mkjail()
for ifname in $@
do
vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}"
+ unlist_interface $ifname
done
jail -c name=${jailname} persist vnet ${vnet_interfaces}
- echo $jailname >> created_jails.lst
+ echo $jailname $@ >> created_jails.lst
+}
+
+vnet_ifmove()
+{
+ ifname=$1
+ jailname=$2
+
+ ifconfig ${ifname} vnet ${jailname}
+ unlist_interface $ifname
+ sed -i "" "/^${jailname}/s/\$/ ${ifname}/" created_jails.lst
}
vnet_cleanup()
{
if [ -f created_jails.lst ]; then
- for jailname in `cat created_jails.lst`
- do
+ while read jailname ifnames; do
+ for ifname in ${ifnames}; do
+ jexec ${jailname} ifconfig ${ifname} destroy
+ done
jail -r ${jailname}
- done
+ done < created_jails.lst
rm created_jails.lst
fi
diff --git a/tests/sys/netpfil/pf/set_skip.sh b/tests/sys/netpfil/pf/set_skip.sh
index ce7b1900ae00..3f4cfc3fda2c 100644
--- a/tests/sys/netpfil/pf/set_skip.sh
+++ b/tests/sys/netpfil/pf/set_skip.sh
@@ -105,7 +105,7 @@ set_skip_dynamic_body()
epair=$(vnet_mkepair)
ifconfig ${epair}a 192.0.2.2/24 up
- ifconfig ${epair}b vnet alcatraz
+ vnet_ifmove ${epair}b alcatraz
jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up