1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2015 OpenWrt.org
8 LLDPCLI
=/usr
/sbin
/lldpcli
9 LLDPSOCKET
=/var
/run
/lldpd.socket
10 LLDPD_CONF
=/tmp
/lldpd.conf
11 LLDPD_CONFS_DIR
=/tmp
/lldpd.d
15 [ -s /etc
/os-release
] && .
/etc
/os-release
16 [ -z "$PRETTY_NAME" ] && [ -s /etc
/openwrt_version
] && \
17 PRETTY_NAME
="$(cat /etc/openwrt_version)"
19 echo "${PRETTY_NAME:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
24 .
/lib
/functions
/network.sh
26 local lldp_description
29 config_get lldp_description
'config' 'lldp_description' "$(find_release_info)"
32 config_get ifaces
'config' 'interface'
34 local iface ifnames
=""
35 for iface
in $ifaces; do
37 if network_get_device ifname
"$iface" ||
[ -e "/sys/class/net/$iface" ]; then
38 append ifnames
"${ifname:-$iface}" ","
42 # Clear out the config file first
43 echo -n > "$LLDPD_CONF"
44 [ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF"
45 [ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF"
47 # Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR
48 [ -e $LLDPD_CONFS_DIR ] ||
ln -s /etc
/lldpd.d
$LLDPD_CONFS_DIR
63 config_get_bool enable_cdp
'config' 'enable_cdp' 0
64 config_get_bool enable_fdp
'config' 'enable_fdp' 0
65 config_get_bool enable_sonmp
'config' 'enable_sonmp' 0
66 config_get_bool enable_edp
'config' 'enable_edp' 0
67 config_get lldp_class
'config' 'lldp_class'
68 config_get lldp_location
'config' 'lldp_location'
69 config_get_bool readonly_mode
'config' 'readonly_mode' 0
70 config_get agentxsocket
'config' 'agentxsocket'
72 mkdir
-p /var
/run
/lldp
73 chown lldp
:lldp
/var
/run
/lldp
75 # When lldpd starts, it also loads up what we write in this config file
79 procd_set_param
command /usr
/sbin
/lldpd
80 procd_append_param
command -d # don't daemonize, procd will handle that for us
82 [ $enable_cdp -gt 0 ] && procd_append_param
command '-c'
83 [ $enable_fdp -gt 0 ] && procd_append_param
command '-f'
84 [ $enable_sonmp -gt 0 ] && procd_append_param
command '-s'
85 [ $enable_edp -gt 0 ] && procd_append_param
command '-e'
86 [ $readonly_mode -gt 0 ] && procd_append_param
command '-r'
87 [ -n "$lldp_class" ] && procd_append_param
command -M "$lldp_class"
88 [ -n "$agentxsocket" ] && procd_append_param
command -x -X "$agentxsocket"
90 # set auto respawn behavior
91 procd_set_param respawn
96 pgrep
-x /usr
/sbin
/lldpd
&> /dev
/null
101 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
103 unconfigure lldp custom-tlv
104 unconfigure system interface pattern
105 unconfigure system description
108 # If something changed it should be included by the lldpcli call
110 $LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev
/null
111 # Broadcast update over the wire
112 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
120 rm -rf /var
/run
/lldp
$LLDPSOCKET