Merge pull request #37 from ifupdown-ng/feature/unify-link-and-vlan-executors
unify link and vlan executors
This commit is contained in:
commit
7da13ddf83
8 changed files with 136 additions and 16 deletions
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
|
@ -15,5 +15,8 @@ jobs:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Build and run tests
|
- name: Build
|
||||||
|
run: make
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
run: make check
|
run: make check
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -111,7 +111,7 @@ clean:
|
||||||
rm -f ${MANPAGES}
|
rm -f ${MANPAGES}
|
||||||
|
|
||||||
check: ${LIBIFUPDOWN_LIB} ${CMDS}
|
check: ${LIBIFUPDOWN_LIB} ${CMDS}
|
||||||
kyua test
|
kyua test || (kyua report --verbose && exit 1)
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -D -m755 ${MULTICALL} ${DESTDIR}/sbin/${MULTICALL}
|
install -D -m755 ${MULTICALL} ${DESTDIR}/sbin/${MULTICALL}
|
||||||
|
|
|
@ -1,9 +1,63 @@
|
||||||
#!/bin/sh
|
#!/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
|
case "$PHASE" in
|
||||||
up|down)
|
up|down)
|
||||||
[ -n "$IF_MTU" ] && OPTIONS="$OPTIONS mtu $IF_MTU"
|
if is_vlan; then
|
||||||
${MOCK} ip link set $PHASE dev $IFACE $OPTIONS
|
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)
|
||||||
|
if is_vlan; then
|
||||||
|
echo "$IF_VLAN_RAW_DEVICE"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
case "$PHASE" in
|
|
||||||
depend)
|
|
||||||
RAW_DEVICE="${IFACE%.*}"
|
|
||||||
echo "$RAW_DEVICE"
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -63,7 +63,11 @@ lif_interface_init(struct lif_interface *interface, const char *ifname)
|
||||||
|
|
||||||
interface->ifname = strdup(ifname);
|
interface->ifname = strdup(ifname);
|
||||||
|
|
||||||
lif_interface_use_executor(interface, strchr(ifname, '.') == NULL ? "link" : "vlan");
|
lif_interface_use_executor(interface, "link");
|
||||||
|
|
||||||
|
/* keep the 'vlan' executor as a config hint for backwards compatibility */
|
||||||
|
if (strchr(ifname, '.') != NULL)
|
||||||
|
lif_interface_use_executor(interface, "vlan");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
4
tests/fixtures/vlan-named.interfaces
vendored
Normal file
4
tests/fixtures/vlan-named.interfaces
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
iface servers
|
||||||
|
vlan-raw-device eth0
|
||||||
|
vlan-id 8
|
||||||
|
address 2001:db8:1000:2::2/64
|
|
@ -30,7 +30,9 @@ tests_init \
|
||||||
tunnel_legacy_rewrite \
|
tunnel_legacy_rewrite \
|
||||||
tunnel_ifupdown2_dependency \
|
tunnel_ifupdown2_dependency \
|
||||||
tunnel_ifupdown2_rewrite \
|
tunnel_ifupdown2_rewrite \
|
||||||
gre_dependency
|
gre_dependency \
|
||||||
|
vlan_explicit_learned_dependency \
|
||||||
|
vlan_guessed_learned_dependency
|
||||||
|
|
||||||
noargs_body() {
|
noargs_body() {
|
||||||
atf_check -s exit:1 -e ignore ifquery -S/dev/null
|
atf_check -s exit:1 -e ignore ifquery -S/dev/null
|
||||||
|
@ -192,3 +194,15 @@ gre_dependency_body() {
|
||||||
atf_check -s exit:0 -o match:"requires eth0" \
|
atf_check -s exit:0 -o match:"requires eth0" \
|
||||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/gre.interfaces tun0
|
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/gre.interfaces tun0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vlan_explicit_learned_dependency_body() {
|
||||||
|
atf_check -s exit:0 -o match:"requires eth0" \
|
||||||
|
-o match:"use vlan" \
|
||||||
|
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vlan-named.interfaces servers
|
||||||
|
}
|
||||||
|
|
||||||
|
vlan_guessed_learned_dependency_body() {
|
||||||
|
atf_check -s exit:0 -o match:"requires eth0" \
|
||||||
|
-o match:"use vlan" \
|
||||||
|
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vlan.interfaces eth0.8
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,16 @@
|
||||||
. $(atf_get_srcdir)/../test_env.sh
|
. $(atf_get_srcdir)/../test_env.sh
|
||||||
EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/link"
|
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 \
|
||||||
|
vlan_explicit_depend \
|
||||||
|
vlan_guessed_depend
|
||||||
|
|
||||||
up_body() {
|
up_body() {
|
||||||
export IFACE=lo PHASE=up MOCK=echo
|
export IFACE=lo PHASE=up MOCK=echo
|
||||||
|
@ -22,3 +31,42 @@ mtu_body() {
|
||||||
atf_check -s exit:0 -o match:'ip link set up dev eth0 mtu 1492' \
|
atf_check -s exit:0 -o match:'ip link set up dev eth0 mtu 1492' \
|
||||||
${EXECUTOR}
|
${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}
|
||||||
|
}
|
||||||
|
|
||||||
|
vlan_explicit_depend_body() {
|
||||||
|
export IFACE=servers PHASE=up MOCK=echo \
|
||||||
|
IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123"
|
||||||
|
atf_check -s exit:0 -o match:'eth0' \
|
||||||
|
${EXECUTOR}
|
||||||
|
}
|
||||||
|
|
||||||
|
vlan_guessed_depend_body() {
|
||||||
|
export IFACE=eth0.8 PHASE=depend
|
||||||
|
atf_check -s exit:0 -o match:'eth0' \
|
||||||
|
${EXECUTOR}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue