Skip to content

Instantly share code, notes, and snippets.

@genneko
Last active May 11, 2019 12:50
Show Gist options
  • Save genneko/73eaa796fbd2acc1cd423b714e5c7c3d to your computer and use it in GitHub Desktop.
Save genneko/73eaa796fbd2acc1cd423b714e5c7c3d to your computer and use it in GitHub Desktop.
Test: destroy renamed clone interfaces on VNET(VIMAGE) jail.
#!/bin/sh
JAILNAME=test
IFLIST="edsc epair ipsec gif gre lagg lo stf tap tun vlan vmnet vxlan"
runcmd(){
echo "#" $@ >&2
"$@"
}
create(){
local iftype=$1
runcmd jexec $JAILNAME ifconfig $iftype create
}
rename(){
local src=$1
local dst=$2
runcmd jexec $JAILNAME ifconfig $src name $dst
}
destroy(){
local iftype=$1
runcmd jexec $JAILNAME ifconfig $iftype destroy
}
echo
runcmd jail -c name=$JAILNAME vnet persist
i=0
for iftype in $IFLIST; do
#for iftype in $(ifconfig -C); do
echo
echo "Interface type [$iftype]"
echo "------------------------"
runcmd kldload "if_$iftype" 2>/dev/null
sleep 1
ifname=$(create $iftype)
if [ -z "$ifname" ]; then
echo "! --> FAILED to create an interface of the type [$iftype]."
continue
fi
echo " --> [$ifname] created"
sleep 1
newifname=$(rename $ifname "foo$i")
if [ -z "$newifname" ]; then
echo "! --> FAILED to rename [$ifname] to [$newifname]."
echo -n "! --> aborting the test on [$iftype]..."
destroy $ifname && echo "ok" || echo "FALIED"
continue
fi
echo " --> [$ifname] renamed to [$newifname]"
i=$(expr $i + 1)
sleep 1
destroy $newifname &&
echo " --> [$newifname] destroyed" ||
(
echo "! --> FAILED to destroy [$newifname]"
renifname=$(rename $newifname $ifname)
if [ "$renifname" == "$ifname" ]; then
echo "! --> [$newifname] renamed back to [$ifname]"
sleep 1
if destroy $ifname; then
echo "! --> [$ifname] destroyed"
else
echo "!!--> FAILED to destroy [$ifname]"
fi
fi
)
done
echo
runcmd jail -r $JAILNAME
--- sys/net/if_clone.c (revision 343922)
+++ sys/net/if_clone.c (working copy)
@@ -269,12 +269,8 @@
if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
CURVNET_SET_QUIET(vnet0);
LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
- if (ifc->ifc_type == SIMPLE) {
- if (ifc_simple_match(ifc, name))
- break;
- } else {
- if (ifc->ifc_match(ifc, name))
- break;
+ if (strcmp(ifc->ifc_name, ifp->if_dname) == 0) {
+ break;
}
CURVNET_RESTORE();
}
On vnet jails, some types of cloned interfaces cannot be destroyed
when they have been renamed.
I reported a similar bug #235704 about tun(4) interface.
The bug has been cleanly fixed by virtualizing if_tun cloner but I
found some other interface types also seemed to have the same issue.
According to my testings on 12-stable and 13-current, the following
interface types are affected.
12-stable (r347428) stf, tap, vmnet, vxlan
13-current (r347476) stf, vxlan (tap and vmnet seem to be fixed by recent tun/tap merge)
Patch:
After applying the patch attached to the bug #235704,
I ran the same test script again. This time all interfaces
were destroyed as expected.
See also bug #235704, comment #3 and bug #235704, comment #9.
# jail -c name=test vnet persist
Interface type [edsc]
------------------------
# jexec test ifconfig edsc create
--> [edsc0] created
# jexec test ifconfig edsc0 name foo0
--> [edsc0] renamed to [foo0]
# jexec test ifconfig foo0 destroy
--> [foo0] destroyed
Interface type [epair]
------------------------
# jexec test ifconfig epair create
--> [epair0a] created
# jexec test ifconfig epair0a name foo1
--> [epair0a] renamed to [foo1]
# jexec test ifconfig foo1 destroy
--> [foo1] destroyed
Interface type [ipsec]
------------------------
# jexec test ifconfig ipsec create
--> [ipsec0] created
# jexec test ifconfig ipsec0 name foo2
--> [ipsec0] renamed to [foo2]
# jexec test ifconfig foo2 destroy
--> [foo2] destroyed
Interface type [gif]
------------------------
# jexec test ifconfig gif create
--> [gif0] created
# jexec test ifconfig gif0 name foo3
--> [gif0] renamed to [foo3]
# jexec test ifconfig foo3 destroy
--> [foo3] destroyed
Interface type [gre]
------------------------
# jexec test ifconfig gre create
--> [gre0] created
# jexec test ifconfig gre0 name foo4
--> [gre0] renamed to [foo4]
# jexec test ifconfig foo4 destroy
--> [foo4] destroyed
Interface type [lagg]
------------------------
# jexec test ifconfig lagg create
--> [lagg0] created
# jexec test ifconfig lagg0 name foo5
--> [lagg0] renamed to [foo5]
# jexec test ifconfig foo5 destroy
--> [foo5] destroyed
Interface type [lo]
------------------------
# jexec test ifconfig lo create
--> [lo1] created
# jexec test ifconfig lo1 name foo6
--> [lo1] renamed to [foo6]
# jexec test ifconfig foo6 destroy
--> [foo6] destroyed
Interface type [stf]
------------------------
# jexec test ifconfig stf create
--> [stf0] created
# jexec test ifconfig stf0 name foo7
--> [stf0] renamed to [foo7]
# jexec test ifconfig foo7 destroy
--> [foo7] destroyed
Interface type [tap]
------------------------
# jexec test ifconfig tap create
--> [tap0] created
# jexec test ifconfig tap0 name foo8
--> [tap0] renamed to [foo8]
# jexec test ifconfig foo8 destroy
--> [foo8] destroyed
Interface type [tun]
------------------------
# jexec test ifconfig tun create
--> [tun1] created
# jexec test ifconfig tun1 name foo9
--> [tun1] renamed to [foo9]
# jexec test ifconfig foo9 destroy
--> [foo9] destroyed
Interface type [vlan]
------------------------
# jexec test ifconfig vlan create
--> [vlan0] created
# jexec test ifconfig vlan0 name foo10
--> [vlan0] renamed to [foo10]
# jexec test ifconfig foo10 destroy
--> [foo10] destroyed
Interface type [vmnet]
------------------------
# jexec test ifconfig vmnet create
--> [vmnet0] created
# jexec test ifconfig vmnet0 name foo11
--> [vmnet0] renamed to [foo11]
# jexec test ifconfig foo11 destroy
--> [foo11] destroyed
Interface type [vxlan]
------------------------
# jexec test ifconfig vxlan create
--> [vxlan0] created
# jexec test ifconfig vxlan0 name foo12
--> [vxlan0] renamed to [foo12]
# jexec test ifconfig foo12 destroy
--> [foo12] destroyed
# jail -r test
test: removed
# jail -c name=test vnet persist
Interface type [edsc]
------------------------
# jexec test ifconfig edsc create
--> [edsc0] created
# jexec test ifconfig edsc0 name foo0
--> [edsc0] renamed to [foo0]
# jexec test ifconfig foo0 destroy
--> [foo0] destroyed
Interface type [epair]
------------------------
# jexec test ifconfig epair create
--> [epair0a] created
# jexec test ifconfig epair0a name foo1
--> [epair0a] renamed to [foo1]
# jexec test ifconfig foo1 destroy
--> [foo1] destroyed
Interface type [ipsec]
------------------------
# jexec test ifconfig ipsec create
--> [ipsec0] created
# jexec test ifconfig ipsec0 name foo2
--> [ipsec0] renamed to [foo2]
# jexec test ifconfig foo2 destroy
--> [foo2] destroyed
Interface type [gif]
------------------------
# jexec test ifconfig gif create
--> [gif0] created
# jexec test ifconfig gif0 name foo3
--> [gif0] renamed to [foo3]
# jexec test ifconfig foo3 destroy
--> [foo3] destroyed
Interface type [gre]
------------------------
# jexec test ifconfig gre create
--> [gre0] created
# jexec test ifconfig gre0 name foo4
--> [gre0] renamed to [foo4]
# jexec test ifconfig foo4 destroy
--> [foo4] destroyed
Interface type [lagg]
------------------------
# jexec test ifconfig lagg create
--> [lagg0] created
# jexec test ifconfig lagg0 name foo5
--> [lagg0] renamed to [foo5]
# jexec test ifconfig foo5 destroy
--> [foo5] destroyed
Interface type [lo]
------------------------
# jexec test ifconfig lo create
--> [lo1] created
# jexec test ifconfig lo1 name foo6
--> [lo1] renamed to [foo6]
# jexec test ifconfig foo6 destroy
--> [foo6] destroyed
Interface type [stf]
------------------------
# jexec test ifconfig stf create
--> [stf0] created
# jexec test ifconfig stf0 name foo7
--> [stf0] renamed to [foo7]
# jexec test ifconfig foo7 destroy
--> [foo7] destroyed
Interface type [tap]
------------------------
# jexec test ifconfig tap create
--> [tap0] created
# jexec test ifconfig tap0 name foo8
--> [tap0] renamed to [foo8]
# jexec test ifconfig foo8 destroy
--> [foo8] destroyed
Interface type [tun]
------------------------
# jexec test ifconfig tun create
--> [tun1] created
# jexec test ifconfig tun1 name foo9
--> [tun1] renamed to [foo9]
# jexec test ifconfig foo9 destroy
--> [foo9] destroyed
Interface type [vlan]
------------------------
# jexec test ifconfig vlan create
--> [vlan0] created
# jexec test ifconfig vlan0 name foo10
--> [vlan0] renamed to [foo10]
# jexec test ifconfig foo10 destroy
--> [foo10] destroyed
Interface type [vmnet]
------------------------
# jexec test ifconfig vmnet create
--> [vmnet0] created
# jexec test ifconfig vmnet0 name foo11
--> [vmnet0] renamed to [foo11]
# jexec test ifconfig foo11 destroy
--> [foo11] destroyed
Interface type [vxlan]
------------------------
# jexec test ifconfig vxlan create
--> [vxlan0] created
# jexec test ifconfig vxlan0 name foo12
--> [vxlan0] renamed to [foo12]
# jexec test ifconfig foo12 destroy
--> [foo12] destroyed
# jail -r test
test: removed
# jail -c name=test vnet persist
Interface type [edsc]
------------------------
# jexec test ifconfig edsc create
--> [edsc0] created
# jexec test ifconfig edsc0 name foo0
--> [edsc0] renamed to [foo0]
# jexec test ifconfig foo0 destroy
--> [foo0] destroyed
Interface type [epair]
------------------------
# jexec test ifconfig epair create
--> [epair0a] created
# jexec test ifconfig epair0a name foo1
--> [epair0a] renamed to [foo1]
# jexec test ifconfig foo1 destroy
--> [foo1] destroyed
Interface type [ipsec]
------------------------
# jexec test ifconfig ipsec create
--> [ipsec0] created
# jexec test ifconfig ipsec0 name foo2
--> [ipsec0] renamed to [foo2]
# jexec test ifconfig foo2 destroy
--> [foo2] destroyed
Interface type [gif]
------------------------
# jexec test ifconfig gif create
--> [gif0] created
# jexec test ifconfig gif0 name foo3
--> [gif0] renamed to [foo3]
# jexec test ifconfig foo3 destroy
--> [foo3] destroyed
Interface type [gre]
------------------------
# jexec test ifconfig gre create
--> [gre0] created
# jexec test ifconfig gre0 name foo4
--> [gre0] renamed to [foo4]
# jexec test ifconfig foo4 destroy
--> [foo4] destroyed
Interface type [lagg]
------------------------
# jexec test ifconfig lagg create
--> [lagg0] created
# jexec test ifconfig lagg0 name foo5
--> [lagg0] renamed to [foo5]
# jexec test ifconfig foo5 destroy
--> [foo5] destroyed
Interface type [lo]
------------------------
# jexec test ifconfig lo create
--> [lo1] created
# jexec test ifconfig lo1 name foo6
--> [lo1] renamed to [foo6]
# jexec test ifconfig foo6 destroy
--> [foo6] destroyed
Interface type [stf]
------------------------
# jexec test ifconfig stf create
--> [stf0] created
# jexec test ifconfig stf0 name foo7
--> [stf0] renamed to [foo7]
# jexec test ifconfig foo7 destroy
ifconfig: SIOCIFDESTROY: Invalid argument
! --> FAILED to destroy [foo7]
# jexec test ifconfig foo7 name stf0
! --> [foo7] renamed back to [stf0]
# jexec test ifconfig stf0 destroy
! --> [stf0] destroyed
Interface type [tap]
------------------------
# jexec test ifconfig tap create
--> [tap0] created
# jexec test ifconfig tap0 name foo8
--> [tap0] renamed to [foo8]
# jexec test ifconfig foo8 destroy
ifconfig: SIOCIFDESTROY: Invalid argument
! --> FAILED to destroy [foo8]
# jexec test ifconfig foo8 name tap0
! --> [foo8] renamed back to [tap0]
# jexec test ifconfig tap0 destroy
! --> [tap0] destroyed
Interface type [tun]
------------------------
# jexec test ifconfig tun create
--> [tun1] created
# jexec test ifconfig tun1 name foo9
--> [tun1] renamed to [foo9]
# jexec test ifconfig foo9 destroy
--> [foo9] destroyed
Interface type [vlan]
------------------------
# jexec test ifconfig vlan create
--> [vlan0] created
# jexec test ifconfig vlan0 name foo10
--> [vlan0] renamed to [foo10]
# jexec test ifconfig foo10 destroy
--> [foo10] destroyed
Interface type [vmnet]
------------------------
# jexec test ifconfig vmnet create
--> [vmnet0] created
# jexec test ifconfig vmnet0 name foo11
--> [vmnet0] renamed to [foo11]
# jexec test ifconfig foo11 destroy
ifconfig: SIOCIFDESTROY: Invalid argument
! --> FAILED to destroy [foo11]
# jexec test ifconfig foo11 name vmnet0
! --> [foo11] renamed back to [vmnet0]
# jexec test ifconfig vmnet0 destroy
! --> [vmnet0] destroyed
Interface type [vxlan]
------------------------
# jexec test ifconfig vxlan create
--> [vxlan0] created
# jexec test ifconfig vxlan0 name foo12
--> [vxlan0] renamed to [foo12]
# jexec test ifconfig foo12 destroy
ifconfig: SIOCIFDESTROY: Invalid argument
! --> FAILED to destroy [foo12]
# jexec test ifconfig foo12 name vxlan0
! --> [foo12] renamed back to [vxlan0]
# jexec test ifconfig vxlan0 destroy
! --> [vxlan0] destroyed
# jail -r test
test: removed
#!/bin/sh
JAILNAME=test
IFLIST="edsc epair ipsec gif gre lagg lo stf tap tun vlan vmnet vxlan"
create(){
local iftype=$1
jexec $JAILNAME ifconfig $iftype create
}
rename(){
local src=$1
local dst=$2
jexec $JAILNAME ifconfig $src name $dst
}
destroy(){
local iftype=$1
jexec $JAILNAME ifconfig $iftype destroy
}
echo "On VNET jail '$JAILNAME':"
jail -c name=$JAILNAME vnet persist
i=0
for iftype in $IFLIST; do
#for iftype in $(ifconfig -C); do
echo
echo "Testing interface type [$iftype]..."
kldload "if_$iftype" >/dev/null 2>&1
sleep 1
ifname=$(create $iftype)
if [ -z "$ifname" ]; then
echo "! FAILED to create an interface of the type [$iftype]."
continue
fi
echo " [$ifname] created"
sleep 1
newifname=$(rename $ifname "foo$i")
if [ -z "$newifname" ]; then
echo "! FAILED to rename [$ifname] to [$newifname]."
echo -n " aborting the test on [$iftype]..."
destroy $ifname && echo "ok" || echo "FALIED"
continue
fi
echo " [$ifname] renamed to [$newifname]"
i=$(expr $i + 1)
sleep 1
destroy $newifname &&
echo " [$newifname] destroyed" ||
(
echo "! FAILED to destroy [$newifname]"
renifname=$(rename $newifname $ifname)
if [ "$renifname" == "$ifname" ]; then
echo "! [$newifname] renamed back to [$ifname]"
sleep 1
if destroy $ifname; then
echo "! [$ifname] destroyed"
else
echo "!!FAILED to destroy [$ifname]"
fi
fi
)
done
echo
echo -n "Jail "
jail -r $JAILNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment