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

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2019 Dengfeng Liu
  3. START=99
  4. USE_PROCD=1
  5. NAME=kcptun-c
  6. PROG=/usr/bin/${NAME}
  7. validate_section_kcptun()
  8. {
  9. uci_load_validate "${NAME}" kcptun "$1" "$2" \
  10. 'local_port:port' \
  11. 'remote_ip:string' \
  12. 'remote_port:port' \
  13. 'mode:string' \
  14. 'nocomp:bool' \
  15. 'sndwnd:uinteger' \
  16. 'rcvwnd:uinteger' \
  17. 'disabled:bool'
  18. }
  19. kcptun_instance()
  20. {
  21. [ "$2" = 0 ] || {
  22. echo "validation failed"
  23. return 1
  24. }
  25. [ "${disabled}" = "1" ] && return 1
  26. [ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1
  27. [ "${remote_port}" -gt 0 ] && [ "${remote_port}" -lt 65536 ] || return 1
  28. [ -n "${remote_ip}" ] || {
  29. return 1
  30. }
  31. procd_open_instance
  32. procd_set_param command "${PROG}"
  33. procd_append_param command --localaddr ":${local_port}"
  34. procd_append_param command --remoteaddr "${remote_ip}:${remote_port}"
  35. [ -n "${mode}" ] && procd_append_param command --mode "${mode}"
  36. [ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp
  37. [ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}"
  38. [ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}"
  39. procd_set_param respawn
  40. procd_close_instance
  41. }
  42. start_service()
  43. {
  44. config_load "${NAME}"
  45. config_foreach validate_section_kcptun kcptun kcptun_instance
  46. }