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.

108 lines
2.2 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=60
  3. USE_PROCD=1
  4. NAME=nlbwmon
  5. PROG=/usr/sbin/nlbwmon
  6. NICEPRIO=19
  7. add_subnet() {
  8. local network="$1"
  9. local range ranges
  10. case "$network" in
  11. *.*|*:*)
  12. procd_append_param command '-s' "$network"
  13. ;;
  14. *)
  15. if network_get_subnets ranges "$network"; then
  16. for range in $ranges; do
  17. procd_append_param command '-s' "$range"
  18. done
  19. fi
  20. if network_get_subnets6 ranges "$network"; then
  21. for range in $ranges; do
  22. procd_append_param command '-s' "$range"
  23. done
  24. fi
  25. ;;
  26. esac
  27. }
  28. add_option() {
  29. local cfg="$1"
  30. local flag="$2"
  31. local option="$3"
  32. local default="$4"
  33. local value
  34. config_get value "$cfg" "$option" "$default"
  35. [ -n "$value" ] && procd_append_param command "$flag" "$value"
  36. }
  37. add_bool() {
  38. local cfg="$1"
  39. local flag="$2"
  40. local option="$3"
  41. local default="$4"
  42. local value
  43. config_get_bool value "$cfg" "$option" "$default"
  44. [ $value -eq 1 ] && procd_append_param command "$flag"
  45. }
  46. parse_config() {
  47. . /lib/functions/network.sh
  48. local cfg="$1"
  49. local dir
  50. config_get dir "$cfg" database_directory /var/lib/nlbwmon
  51. mkdir -p "$dir"
  52. procd_append_param command -o "$dir"
  53. add_option "$cfg" -b netlink_buffer_size 524288
  54. add_option "$cfg" -i commit_interval 24h
  55. add_option "$cfg" -r refresh_interval 30s
  56. add_option "$cfg" -p protocol_database /usr/share/nlbwmon/protocols
  57. add_option "$cfg" -G database_generations 10
  58. add_option "$cfg" -I database_interval 1
  59. add_option "$cfg" -L database_limit 10000
  60. add_bool "$cfg" -P database_prealloc 0
  61. add_bool "$cfg" -Z database_compress 1
  62. config_list_foreach "$cfg" local_network add_subnet
  63. }
  64. start_service() {
  65. procd_open_instance
  66. procd_set_param stderr 1
  67. procd_set_param command "$PROG"
  68. procd_set_param nice "$NICEPRIO"
  69. config_load nlbwmon
  70. config_foreach parse_config nlbwmon
  71. procd_close_instance
  72. }
  73. add_interface_trigger() {
  74. local interface ignore
  75. config_get interface "$1" interface
  76. config_get_bool ignore "$1" ignore 0
  77. [ -n "$interface" -a $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/nlbwmon reload
  78. }
  79. service_triggers() {
  80. procd_add_reload_trigger "dhcp" "system" "nlbwmon"
  81. config_load dhcp
  82. config_foreach add_interface_trigger dhcp
  83. }