lldpd.init 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2015 OpenWrt.org
  3. START=90
  4. STOP=01
  5. USE_PROCD=1
  6. LLDPCLI=/usr/sbin/lldpcli
  7. LLDPSOCKET=/var/run/lldpd.socket
  8. find_release_info()
  9. {
  10. [ -s /etc/openwrt_release ] && . /etc/openwrt_release
  11. [ -z "$DISTRIB_DESCRIPTION" ] && [ -s /etc/openwrt_version ] && \
  12. DISTRIB_DESCRIPTION="$(cat /etc/openwrt_version)"
  13. echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
  14. }
  15. start_service() {
  16. . /lib/functions/network.sh
  17. local enable_cdp
  18. local enable_fdp
  19. local enable_sonmp
  20. local enable_edp
  21. local lldp_class
  22. local lldp_location
  23. local lldp_description
  24. local readonly_mode
  25. config_load 'lldpd'
  26. config_get_bool enable_cdp 'config' 'enable_cdp' 0
  27. config_get_bool enable_fdp 'config' 'enable_fdp' 0
  28. config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
  29. config_get_bool enable_edp 'config' 'enable_edp' 0
  30. config_get lldp_class 'config' 'lldp_class'
  31. config_get lldp_location 'config' 'lldp_location'
  32. config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
  33. config_get_bool readonly_mode 'config' 'readonly_mode' 0
  34. local ifaces
  35. config_get ifaces 'config' 'interface'
  36. local iface ifnames=""
  37. for iface in $ifaces; do
  38. local ifname=""
  39. if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
  40. append ifnames "${ifname:-$iface}" ","
  41. fi
  42. done
  43. mkdir -p /var/run/lldp
  44. chown lldp:lldp /var/run/lldp
  45. procd_open_instance
  46. procd_set_param command /usr/sbin/lldpd
  47. procd_append_param command -d # don't daemonize, procd will handle that for us
  48. [ -n "$ifnames" ] && procd_append_param command -I "$ifnames"
  49. [ $enable_cdp -gt 0 ] && procd_append_param command '-c'
  50. [ $enable_fdp -gt 0 ] && procd_append_param command '-f'
  51. [ $enable_sonmp -gt 0 ] && procd_append_param command '-s'
  52. [ $enable_edp -gt 0 ] && procd_append_param command '-e'
  53. [ $readonly_mode -gt 0 ] && procd_append_param command '-r'
  54. [ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
  55. [ -n "$lldp_description" ] && procd_append_param command -S "$lldp_description"
  56. # set auto respawn behavior
  57. procd_set_param respawn
  58. procd_append_param respawn 3600
  59. procd_append_param respawn 5
  60. procd_append_param respawn -1
  61. procd_close_instance
  62. }
  63. service_running() {
  64. pgrep -x /usr/sbin/lldpd &> /dev/null
  65. }
  66. reload_service() {
  67. running || return 1
  68. # Custom TLVs are special and should be
  69. # reloaded from config during lldpd reload
  70. $LLDPCLI -u $LLDPSOCKET unconfigure lldp custom-tlv &> /dev/null
  71. $LLDPCLI -u $LLDPSOCKET -c /etc/lldpd.conf -c /etc/lldpd.d &> /dev/null
  72. # Broadcast update over the wire
  73. $LLDPCLI -u $LLDPSOCKET update &> /dev/null
  74. return 0
  75. }
  76. stop_service() {
  77. rm -rf /var/run/lldp $LLDPSOCKET
  78. }