salt-common/sls/tayga/tayga.sh
Antsiferov Grigory 0dde1b0758 * sls/tayga
netifrc module and /etc/conf.d/net configuration update.
2016-07-18 21:15:34 +03:00

75 lines
1.7 KiB
Bash

# Copyright (c) 2016 Victory Ejevika <ki@bakka.su>
# Released under the 2-clause BSD license.
# Based on TUN/TAP module by Roy Marples <roy@marples.name>
tayga_depend()
{
before bridge interface macchanger
program tayga
}
_config_vars="$_config_vars"
_is_tayga()
{
[ -n "$(RC_SVCNAME="net.${IFACE}"; export RC_SVCNAME ; service_get_value tayga)" ]
}
tayga_pre_start()
{
local rc=
# ALL interfaces run pre_start blocks, not just those with something
# assigned, so we must check if we need to run on this interface before we
# do so.
local tayga
eval tayga=\$tayga_${IFVAR}
test "${tayga}" = 'true' || return 0
if [ ! -e /dev/net/tun ]; then
if ! modprobe tun; then
eerror "TUN/TAP support is not present in this kernel"
return 1
fi
vebegin "Waiting for /dev/net/tun"
# /dev/net/tun can take its time to appear
local timeout=10
while [ ! -e /dev/net/tun -a ${timeout} -gt 0 ]; do
sleep 1
: $(( timeout -= 1 ))
done
if [ ! -e /dev/net/tun ]; then
eerror "TUN/TAP support present but /dev/net/tun is not"
return 1
fi
veend 0
fi
ebegin "Creating nat64 interface ${IFACE}"
local t_opts=
eval t_opts=\$tayga_opts_${IFVAR}
if type tayga >/dev/null 2>&1; then
tayga --mktun ${t_opts} #add dev "${IFACE}"
rc=$?
else
eerror "TAYGA is not found, please install it, or add to your PATH"
rc=1
fi
eend $rc && _up && service_set_value tayga "${tayga}"
}
tayga_post_stop()
{
_is_tayga || return 0
ebegin "Destroying nat64 interface ${IFACE}"
if type tayga > /dev/null 2>&1; then
tayga --rmtun
else
eerror "TAYGA is not found, please install it, or add to your PATH"
rc=1
fi
eend $?
}