1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00
openmptcprouter-feeds/mlvpn/files/etc/init.d/mlvpn

85 lines
2.2 KiB
Text
Raw Normal View History

2018-06-06 15:57:59 +00:00
#!/bin/sh /etc/rc.common
START=88
USE_PROCD=1
validate_section() {
uci_validate_section mlvpn mlvpn ${1} \
'enable:bool:0' \
'timeout:uinteger:30' \
'mode:string:client' \
'password:string' \
'reorder_buffer_size:uinteger:64' \
'loss_tolerence:uinteger:30' \
'interface_name:string:mlvpn0' \
2018-06-07 14:52:27 +00:00
'host:host' \
'firstport:port'
2018-06-06 15:57:59 +00:00
}
2018-06-07 14:52:27 +00:00
interface_multipath_settings() {
local mode port
2018-06-06 15:57:59 +00:00
local config="$1"
id=$(($id+1))
config_get mode "$config" multipath ""
[ "$mode" = "" ] && {
mode="$(uci -q get openmptcprouter.$config.multipath)"
}
[ "$mode" = "off" ] || [ "$mode" = "" ] && return 1
config_get ifname "$config" ifname
[ -z "$ifname" ] && ifname=$(ifstatus "$config" | jsonfilter -q -e '@["l3_device"]')
[ -z "$ifname" ] && return 1
2018-06-06 15:57:59 +00:00
count=$(($count+1))
2018-06-07 14:52:27 +00:00
port=$((firstport+count))
2018-06-06 15:57:59 +00:00
cat >> /tmp/etc/${interface_name}.conf <<-EOF
[${id}]
bindhost = "${ifname}"
bindport = "${port}"
2018-06-07 14:52:27 +00:00
remotehost = "${host}"
2018-06-06 15:57:59 +00:00
remoteport = "${port}"
EOF
}
start_service() {
2018-06-07 14:52:27 +00:00
local enable timeout mode password reorder_buffer_size interface_name host firstport loss_tolerence
2018-06-06 15:57:59 +00:00
validate_section "general" || {
_err "validation failed"
return 1
}
[ "${enable}" = "1" ] || return 1
2019-09-18 20:47:10 +00:00
if [ "$(uci -q get network.omrvpn)" != "${interface_name}" ]; then
2018-07-01 18:02:25 +00:00
uci -q set network.omrvpn.ifname=${interface_name}
uci -q commit
2018-06-06 15:57:59 +00:00
fi
cat > /tmp/etc/${interface_name}.conf <<-EOF
[general]
tuntap = "tun"
mode = "${mode}"
interface_name = "${interface_name}"
timeout = ${timeout}
2018-07-01 18:02:25 +00:00
reorder_buffer = yes
2018-06-06 15:57:59 +00:00
reorder_buffer_size = ${reorder_buffer_size}
loss_tolerence = ${loss_tolerence}
password = "${password}"
2020-02-05 21:04:19 +00:00
mtu = 1452
2018-06-06 15:57:59 +00:00
EOF
2018-06-07 14:52:27 +00:00
2018-06-06 15:57:59 +00:00
local count=0 id=0
config_load network
2018-06-07 14:52:27 +00:00
config_foreach interface_multipath_settings interface
2018-06-06 15:57:59 +00:00
chmod 0600 "/tmp/etc/${interface_name}.conf"
procd_open_instance
procd_set_param command /usr/sbin/mlvpn --config "/tmp/etc/${interface_name}.conf" --user nobody
procd_set_param file "/tmp/etc/${interface_name}.conf"
2019-09-18 20:47:10 +00:00
#procd_set_param reload_signal SIGHUP
procd_set_param respawn 0 30 5
2018-06-06 15:57:59 +00:00
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger mlvpn network
}