Merge pull request #30 from ifupdown-ng/feature/tunnel-generic
generic tunnel executor
This commit is contained in:
commit
59ba50ba4e
9 changed files with 146 additions and 3 deletions
3
Makefile
3
Makefile
|
@ -81,7 +81,8 @@ EXECUTOR_SCRIPTS_CORE ?= \
|
|||
|
||||
EXECUTOR_SCRIPTS_OPT ?= \
|
||||
bridge \
|
||||
vrf
|
||||
vrf \
|
||||
tunnel
|
||||
|
||||
EXECUTOR_SCRIPTS ?= ${EXECUTOR_SCRIPTS_CORE} ${EXECUTOR_SCRIPTS_OPT}
|
||||
|
||||
|
|
30
executor-scripts/linux/tunnel
Executable file
30
executor-scripts/linux/tunnel
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Based on alpine's tunnel configuration script.
|
||||
# Copyright (c) 2017 Kaarle Ritvanen
|
||||
|
||||
PARAMS=$(set | sed -E '
|
||||
s/^IF_TUNNEL_([A-Z0-9_]+)=(.+)/\1\n\2/
|
||||
ta
|
||||
d
|
||||
:a
|
||||
h
|
||||
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
|
||||
P
|
||||
g
|
||||
s/.*\n//
|
||||
')
|
||||
|
||||
[ "$PARAMS" ] || exit 0
|
||||
|
||||
case "$PHASE" in
|
||||
pre-up)
|
||||
${MOCK} eval ip tunnel add $IFACE $PARAMS
|
||||
;;
|
||||
post-down)
|
||||
${MOCK} ip tunnel del $IFACE
|
||||
;;
|
||||
depend)
|
||||
echo "$IF_TUNNEL_DEV"
|
||||
;;
|
||||
esac
|
|
@ -24,9 +24,16 @@ struct remap_token {
|
|||
const char *alternative;
|
||||
};
|
||||
|
||||
/* this list must be in alphabetical order for bsearch */
|
||||
static const struct remap_token tokens[] = {
|
||||
{"endpoint", "tunnel-remote"}, /* legacy ifupdown */
|
||||
{"local", "tunnel-local"}, /* legacy ifupdown */
|
||||
{"mode", "tunnel-mode"}, /* legacy ifupdown */
|
||||
{"provider", "ppp-provider"}, /* legacy ifupdown, ifupdown2 */
|
||||
{"vrf", "vrf-member"},
|
||||
{"ttl", "tunnel-ttl"}, /* legacy ifupdown */
|
||||
{"tunnel-endpoint", "tunnel-remote"}, /* ifupdown2 */
|
||||
{"tunnel-physdev", "tunnel-dev"}, /* ifupdown2 */
|
||||
{"vrf", "vrf-member"}, /* ifupdown2 */
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
12
tests/fixtures/tunnel-ifupdown2.interfaces
vendored
Normal file
12
tests/fixtures/tunnel-ifupdown2.interfaces
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
auto tun0
|
||||
iface tun0
|
||||
tunnel-local 203.0.113.2
|
||||
tunnel-endpoint 203.0.113.1
|
||||
tunnel-mode gre
|
||||
tunnel-physdev eth0
|
||||
tunnel-ttl 255
|
||||
address 203.0.113.10/30
|
||||
gateway 203.0.113.9
|
||||
|
||||
iface eth0
|
||||
address 203.0.113.2/30
|
12
tests/fixtures/tunnel-legacy.interfaces
vendored
Normal file
12
tests/fixtures/tunnel-legacy.interfaces
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
auto tun0
|
||||
iface tun0
|
||||
local 203.0.113.2
|
||||
endpoint 203.0.113.1
|
||||
mode gre
|
||||
tunnel-dev eth0
|
||||
ttl 255
|
||||
address 203.0.113.10/30
|
||||
gateway 203.0.113.9
|
||||
|
||||
iface eth0
|
||||
address 203.0.113.2/30
|
12
tests/fixtures/tunnel.interfaces
vendored
Normal file
12
tests/fixtures/tunnel.interfaces
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
auto tun0
|
||||
iface tun0
|
||||
tunnel-local 203.0.113.2
|
||||
tunnel-remote 203.0.113.1
|
||||
tunnel-mode gre
|
||||
tunnel-dev eth0
|
||||
tunnel-ttl 255
|
||||
address 203.0.113.10/30
|
||||
gateway 203.0.113.9
|
||||
|
||||
iface eth0
|
||||
address 203.0.113.2/30
|
|
@ -23,7 +23,12 @@ tests_init \
|
|||
vrf_ifupdown2_rewrite \
|
||||
vrf_ifupdown2_dependency \
|
||||
ppp_dependency \
|
||||
ppp_legacy_rewrite
|
||||
ppp_legacy_rewrite \
|
||||
tunnel_dependency \
|
||||
tunnel_legacy_dependency \
|
||||
tunnel_legacy_rewrite \
|
||||
tunnel_ifupdown2_dependency \
|
||||
tunnel_ifupdown2_rewrite
|
||||
|
||||
noargs_body() {
|
||||
atf_check -s exit:1 -e ignore ifquery -S/dev/null
|
||||
|
@ -142,3 +147,36 @@ ppp_legacy_rewrite_body() {
|
|||
atf_check -s exit:0 -o match:"ppp-provider someisp" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/ppp-legacy.interfaces ppp0
|
||||
}
|
||||
|
||||
tunnel_dependency_body() {
|
||||
atf_check -s exit:0 -o match:"requires eth0" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/tunnel.interfaces tun0
|
||||
}
|
||||
|
||||
tunnel_legacy_dependency_body() {
|
||||
atf_check -s exit:0 -o match:"requires eth0" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/tunnel-legacy.interfaces tun0
|
||||
}
|
||||
|
||||
tunnel_ifupdown2_dependency_body() {
|
||||
atf_check -s exit:0 -o match:"requires eth0" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/tunnel-ifupdown2.interfaces tun0
|
||||
}
|
||||
|
||||
tunnel_legacy_rewrite_body() {
|
||||
atf_check -s exit:0 \
|
||||
-o match:"tunnel-local 203.0.113.2" \
|
||||
-o match:"tunnel-remote 203.0.113.1" \
|
||||
-o match:"tunnel-mode gre" \
|
||||
-o match:"tunnel-ttl 255" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/tunnel-legacy.interfaces tun0
|
||||
}
|
||||
|
||||
tunnel_ifupdown2_rewrite_body() {
|
||||
atf_check -s exit:0 \
|
||||
-o match:"tunnel-local 203.0.113.2" \
|
||||
-o match:"tunnel-remote 203.0.113.1" \
|
||||
-o match:"tunnel-mode gre" \
|
||||
-o match:"tunnel-ttl 255" \
|
||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/tunnel-ifupdown2.interfaces tun0
|
||||
}
|
||||
|
|
|
@ -8,3 +8,4 @@ atf_test_program{name='dhcp_test'}
|
|||
atf_test_program{name='static_test'}
|
||||
atf_test_program{name='vrf_test'}
|
||||
atf_test_program{name='ppp_test'}
|
||||
atf_test_program{name='tunnel_test'}
|
||||
|
|
30
tests/linux/tunnel_test
Executable file
30
tests/linux/tunnel_test
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env atf-sh
|
||||
|
||||
. $(atf_get_srcdir)/../test_env.sh
|
||||
EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/tunnel"
|
||||
|
||||
tests_init \
|
||||
tunnel_bringup \
|
||||
tunnel_teardown
|
||||
|
||||
tunnel_bringup_body() {
|
||||
export MOCK=echo IFACE=tun0 PHASE=pre-up IF_TUNNEL_TYPE=gre \
|
||||
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
||||
IF_TUNNEL_TTL=255
|
||||
atf_check -s exit:0 \
|
||||
-o match:"ip tunnel add tun0" \
|
||||
-o match:"type 'gre'" \
|
||||
-o match:"ttl '255'" \
|
||||
-o match:"local '1.2.3.4'" \
|
||||
-o match:"remote '5.6.7.8'" \
|
||||
${EXECUTOR}
|
||||
}
|
||||
|
||||
tunnel_teardown_body() {
|
||||
export MOCK=echo IFACE=tun0 PHASE=post-down IF_TUNNEL_TYPE=gre \
|
||||
IF_TUNNEL_LOCAL=1.2.3.4 IF_TUNNEL_REMOTE=5.6.7.8 \
|
||||
IF_TUNNEL_TTL=255
|
||||
atf_check -s exit:0 \
|
||||
-o match:"ip tunnel del tun0" \
|
||||
${EXECUTOR}
|
||||
}
|
Loading…
Reference in a new issue