addrwatch.init 2.0 KB

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