You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.3 KiB

#!/bin/sh /etc/rc.common
# Copyright (C) 2019 Dengfeng Liu
START=99
USE_PROCD=1
NAME=kcptun-s
PROG=/usr/bin/${NAME}
validate_section_kcptun()
{
uci_load_validate "${NAME}" kcptun "$1" "$2" \
'local_port:port' \
'target_ip:string' \
'target_port:port' \
'mode:string' \
'nocomp:bool' \
'sndwnd:uinteger' \
'rcvwnd:uinteger' \
'disabled:bool'
}
kcptun_instance()
{
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
[ "${disabled}" = "1" ] && return 1
[ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1
[ "${target_port}" -gt 0 ] && [ "${target_port}" -lt 65536 ] || return 1
[ -n "${target_ip}" ] || {
return 1
}
procd_open_instance
procd_set_param command "${PROG}"
procd_append_param command --listen ":${local_port}"
procd_append_param command --target "${target_ip}:${target_port}"
[ -n "${mode}" ] && procd_append_param command --mode "${mode}"
[ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp
[ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}"
[ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}"
procd_set_param respawn
procd_close_instance
}
start_service()
{
config_load "${NAME}"
config_foreach validate_section_kcptun kcptun kcptun_instance
}