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.

80 lines
2.1 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_load_validate addrwatch addrwatch "$1" "$2" \
  7. 'enabled:bool:0' \
  8. 'interface:list(string):lan' \
  9. 'syslog:bool:0' \
  10. 'output:string' \
  11. 'verbose:bool:0' \
  12. 'ipv4only:bool:0' \
  13. 'ipv6only:bool:0' \
  14. 'blacklist:list(or(ip4addr,ip6addr))' \
  15. 'hashsize:range(1,65536):1'\
  16. 'ratelimit:integer:0'
  17. }
  18. start_instance() {
  19. local cfg="$1"
  20. local netdevs=""
  21. [ "$2" = 0 ] || {
  22. echo "validation of config $cfg failed"
  23. return 1
  24. }
  25. [ $enabled -eq 1 ] || return 1
  26. for iface in $interface; do
  27. local netdev
  28. network_get_physdev netdev "$iface"
  29. append netdevs "$netdev"
  30. done
  31. procd_open_instance
  32. procd_set_param command /usr/sbin/addrwatch --quiet
  33. [ -n "$output" ] && procd_append_param command "--output=$output"
  34. [ "$verbose" -eq 1 ] && procd_append_param command "--verbose"
  35. [ "$ipv4only" -eq 1 ] && procd_append_param command "--ipv4-only"
  36. [ "$ipv6only" -eq 1 ] && procd_append_param command "--ipv6-only"
  37. [ -n "$hashsize" ] && procd_append_param command "--hashsize=$hashsize"
  38. [ -n "$ratelimit" ] && procd_append_param command "--ratelimit=$ratelimit"
  39. for blitem in $blacklist; do
  40. procd_append_param command "--blacklist=$blitem"
  41. done
  42. procd_append_param command $netdevs
  43. procd_set_param netdev $netdevs
  44. procd_set_param respawn
  45. procd_open_trigger
  46. for iface in $interface; do
  47. procd_add_interface_trigger "interface.*" $iface /etc/init.d/addrwatch reload
  48. done
  49. procd_close_trigger
  50. procd_close_instance
  51. [ "$syslog" -eq 1 ] && {
  52. if [ -x /usr/sbin/addrwatch_syslog ]; then
  53. procd_open_instance
  54. procd_set_param command /usr/sbin/addrwatch_syslog
  55. procd_set_param respawn
  56. procd_close_instance
  57. else
  58. echo "Cannot find /usr/sbin/addrwatch_syslog" >&2
  59. echo "Install the addrwatch-syslog package to enable syslog output" >&2
  60. fi
  61. }
  62. }
  63. start_service() {
  64. . /lib/functions/network.sh
  65. config_load 'addrwatch'
  66. config_foreach validate_section_addrwatch 'addrwatch' start_instance
  67. }
  68. service_triggers() {
  69. procd_add_reload_trigger 'addrwatch'
  70. procd_add_validation validate_section_addrwatch
  71. }