lldpd.init 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2012 OpenWrt.org
  3. START=90
  4. SERVICE_USE_PID=1
  5. find_release_info()
  6. {
  7. [ -s /etc/openwrt_release ] && . /etc/openwrt_release
  8. [ -z "$DISTRIB_DESCRIPTION" ] && [ -s /etc/openwrt_version ] && \
  9. DISTRIB_DESCRIPTION="$(cat /etc/openwrt_version)"
  10. echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
  11. }
  12. start() {
  13. . /lib/functions/network.sh
  14. local enable_cdp
  15. local enable_fdp
  16. local enable_sonmp
  17. local enable_edp
  18. local lldp_class
  19. local lldp_location
  20. local lldp_description
  21. local readonly_mode
  22. config_load 'lldpd'
  23. config_get_bool enable_cdp 'config' 'enable_cdp' 0
  24. config_get_bool enable_fdp 'config' 'enable_fdp' 0
  25. config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
  26. config_get_bool enable_edp 'config' 'enable_edp' 0
  27. config_get lldp_class 'config' 'lldp_class'
  28. config_get lldp_location 'config' 'lldp_location'
  29. config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
  30. config_get_bool readonly_mode 'config' 'readonly_mode' 0
  31. local ifaces
  32. config_get ifaces 'config' 'interface'
  33. local iface ifnames=""
  34. for iface in $ifaces; do
  35. local ifname=""
  36. if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
  37. append ifnames "${ifname:-$iface}" ","
  38. fi
  39. done
  40. [ -n "$ifnames" ] && append args "-I $ifnames"
  41. [ $enable_cdp -gt 0 ] && append args '-c'
  42. [ $enable_fdp -gt 0 ] && append args '-f'
  43. [ $enable_sonmp -gt 0 ] && append args '-s'
  44. [ $enable_edp -gt 0 ] && append args '-e'
  45. [ $readonly_mode -gt 0 ] && append args '-r'
  46. mkdir -p /var/run/lldp
  47. chown lldp:lldp /var/run/lldp
  48. service_start /usr/sbin/lldpd $args \
  49. ${lldp_class:+ -M $lldp_class} \
  50. ${lldp_description:+ -S "$lldp_description"}
  51. [ -n "$lldp_location" ] && {
  52. sleep 1
  53. /usr/sbin/lldpctl -L "$lldp_location" > /dev/null 2>&1
  54. }
  55. }
  56. stop() {
  57. service_stop /usr/sbin/lldpd
  58. rm -f /var/run/lldpd.socket /var/run/lldpd.pid
  59. }