Merge pull request #32 from ifupdown-ng/feature/tunnel-generic
tunnel: improve validation of options
This commit is contained in:
commit
b08b52939f
2 changed files with 24 additions and 7 deletions
|
@ -2,6 +2,23 @@
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
[ -z "$IF_TUNNEL_LOCAL" ] && exit 1
|
||||||
|
[ -z "$IF_TUNNEL_REMOTE" ] && exit 1
|
||||||
|
[ -z "$IF_TUNNEL_MODE" ] && exit 1
|
||||||
|
|
||||||
|
COMMAND="tunnel"
|
||||||
|
FAMILY="-4"
|
||||||
|
|
||||||
|
case "$IF_TUNNEL_MODE" in
|
||||||
|
gretap)
|
||||||
|
COMMAND="link"
|
||||||
|
;;
|
||||||
|
vti6|ipip6|ip6*)
|
||||||
|
FAMILY="-6"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
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/
|
||||||
|
@ -19,10 +36,10 @@ PARAMS=$(set | sed -E '
|
||||||
|
|
||||||
case "$PHASE" in
|
case "$PHASE" in
|
||||||
pre-up)
|
pre-up)
|
||||||
${MOCK} eval ip tunnel add $IFACE $PARAMS
|
${MOCK} eval ip $FAMILY $COMMAND add $IFACE $PARAMS
|
||||||
;;
|
;;
|
||||||
post-down)
|
post-down)
|
||||||
${MOCK} ip tunnel del $IFACE
|
${MOCK} ip $FAMILY $COMMAND del $IFACE
|
||||||
;;
|
;;
|
||||||
depend)
|
depend)
|
||||||
echo "$IF_TUNNEL_DEV"
|
echo "$IF_TUNNEL_DEV"
|
||||||
|
|
|
@ -8,12 +8,12 @@ tests_init \
|
||||||
tunnel_teardown
|
tunnel_teardown
|
||||||
|
|
||||||
tunnel_bringup_body() {
|
tunnel_bringup_body() {
|
||||||
export MOCK=echo IFACE=tun0 PHASE=pre-up IF_TUNNEL_TYPE=gre \
|
export MOCK=echo IFACE=tun0 PHASE=pre-up IF_TUNNEL_MODE=gre \
|
||||||
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
||||||
IF_TUNNEL_TTL=255
|
IF_TUNNEL_TTL=255
|
||||||
atf_check -s exit:0 \
|
atf_check -s exit:0 \
|
||||||
-o match:"ip tunnel add tun0" \
|
-o match:"ip -4 tunnel add tun0" \
|
||||||
-o match:"type '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'" \
|
||||||
|
@ -21,10 +21,10 @@ tunnel_bringup_body() {
|
||||||
}
|
}
|
||||||
|
|
||||||
tunnel_teardown_body() {
|
tunnel_teardown_body() {
|
||||||
export MOCK=echo IFACE=tun0 PHASE=post-down IF_TUNNEL_TYPE=gre \
|
export MOCK=echo IFACE=tun0 PHASE=post-down IF_TUNNEL_MODE=gre \
|
||||||
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
||||||
IF_TUNNEL_TTL=255
|
IF_TUNNEL_TTL=255
|
||||||
atf_check -s exit:0 \
|
atf_check -s exit:0 \
|
||||||
-o match:"ip tunnel del tun0" \
|
-o match:"ip -4 tunnel del tun0" \
|
||||||
${EXECUTOR}
|
${EXECUTOR}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue