Merge pull request #144 from BarbarossaTM/fix/tunnels

tunnel executor: Make sure mode/type is 1st parameter
This commit is contained in:
Ariadne Conill 2021-03-21 19:49:10 -08:00 committed by GitHub
commit 9faa988326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 8 deletions

1
.gitignore vendored
View file

@ -13,4 +13,5 @@ ifquery
ifup ifup
ifdown ifdown
ifctrstat ifctrstat
ifparse
*.lock *.lock

View file

@ -2,23 +2,38 @@
# Based on alpine's tunnel configuration script. # Based on alpine's tunnel configuration script.
# Copyright (c) 2017 Kaarle Ritvanen # Copyright (c) 2017 Kaarle Ritvanen
# Copyright (c) 2020 Ariadne Conill (extended for ifupdown-ng) # Copyright (c) 2020 Ariadne Conill (extended for ifupdown-ng)
# Copyright (c) 2021 Maximilian Wilhelm (make sure mode/type is 1st parameter)
[ -z "$IF_TUNNEL_LOCAL" ] && exit 1 [ -z "$IF_TUNNEL_LOCAL" ] && exit 1
[ -z "$IF_TUNNEL_REMOTE" ] && exit 1 [ -z "$IF_TUNNEL_REMOTE" ] && exit 1
[ -z "$IF_TUNNEL_MODE" ] && exit 1 [ -z "$IF_TUNNEL_MODE" ] && exit 1
COMMAND="tunnel" [ -n "$VERBOSE" ] && set -x
# Figure out address familiy
FAMILY="-4" FAMILY="-4"
case "$IF_TUNNEL_MODE" in case "$IF_TUNNEL_MODE" in
gretap)
COMMAND="link"
;;
vti6|ipip6|ip6*) vti6|ipip6|ip6*)
FAMILY="-6" FAMILY="-6"
;; ;;
esac esac
# Figure out object type - gretap tunnels have to create using ip link
# and therefor require 'type' keyword instead of 'mode'
OBJECT="tunnel"
TYPE_KW="mode"
if [ "${IF_TUNNEL_MODE}" = "gretap" ]; then
OBJECT="link"
TYPE_KW="type"
fi
# Store tunnel type/mode separaltely and unset input variable to exclude it
# from PARAMS below
TUNNEL_MODE="$IF_TUNNEL_MODE"
unset IF_TUNNEL_MODE
# Mangle residual IF_TUNNEL_* params into single string
PARAMS=$(set | sed -E ' PARAMS=$(set | sed -E '
s/^IF_TUNNEL_([A-Z0-9_]+)=(.+)/\1\n\2/ s/^IF_TUNNEL_([A-Z0-9_]+)=(.+)/\1\n\2/
ta ta
@ -35,10 +50,10 @@ PARAMS=$(set | sed -E '
case "$PHASE" in case "$PHASE" in
create) create)
${MOCK} eval ip $FAMILY $COMMAND add $IFACE $PARAMS ${MOCK} eval ip $FAMILY $OBJECT add $IFACE $TYPE_KW $TUNNEL_MODE $PARAMS
;; ;;
destroy) destroy)
${MOCK} ip $FAMILY $COMMAND del $IFACE ${MOCK} ip $FAMILY $OBJECT del $IFACE
;; ;;
depend) depend)
echo "$IF_TUNNEL_DEV" echo "$IF_TUNNEL_DEV"

View file

@ -70,6 +70,7 @@ static const struct remap_token tokens[] = {
{"hardware-irq-coalesce-tx-usecs-irq", "ethtool-coalesce-tx-usecs-irq"}, /* Debian ethtool integration */ {"hardware-irq-coalesce-tx-usecs-irq", "ethtool-coalesce-tx-usecs-irq"}, /* Debian ethtool integration */
{"hardware-irq-coalesce-tx-usecs-low", "ethtool-coalesce-tx-usecs-low"}, /* Debian ethtool integration */ {"hardware-irq-coalesce-tx-usecs-low", "ethtool-coalesce-tx-usecs-low"}, /* Debian ethtool integration */
{"hostname", "dhcp-hostname"}, /* legacy ifupdown */ {"hostname", "dhcp-hostname"}, /* legacy ifupdown */
{"key", "tunnel-key"}, /* legacy ifupdown */
{"leasetime", "dhcp-leastime"}, /* legacy ifupdown */ {"leasetime", "dhcp-leastime"}, /* legacy ifupdown */
{"link-autoneg", "ethtool-ethernet-autoneg"}, /* ifupdown2 */ {"link-autoneg", "ethtool-ethernet-autoneg"}, /* ifupdown2 */
{"link-duplex", "ethtool-link-duplex"}, /* Debian ethtool integration */ {"link-duplex", "ethtool-link-duplex"}, /* Debian ethtool integration */

View file

@ -5,7 +5,9 @@ EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/tunnel"
tests_init \ tests_init \
tunnel_bringup \ tunnel_bringup \
tunnel_teardown tunnel_teardown \
gretap_up \
gretap_down
tunnel_bringup_body() { tunnel_bringup_body() {
export MOCK=echo IFACE=tun0 PHASE=create IF_TUNNEL_MODE=gre \ export MOCK=echo IFACE=tun0 PHASE=create IF_TUNNEL_MODE=gre \
@ -13,7 +15,7 @@ tunnel_bringup_body() {
IF_TUNNEL_TTL=255 IF_TUNNEL_TTL=255
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:"ip -4 tunnel add tun0" \ -o match:"ip -4 tunnel add tun0" \
-o match:"mode 'gre'" \ -o match:"mode gre" \
-o match:"ttl '255'" \ -o match:"ttl '255'" \
-o match:"local '1.2.3.4'" \ -o match:"local '1.2.3.4'" \
-o match:"remote '5.6.7.8'" \ -o match:"remote '5.6.7.8'" \
@ -28,3 +30,23 @@ tunnel_teardown_body() {
-o match:"ip -4 tunnel del tun0" \ -o match:"ip -4 tunnel del tun0" \
${EXECUTOR} ${EXECUTOR}
} }
gretap_up_body() {
export MOCK=echo IFACE=foo PHASE=create IF_TUNNEL_MODE=gretap \
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8
atf_check -s exit:0 \
-o match:"ip -4 link add foo" \
-o match:"type gretap" \
-o match:"local '1.2.3.4'" \
-o match:"remote '5.6.7.8'" \
${EXECUTOR}
}
gretap_down_body() {
export MOCK=echo IFACE=foo PHASE=destroy IF_TUNNEL_MODE=gretap \
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8
atf_check -s exit:0 \
-o match:"ip -4 link del foo" \
${EXECUTOR}
}