2018-01-19 13:22:01 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
|
|
|
|
# Copyright (C) 2015 ovh.com
|
|
|
|
# Copyright (C) 2017 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
|
|
|
|
|
|
|
START=90
|
|
|
|
STOP=10
|
|
|
|
|
|
|
|
USE_PROCD=1
|
|
|
|
PROG_NAME=glorytun-udp
|
|
|
|
PROG=/usr/sbin/${PROG_NAME}
|
|
|
|
|
|
|
|
_log() {
|
|
|
|
logger -p daemon.info -t ${PROG_NAME} "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
_err() {
|
|
|
|
logger -p daemon.err -t ${PROG_NAME} "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_section() {
|
|
|
|
uci_validate_section glorytun glorytun "${1}" \
|
2018-04-04 11:24:24 +00:00
|
|
|
'enable:bool:0' \
|
|
|
|
'key:string' \
|
|
|
|
'host:host' \
|
|
|
|
'port:port' \
|
|
|
|
'proto:string' \
|
|
|
|
'bind:string:0.0.0.0' \
|
|
|
|
'bindport:port' \
|
|
|
|
'mtu:uinteger:1450' \
|
|
|
|
'mtuauto:bool:0' \
|
|
|
|
'chacha20:bool:0' \
|
2018-01-19 13:22:01 +00:00
|
|
|
'dev:string'
|
|
|
|
}
|
|
|
|
|
|
|
|
start_instance() {
|
2018-07-01 18:21:02 +00:00
|
|
|
local enable key host port listener proto bind bindport mtu mtuauto chacha20 dev
|
2018-01-19 13:22:01 +00:00
|
|
|
|
|
|
|
validate_section "${1}" || {
|
|
|
|
_err "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "${enable}" = "1" ] || return 1
|
2018-02-07 14:20:38 +00:00
|
|
|
[ "${proto}" = "udp" ] || return 1
|
2018-01-19 13:22:01 +00:00
|
|
|
|
|
|
|
[ -n "${key}" ] || return 1
|
2018-06-06 15:52:22 +00:00
|
|
|
[ "${key}" != "secretkey" ] || return 1
|
2018-01-19 13:22:01 +00:00
|
|
|
[ -n "${port}" ] || return 1
|
|
|
|
[ -n "${dev}" ] || return 1
|
|
|
|
|
|
|
|
echo "${key}" > /tmp/${PROG_NAME}-${1}.key
|
|
|
|
key=""
|
|
|
|
|
2018-06-06 15:52:22 +00:00
|
|
|
if [ "$(uci -q get network.omrvpn)" != "" ]; then
|
2018-07-01 18:21:02 +00:00
|
|
|
uci -q set network.omrvpn.ifname=$dev
|
|
|
|
uci -q commit
|
2018-06-06 15:52:22 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-19 13:22:01 +00:00
|
|
|
_log "starting ${PROG_NAME} ${1} instance $*"
|
|
|
|
|
|
|
|
procd_open_instance
|
|
|
|
|
|
|
|
procd_set_param command ${PROG} \
|
2018-02-07 19:00:50 +00:00
|
|
|
${bind:+bind "$bind"} \
|
2018-05-29 16:03:00 +00:00
|
|
|
${bindport:+ "$bindport"} \
|
2018-04-04 11:24:24 +00:00
|
|
|
${host:+to "$host"} \
|
|
|
|
${port:+ "$port"} \
|
|
|
|
${dev:+dev "$dev"} \
|
|
|
|
keyfile /tmp/${PROG_NAME}-${1}.key \
|
2018-05-29 16:03:00 +00:00
|
|
|
persist
|
2018-01-19 13:22:01 +00:00
|
|
|
|
2018-04-04 11:24:24 +00:00
|
|
|
[ "${chacha20}" = "1" ] && procd_append_param command chacha
|
2018-02-07 19:00:50 +00:00
|
|
|
|
2018-01-19 13:22:01 +00:00
|
|
|
procd_set_param respawn 0 30 0
|
|
|
|
procd_set_param file /tmp/${PROG_NAME}-${1}.key
|
|
|
|
|
|
|
|
procd_set_param stdout 1
|
|
|
|
procd_set_param stderr 1
|
|
|
|
|
|
|
|
procd_close_instance
|
2018-07-01 18:21:02 +00:00
|
|
|
|
|
|
|
#config_load network
|
|
|
|
#config_foreach add_glorytun_path interface
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
add_glorytun_path() {
|
|
|
|
case "$1" in
|
|
|
|
loopback|lan|if0|*tun*|ifb*) return ;;
|
|
|
|
esac
|
|
|
|
local multipath
|
|
|
|
network_get_ipaddr ipaddr "$1"
|
|
|
|
config_get multipath "$1" multipath "off"
|
|
|
|
case "$multipath" in
|
|
|
|
master|on) glorytun-udp path "$ipaddr" dev $dev up ;;
|
|
|
|
backup) glorytun-udp path "$ipaddr" dev $dev backup ;;
|
|
|
|
*) glorytun-udp path "$ipaddr" dev $dev down ;;
|
|
|
|
esac
|
2018-01-19 13:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
2018-07-01 18:21:02 +00:00
|
|
|
local dev
|
2018-01-19 13:22:01 +00:00
|
|
|
config_load glorytun
|
|
|
|
config_foreach start_instance glorytun
|
|
|
|
}
|
|
|
|
|
2018-05-30 12:33:12 +00:00
|
|
|
reload_service() {
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:22:01 +00:00
|
|
|
service_triggers() {
|
2018-09-18 09:02:42 +00:00
|
|
|
procd_add_reload_trigger glorytun-udp network
|
2018-01-19 13:22:01 +00:00
|
|
|
}
|