link executor: integrate physical vlan configuration
This commit is contained in:
parent
72ad50213f
commit
badcccaa5b
3 changed files with 90 additions and 12 deletions
|
@ -1,9 +1,61 @@
|
|||
#!/bin/sh
|
||||
[ -z "$VERBOSE" ] || set -x
|
||||
OPTIONS=""
|
||||
|
||||
[ -n "$VERBOSE" ] && set -x
|
||||
|
||||
IF_LINK_OPTIONS="$IF_LINK_OPTIONS"
|
||||
[ -n "$IF_MTU" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS mtu $IF_MTU"
|
||||
|
||||
is_vlan() {
|
||||
case "$IFACE" in
|
||||
*#*) return 1 ;;
|
||||
*:*) return 1 ;;
|
||||
vlan*.*) return 1 ;;
|
||||
vlan*)
|
||||
IF_VLAN_ID="${IFACE#vlan}"
|
||||
[ -n "${IF_VLAN_RAW_DEVICE:-}" ] && return 0
|
||||
return 1
|
||||
;;
|
||||
*.*)
|
||||
IF_VLAN_RAW_DEVICE="${IFACE%.*}"
|
||||
IF_VLAN_ID="${IFACE##*.}"
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
[ -z "${IF_VLAN_ID:-}" ] && return 1
|
||||
[ -z "${IF_VLAN_RAW_DEVICE:-}" ] && return 1
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$PHASE" in
|
||||
up|down)
|
||||
[ -n "$IF_MTU" ] && OPTIONS="$OPTIONS mtu $IF_MTU"
|
||||
${MOCK} ip link set $PHASE dev $IFACE $OPTIONS
|
||||
if is_vlan; then
|
||||
ADD_DEL="add"
|
||||
[ "$PHASE" = "down" ] && ADD_DEL="delete"
|
||||
|
||||
if [ -e /sys/class/net/$IFACE ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "$MOCK" ]; then
|
||||
if ! ip link show "$IF_VLAN_RAW_DEVICE" >/dev/null; then
|
||||
echo "Device $IF_VLAN_RAW_DEVICE for $IFACE does not exist"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! [ -d /proc/net/vlan ]; then
|
||||
echo "Loading 8021q kernel module for VLAN support"
|
||||
${MOCK} modprobe 8021q
|
||||
fi
|
||||
|
||||
${MOCK} ip link $ADD_DEL link "$IF_VLAN_RAW_DEVICE" name "$IFACE" type vlan id "$IF_VLAN_ID"
|
||||
else
|
||||
${MOCK} ip link set $PHASE dev $IFACE $IF_LINK_OPTIONS
|
||||
fi
|
||||
;;
|
||||
depend)
|
||||
echo "$IF_VLAN_RAW_DEVICE"
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
case "$PHASE" in
|
||||
depend)
|
||||
RAW_DEVICE="${IFACE%.*}"
|
||||
echo "$RAW_DEVICE"
|
||||
;;
|
||||
esac
|
|
@ -3,7 +3,14 @@
|
|||
. $(atf_get_srcdir)/../test_env.sh
|
||||
EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/link"
|
||||
|
||||
tests_init up down mtu
|
||||
tests_init \
|
||||
up \
|
||||
down \
|
||||
mtu \
|
||||
vlan_explicit_up \
|
||||
vlan_explicit_down \
|
||||
vlan_guessed_up \
|
||||
vlan_guessed_down
|
||||
|
||||
up_body() {
|
||||
export IFACE=lo PHASE=up MOCK=echo
|
||||
|
@ -22,3 +29,29 @@ mtu_body() {
|
|||
atf_check -s exit:0 -o match:'ip link set up dev eth0 mtu 1492' \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
||||
vlan_explicit_up_body() {
|
||||
export IFACE=servers PHASE=up MOCK=echo \
|
||||
IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123"
|
||||
atf_check -s exit:0 -o match:'ip link add link eth0 name servers type vlan id 123' \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
||||
vlan_explicit_down_body() {
|
||||
export IFACE=servers PHASE=down MOCK=echo \
|
||||
IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123"
|
||||
atf_check -s exit:0 -o match:'ip link delete link eth0 name servers type vlan id 123' \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
||||
vlan_guessed_up_body() {
|
||||
export IFACE=eth0.8 PHASE=up MOCK=echo
|
||||
atf_check -s exit:0 -o match:'ip link add link eth0 name eth0.8 type vlan id 8' \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
||||
vlan_guessed_down_body() {
|
||||
export IFACE=eth0.8 PHASE=down MOCK=echo
|
||||
atf_check -s exit:0 -o match:'ip link delete link eth0 name eth0.8 type vlan id 8' \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue