mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-13 11:01:50 +00:00
85 lines
No EOL
2.2 KiB
Bash
Executable file
85 lines
No EOL
2.2 KiB
Bash
Executable file
#!/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' \
|
|
'host:host' \
|
|
'firstport:port'
|
|
}
|
|
|
|
interface_multipath_settings() {
|
|
local mode port
|
|
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
|
|
count=$(($count+1))
|
|
port=$((firstport+count))
|
|
cat >> /tmp/etc/${interface_name}.conf <<-EOF
|
|
|
|
[${id}]
|
|
bindhost = "${ifname}"
|
|
bindport = "${port}"
|
|
remotehost = "${host}"
|
|
remoteport = "${port}"
|
|
EOF
|
|
}
|
|
|
|
start_service() {
|
|
local enable timeout mode password reorder_buffer_size interface_name host firstport loss_tolerence
|
|
validate_section "general" || {
|
|
_err "validation failed"
|
|
return 1
|
|
}
|
|
|
|
[ "${enable}" = "1" ] || return 1
|
|
|
|
if [ "$(uci -q get network.omrvpn)" != "${interface_name}" ]; then
|
|
uci -q set network.omrvpn.ifname=${interface_name}
|
|
uci -q commit
|
|
fi
|
|
|
|
cat > /tmp/etc/${interface_name}.conf <<-EOF
|
|
[general]
|
|
tuntap = "tun"
|
|
mode = "${mode}"
|
|
interface_name = "${interface_name}"
|
|
timeout = ${timeout}
|
|
reorder_buffer = yes
|
|
reorder_buffer_size = ${reorder_buffer_size}
|
|
loss_tolerence = ${loss_tolerence}
|
|
password = "${password}"
|
|
mtu = 1452
|
|
EOF
|
|
|
|
local count=0 id=0
|
|
config_load network
|
|
config_foreach interface_multipath_settings interface
|
|
|
|
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"
|
|
#procd_set_param reload_signal SIGHUP
|
|
procd_set_param respawn 0 30 5
|
|
procd_close_instance
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger mlvpn network
|
|
} |