2012-10-10 13:17:14 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2015-12-05 09:57:19 +00:00
|
|
|
# Copyright (C) 2008-2015 OpenWrt.org
|
2012-10-10 13:17:14 +00:00
|
|
|
|
|
|
|
START=90
|
2015-12-05 09:57:19 +00:00
|
|
|
STOP=01
|
2012-10-10 13:17:14 +00:00
|
|
|
|
2015-09-16 08:32:33 +00:00
|
|
|
USE_PROCD=1
|
2015-11-03 11:59:09 +00:00
|
|
|
LLDPCLI=/usr/sbin/lldpcli
|
|
|
|
LLDPSOCKET=/var/run/lldpd.socket
|
2015-10-21 13:11:09 +00:00
|
|
|
LLDPD_CONF=/tmp/lldpd.conf
|
|
|
|
LLDPD_CONFS_DIR=/tmp/lldpd.d
|
2012-10-10 13:17:14 +00:00
|
|
|
|
2013-01-02 14:35:43 +00:00
|
|
|
find_release_info()
|
|
|
|
{
|
2016-05-18 07:05:42 +00:00
|
|
|
[ -s /etc/os-release ] && . /etc/os-release
|
|
|
|
[ -z "$PRETTY_NAME" ] && [ -s /etc/openwrt_version ] && \
|
|
|
|
PRETTY_NAME="$(cat /etc/openwrt_version)"
|
2013-01-02 14:35:43 +00:00
|
|
|
|
2017-11-07 08:45:54 +00:00
|
|
|
echo "${PRETTY_NAME:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
|
2013-01-02 14:35:43 +00:00
|
|
|
}
|
|
|
|
|
2015-10-21 13:11:09 +00:00
|
|
|
write_lldpd_conf()
|
|
|
|
{
|
2013-01-02 14:35:43 +00:00
|
|
|
. /lib/functions/network.sh
|
|
|
|
|
2015-10-21 13:11:09 +00:00
|
|
|
local lldp_description
|
|
|
|
|
|
|
|
config_load 'lldpd'
|
|
|
|
config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
|
|
|
|
|
|
|
|
local ifaces
|
|
|
|
config_get ifaces 'config' 'interface'
|
|
|
|
|
|
|
|
local iface ifnames=""
|
|
|
|
for iface in $ifaces; do
|
|
|
|
local ifname=""
|
|
|
|
if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
|
|
|
|
append ifnames "${ifname:-$iface}" ","
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Clear out the config file first
|
|
|
|
echo -n > "$LLDPD_CONF"
|
|
|
|
[ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF"
|
|
|
|
[ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF"
|
|
|
|
|
|
|
|
# Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR
|
|
|
|
[ -e $LLDPD_CONFS_DIR ] || ln -s /etc/lldpd.d $LLDPD_CONFS_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
|
|
|
|
2012-10-10 13:17:14 +00:00
|
|
|
local enable_cdp
|
|
|
|
local enable_fdp
|
|
|
|
local enable_sonmp
|
|
|
|
local enable_edp
|
|
|
|
local lldp_class
|
|
|
|
local lldp_location
|
2015-03-12 10:06:08 +00:00
|
|
|
local readonly_mode
|
2017-01-05 12:05:57 +00:00
|
|
|
local agentxsocket
|
2012-10-10 13:17:14 +00:00
|
|
|
|
|
|
|
config_load 'lldpd'
|
|
|
|
config_get_bool enable_cdp 'config' 'enable_cdp' 0
|
|
|
|
config_get_bool enable_fdp 'config' 'enable_fdp' 0
|
|
|
|
config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
|
|
|
|
config_get_bool enable_edp 'config' 'enable_edp' 0
|
|
|
|
config_get lldp_class 'config' 'lldp_class'
|
|
|
|
config_get lldp_location 'config' 'lldp_location'
|
2015-03-12 10:06:08 +00:00
|
|
|
config_get_bool readonly_mode 'config' 'readonly_mode' 0
|
2017-01-05 12:05:57 +00:00
|
|
|
config_get agentxsocket 'config' 'agentxsocket'
|
2013-01-02 14:35:43 +00:00
|
|
|
|
2015-09-16 08:32:27 +00:00
|
|
|
mkdir -p /var/run/lldp
|
|
|
|
chown lldp:lldp /var/run/lldp
|
|
|
|
|
2015-10-21 13:11:09 +00:00
|
|
|
# When lldpd starts, it also loads up what we write in this config file
|
|
|
|
write_lldpd_conf
|
|
|
|
|
2015-09-16 08:32:33 +00:00
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command /usr/sbin/lldpd
|
|
|
|
procd_append_param command -d # don't daemonize, procd will handle that for us
|
2012-10-10 13:17:14 +00:00
|
|
|
|
2015-09-16 08:32:33 +00:00
|
|
|
[ $enable_cdp -gt 0 ] && procd_append_param command '-c'
|
|
|
|
[ $enable_fdp -gt 0 ] && procd_append_param command '-f'
|
|
|
|
[ $enable_sonmp -gt 0 ] && procd_append_param command '-s'
|
|
|
|
[ $enable_edp -gt 0 ] && procd_append_param command '-e'
|
|
|
|
[ $readonly_mode -gt 0 ] && procd_append_param command '-r'
|
2015-10-05 10:29:01 +00:00
|
|
|
[ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
|
2017-01-05 12:05:57 +00:00
|
|
|
[ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket"
|
2015-09-16 08:32:33 +00:00
|
|
|
|
|
|
|
# set auto respawn behavior
|
|
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
2012-10-10 13:17:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 11:59:09 +00:00
|
|
|
service_running() {
|
|
|
|
pgrep -x /usr/sbin/lldpd &> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
reload_service() {
|
|
|
|
running || return 1
|
2015-10-21 13:11:09 +00:00
|
|
|
$LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
|
2016-01-05 07:40:22 +00:00
|
|
|
pause
|
2015-10-21 13:11:09 +00:00
|
|
|
unconfigure lldp custom-tlv
|
|
|
|
unconfigure system interface pattern
|
|
|
|
unconfigure system description
|
|
|
|
EOF
|
|
|
|
# Rewrite lldpd.conf
|
|
|
|
# If something changed it should be included by the lldpcli call
|
|
|
|
write_lldpd_conf
|
|
|
|
$LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev/null
|
2015-11-03 11:59:09 +00:00
|
|
|
# Broadcast update over the wire
|
2016-01-05 07:40:22 +00:00
|
|
|
$LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
|
|
|
|
resume
|
|
|
|
update
|
|
|
|
EOF
|
2015-11-03 11:59:09 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-09-16 08:32:33 +00:00
|
|
|
stop_service() {
|
2015-11-03 11:59:09 +00:00
|
|
|
rm -rf /var/run/lldp $LLDPSOCKET
|
2012-10-10 13:17:14 +00:00
|
|
|
}
|