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.

98 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. # Copyright (C) 2016-2021 eGloo, Incorporated
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. START=50
  7. STOP=50
  8. USE_PROCD=1
  9. PROG=/usr/sbin/netifyd
  10. function append_params() {
  11. procd_append_param command $@
  12. }
  13. function append_ifopts() {
  14. local filter=0
  15. local filter_expr=
  16. for a in $1; do
  17. case $a in
  18. -F|--device-filter)
  19. filter=1
  20. procd_append_param command $a
  21. ;;
  22. -*)
  23. if [ $filter -gt 0 ]; then
  24. procd_append_param command "${filter_expr#\ }"
  25. filter=0; filter_expr=
  26. fi
  27. procd_append_param command $a
  28. ;;
  29. *)
  30. if [ $filter -gt 0 ]; then
  31. a=${a#\"}; a=${a%\"}; a=${a#\'}; a=${a%\'}
  32. filter_expr="$filter_expr $a"
  33. else
  34. procd_append_param command $a
  35. fi
  36. esac
  37. done
  38. if [ $filter -gt 0 ]; then
  39. procd_append_param command "${filter_expr#\ }"
  40. fi
  41. }
  42. function append_internal_if() {
  43. append_ifopts "-I $@"
  44. }
  45. function append_external_if() {
  46. append_ifopts "-E $@"
  47. }
  48. start_netifyd() {
  49. local autoconfig enabled instance options
  50. instance="$1"
  51. config_get_bool enabled "$instance" enabled 0
  52. [ "$enabled" -eq 0 ] && return 0
  53. source /usr/share/netifyd/functions.sh
  54. load_modules
  55. procd_open_instance
  56. procd_set_param file /etc/netifyd.conf
  57. procd_set_param term_timeout 20
  58. procd_set_param respawn 3600 5 0
  59. procd_set_param command $PROG -R
  60. config_list_foreach "$instance" options append_params
  61. config_get_bool autoconfig "$instance" autoconfig 1
  62. if [ "$autoconfig" -gt 0 ]; then
  63. NETIFYD_AUTODETECT=yes
  64. options="$(auto_detect_options)"
  65. [ ! -z "$options" ] && procd_append_param command $options
  66. fi
  67. config_list_foreach "$instance" internal_if append_internal_if
  68. config_list_foreach "$instance" external_if append_external_if
  69. procd_close_instance
  70. }
  71. start_service() {
  72. [ ! -d /var/run/netifyd ] && mkdir -p /var/run/netifyd
  73. config_load netifyd
  74. config_foreach start_netifyd netifyd
  75. }
  76. reload_service() {
  77. procd_send_signal netifyd
  78. }