1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2015 OpenWrt.org
7 CONFIG_LLDPD_WITH_LLDPMED
=y
10 LLDPDBIN
=/usr
/sbin
/lldpd
11 LLDPCLI
=/usr
/sbin
/lldpcli
12 LLDPSOCKET
=/var
/run
/lldpd.socket
13 LLDPD_CONF
=/tmp
/lldpd.conf
14 LLDPD_CONFS_DIR
=/tmp
/lldpd.d
16 LLDPD_RUN
=/var
/run
/lldpd
17 LLDPD_RESTART_HASH
=${LLDPD_RUN}/lldpd.restart_hash
19 .
"$IPKG_INSTROOT/lib/functions/network.sh"
23 [ -s /etc
/os-release
] && .
/etc
/os-release
24 [ -z "$PRETTY_NAME" ] && [ -s /etc
/openwrt_version
] && \
25 PRETTY_NAME
="$(cat /etc/openwrt_version)"
27 echo "${PRETTY_NAME:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
30 get_config_restart_hash
() {
36 config_get v
'config' 'lldp_class'; append _string
"$v" ","
37 config_get v
'config' 'agentxsocket'; append _string
"$v" ","
38 config_get v
'config' 'cid_interface'; append _string
"$v" ","
39 config_get v
'config' 'filter'; append _string
"$v" ","
40 config_get_bool v
'config' 'readonly_mode'; append _string
"$v" ","
41 config_get_bool v
'config' 'lldp_no_version'; append _string
"$v" ","
42 if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
43 config_get_bool v
'config' 'lldpmed_no_inventory'; append _string
"$v" ","
45 config_get_bool v
'config' 'enable_lldp' 1; append _string
"$v" ","
46 config_get_bool v
'config' 'force_lldp'; append _string
"$v" ","
47 config_get_bool v
'config' 'enable_cdp'; append _string
"$v" ","
48 config_get_bool v
'config' 'enable_edp'; append _string
"$v" ","
49 config_get_bool v
'config' 'enable_fdp'; append _string
"$v" ","
50 config_get_bool v
'config' 'enable_sonmp'; append _string
"$v" ","
52 _hash
=`echo -n "${_string}" | md5sum | awk '{ print \$1 }'`
53 export -n "$var=$_hash"
56 get_config_cid_ifaces
() {
58 config_get _ifaces
'config' 'cid_interface'
60 local _iface _ifnames
=""
61 for _iface
in $_ifaces; do
63 if network_get_device _ifname
"$_iface" ||
[ -e "/sys/class/net/$_iface" ]; then
64 append _ifnames
"${_ifname:-$_iface}" ","
68 export -n "${1}=$_ifnames"
73 local lldp_description
76 config_get lldp_description
'config' 'lldp_description' "$(find_release_info)"
79 config_get lldp_hostname
'config' 'lldp_hostname' "$(cat /proc/sys/kernel/hostname)"
82 config_get ifaces
'config' 'interface'
84 local iface ifnames
=""
85 for iface
in $ifaces; do
87 if network_get_device ifname
"$iface" ||
[ -e "/sys/class/net/$iface" ]; then
88 append ifnames
"${ifname:-$iface}" ","
93 config_get lldp_mgmt_ip
'config' 'lldp_mgmt_ip'
95 local lldp_syscapabilities
96 config_get lldp_syscapabilities
'config' 'lldp_syscapabilities'
98 if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
99 local lldpmed_fast_start
100 config_get_bool lldpmed_fast_start
'config' 'lldpmed_fast_start' 0
102 local lldpmed_fast_start_tx_interval
103 config_get lldpmed_fast_start_tx_interval
'config' 'lldpmed_fast_start_tx_interval' 0
107 config_get lldp_agenttype
'config' 'lldp_agenttype' 'nearest-bridge'
109 local lldp_portidsubtype
110 config_get lldp_portidsubtype
'config' 'lldp_portidsubtype' 'macaddress'
112 # Clear out the config file first
113 echo -n > "$LLDPD_CONF"
114 [ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF"
115 [ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF"
116 [ -n "$lldp_hostname" ] && echo "configure system hostname" "\"$lldp_hostname\"" >> "$LLDPD_CONF"
117 [ -n "$lldp_mgmt_ip" ] && echo "configure system ip management pattern" "\"$lldp_mgmt_ip\"" >> "$LLDPD_CONF"
118 [ -n "$lldp_syscapabilities" ] && echo "configure system capabilities enabled" "\"$lldp_syscapabilities\"" >> "$LLDPD_CONF"
119 if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_fast_start -gt 0 ]; then
120 if [ $lldpmed_fast_start_tx_interval -gt 0 ]; then
121 echo "configure med fast-start tx-interval" "\"$lldpmed_fast_start_tx_interval\"" >> "$LLDPD_CONF"
123 echo "configure med fast-start" "enable" >> "$LLDPD_CONF"
126 [ -n "$lldp_agenttype" ] && echo "configure lldp agent-type" "\"$lldp_agenttype\"" >> "$LLDPD_CONF"
127 [ -n "$lldp_portidsubtype" ] && echo "configure lldp portidsubtype" "\"$lldp_portidsubtype\"" >> "$LLDPD_CONF"
129 # Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR
130 [ -e $LLDPD_CONFS_DIR ] ||
ln -s /etc
/lldpd.d
$LLDPD_CONFS_DIR
143 local lldp_no_version
144 local lldpmed_no_inventory
150 config_get_bool enable_lldp
'config' 'enable_lldp' 1
151 config_get_bool force_lldp
'config' 'force_lldp' 0
152 config_get_bool enable_cdp
'config' 'enable_cdp' 0
153 config_get_bool enable_fdp
'config' 'enable_fdp' 0
154 config_get_bool enable_sonmp
'config' 'enable_sonmp' 0
155 config_get_bool enable_edp
'config' 'enable_edp' 0
156 config_get lldp_class
'config' 'lldp_class'
157 config_get lldp_location
'config' 'lldp_location'
158 config_get_bool lldp_no_version
'config' 'lldp_no_version' 0
159 if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
160 config_get_bool lldpmed_no_inventory
'config' 'lldpmed_no_inventory' 0
162 config_get_bool readonly_mode
'config' 'readonly_mode' 0
163 config_get agentxsocket
'config' 'agentxsocket'
164 config_get filter
'config' 'filter' 15
166 mkdir
-p ${LLDPD_RUN}
167 chown lldp
:lldp
${LLDPD_RUN}
169 # When lldpd starts, it also loads up what we write in this config file
173 procd_set_param
command ${LLDPDBIN}
174 procd_append_param
command -d
176 if [ $enable_lldp -gt 0 ]; then
177 if [ $force_lldp -gt 0 ]; then
178 procd_append_param
command '-l'
182 procd_append_param
command '-ll'
185 [ $enable_cdp -gt 0 ] && procd_append_param
command '-c'
186 [ $enable_fdp -gt 0 ] && procd_append_param
command '-f'
187 [ $enable_sonmp -gt 0 ] && procd_append_param
command '-s'
188 [ $enable_edp -gt 0 ] && procd_append_param
command '-e'
189 [ $readonly_mode -gt 0 ] && procd_append_param
command '-r'
190 [ $lldp_no_version -gt 0 ] && procd_append_param
command '-k'
191 [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_no_inventory -gt 0 ] && procd_append_param
command '-i'
192 [ -n "$lldp_class" ] && procd_append_param
command -M "$lldp_class"
193 [ -n "$agentxsocket" ] && procd_append_param
command -x -X "$agentxsocket"
194 [ -n "$filter" ] && procd_append_param
command -H "$filter"
196 # ChassisID interfaces
198 get_config_cid_ifaces ifnames
199 [ -n "$ifnames" ] && procd_append_param
command -C "$ifnames"
201 # Overwrite default configuration locations processed by lldpcli at start
202 procd_append_param
command -O "$LLDPD_CONF"
205 get_config_restart_hash restart_hash
206 echo -n "$restart_hash" > $LLDPD_RESTART_HASH
208 # set auto respawn behavior
209 procd_set_param respawn
214 procd_add_config_trigger
"config.change" "lldpd" /etc
/init.d
/lldpd reload
220 local running_hash
=""
223 get_config_restart_hash config_hash
224 if [ -f ${LLDPD_RESTART_HASH} ]; then running_hash
=`cat $LLDPD_RESTART_HASH`; fi
226 if [ "x$running_hash" != "x$config_hash" ]; then
228 # Some parameters can't be configured at runtime
233 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
235 unconfigure lldp custom-tlv
236 unconfigure system interface pattern
237 unconfigure system description
238 unconfigure system hostname
239 unconfigure system ip management pattern
241 if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
242 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
243 unconfigure med fast-start
247 # If something changed it should be included by the lldpcli call
249 $LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev
/null
250 # Broadcast update over the wire
251 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
259 rm -rf ${LLDPD_RUN} $LLDPSOCKET 2>/dev
/null