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.

73 lines
2.0 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2016 OpenWrt.org
  3. START=50
  4. USE_PROCD=1
  5. validate_section_addrwatch() {
  6. uci_validate_section addrwatch addrwatch "${1}" \
  7. 'disabled:bool:0' \
  8. 'interface:list(string):lan' \
  9. 'syslog:bool:1' \
  10. 'output:string' \
  11. 'quiet:bool:0' \
  12. 'verbose:bool:0' \
  13. 'ipv4only:bool:0' \
  14. 'ipv6only:bool:0' \
  15. 'blacklist:list(or(ip4addr,ip6addr))' \
  16. 'hashsize:range(1,65536):1024'\
  17. 'ratelimit:integer:3600'
  18. return $?
  19. }
  20. start_instance() {
  21. local cfg="$1"
  22. local disabled interface syslog output quiet verbose ipv4only ipv6only
  23. local blacklist hashsize ratelimit
  24. local netdevs=""
  25. validate_section_addrwatch "${cfg}" || {
  26. echo "validation of config $cfg failed"
  27. return 1
  28. }
  29. [ $disabled -ne 0 ] && return 1
  30. for iface in $interface; do
  31. local netdev
  32. network_get_physdev netdev "${iface}"
  33. append netdevs "${netdev}"
  34. done
  35. procd_open_instance
  36. procd_set_param command /usr/sbin/addrwatch
  37. [ "${syslog}" -eq 1 ] && procd_append_param command --syslog
  38. [ -n "${output}" ] && procd_append_param command --output "$output"
  39. [ "$quiet" -eq 1 ] && procd_append_param command --quiet
  40. [ "$verbose" -eq 1 ] && procd_append_param command --verbose
  41. [ "$ipv4only" -eq 1 ] && procd_append_param command --ipv4only
  42. [ "$ipv6only" -eq 1 ] && procd_append_param command --ipv6only
  43. [ -n "$hashsize" ] && procd_append_param command --hashsize "$hashsize"
  44. [ -n "$ratelimit" ] && procd_append_param command --ratelimit "$ratelimit"
  45. for blitem in $blacklist; do
  46. procd_append_param command "--blacklist=${blitem}"
  47. done
  48. procd_append_param command $netdevs
  49. procd_set_param netdev $netdevs
  50. procd_set_param respawn
  51. procd_open_trigger
  52. for iface in $interface; do
  53. procd_add_interface_trigger "interface.*" ${iface} /etc/init.d/addrwatch reload
  54. done
  55. procd_close_trigger
  56. procd_close_instance
  57. }
  58. start_service() {
  59. . /lib/functions/network.sh
  60. config_load 'addrwatch'
  61. config_foreach start_instance 'addrwatch'
  62. }
  63. service_triggers() {
  64. procd_add_reload_trigger 'addrwatch'
  65. }