wprobe.init 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh /etc/rc.common
  2. START=90
  3. EXPORTER=/usr/sbin/wprobe-ipfix
  4. UTIL=/sbin/wprobe-util
  5. wprobe_ssd() {
  6. local cmd="$1"; shift
  7. local type="$1"; shift
  8. local app="$1"; shift
  9. start-stop-daemon "$cmd" -p "/var/run/wprobe-$type.pid" -b ${app:+-x "$app"} -m -- "$@"
  10. }
  11. stop_wprobe() {
  12. local type="$1"
  13. [ -f "/var/run/wprobe-$type.pid" ] && wprobe_ssd -K "$type"
  14. rm -f "/var/run/wprobe-$type.pid"
  15. }
  16. config_wprobe() {
  17. config_get ifname "$cfg" ifname
  18. config_get interval "$cfg" interval
  19. [ -n "$interval" ] || interval=100
  20. $UTIL "$ifname" -i "$interval" 2>/dev/null >/dev/null
  21. }
  22. start_proxy() {
  23. config_get port "$cfg" port
  24. wprobe_ssd -S proxy "$UTIL" -P -p "${port:-17990}"
  25. }
  26. start_ipfix() {
  27. local cfg="$1"
  28. config_get ifname "$cfg" interface
  29. config_get host "$cfg" host
  30. config_get port "$cfg" port
  31. config_get proto "$cfg" proto
  32. case "$proto" in
  33. sctp) proto="-s";;
  34. tcp) proto="-t";;
  35. udp) proto="-u";;
  36. *) proto="-t";;
  37. esac
  38. [ -z "$ifname" -o -z "$host" ] && {
  39. echo "wprobe-export: missing host or interface name in config $cfg"
  40. return
  41. }
  42. config_wprobe "$cfg"
  43. wprobe_ssd -S "export-$cfg" "$EXPORTER" "$proto" -i "$ifname" -c "$host" -p "${port:-4739}"
  44. }
  45. start_export() {
  46. local cfg="$1"
  47. config_get export_type "$cfg" type
  48. case "$export_type" in
  49. ipfix) [ -x "$EXPORTER" ] && start_ipfix "$cfg";;
  50. wprobe) start_proxy "$cfg";;
  51. esac
  52. }
  53. stop() {
  54. for f in /var/run/wprobe-*.pid; do
  55. CFG="${f%%.pid}"
  56. CFG="${CFG##/var/run/wprobe-}"
  57. stop_wprobe "$CFG"
  58. done
  59. }
  60. start() {
  61. config_load wprobe
  62. config_foreach config_wprobe interface
  63. config_foreach start_export export
  64. }