1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2015 OpenWrt.org
8 LLDPDBIN
=/usr
/sbin
/lldpd
9 LLDPCLI
=/usr
/sbin
/lldpcli
10 LLDPSOCKET
=/var
/run
/lldpd.socket
11 LLDPD_CONF
=/tmp
/lldpd.conf
12 LLDPD_CONFS_DIR
=/tmp
/lldpd.d
14 LLDPD_RUN
=/var
/run
/lldpd
15 LLDPD_RESTART_HASH
=${LLDPD_RUN}/lldpd.restart_hash
17 .
"$IPKG_INSTROOT/lib/functions/network.sh"
21 [ -s /etc
/os-release
] && .
/etc
/os-release
22 [ -z "$PRETTY_NAME" ] && [ -s /etc
/openwrt_version
] && \
23 PRETTY_NAME
="$(cat /etc/openwrt_version)"
25 echo "${PRETTY_NAME:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
28 get_config_restart_hash
() {
34 config_get v
'config' 'lldp_class'; append _string
"$v" ","
35 config_get v
'config' 'agentxsocket'; append _string
"$v" ","
36 config_get v
'config' 'cid_interface'; append _string
"$v" ","
37 config_get v
'config' 'filter'; append _string
"$v" ","
38 config_get_bool v
'config' 'readonly_mode'; append _string
"$v" ","
39 config_get_bool v
'config' 'lldp_no_version'; append _string
"$v" ","
40 config_get_bool v
'config' 'enable_lldp' 1; append _string
"$v" ","
41 config_get_bool v
'config' 'enable_cdp'; append _string
"$v" ","
42 config_get_bool v
'config' 'enable_edp'; append _string
"$v" ","
43 config_get_bool v
'config' 'enable_fdp'; append _string
"$v" ","
44 config_get_bool v
'config' 'enable_sonmp'; append _string
"$v" ","
46 _hash
=`echo -n "${_string}" | md5sum | awk '{ print \$1 }'`
47 export -n "$var=$_hash"
50 get_config_cid_ifaces
() {
52 config_get _ifaces
'config' 'cid_interface'
54 local _iface _ifnames
=""
55 for _iface
in $_ifaces; do
57 if network_get_device _ifname
"$_iface" ||
[ -e "/sys/class/net/$_iface" ]; then
58 append _ifnames
"${_ifname:-$_iface}" ","
62 export -n "${1}=$_ifnames"
67 local lldp_description
70 config_get lldp_description
'config' 'lldp_description' "$(find_release_info)"
73 config_get lldp_hostname
'config' 'lldp_hostname' "$(cat /proc/sys/kernel/hostname)"
76 config_get ifaces
'config' 'interface'
78 local iface ifnames
=""
79 for iface
in $ifaces; do
81 if network_get_device ifname
"$iface" ||
[ -e "/sys/class/net/$iface" ]; then
82 append ifnames
"${ifname:-$iface}" ","
87 config_get lldp_mgmt_ip
'config' 'lldp_mgmt_ip'
89 local lldp_syscapabilities
90 config_get lldp_syscapabilities
'config' 'lldp_syscapabilities'
92 # Clear out the config file first
93 echo -n > "$LLDPD_CONF"
94 [ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF"
95 [ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF"
96 [ -n "$lldp_hostname" ] && echo "configure system hostname" "\"$lldp_hostname\"" >> "$LLDPD_CONF"
97 [ -n "$lldp_mgmt_ip" ] && echo "configure system ip management pattern" "\"$lldp_mgmt_ip\"" >> "$LLDPD_CONF"
98 [ -n "$lldp_syscapabilities" ] && echo "configure system capabilities enabled" "\"$lldp_syscapabilities\"" >> "$LLDPD_CONF"
100 # Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR
101 [ -e $LLDPD_CONFS_DIR ] ||
ln -s /etc
/lldpd.d
$LLDPD_CONFS_DIR
112 local lldp_no_version
118 config_get_bool enable_cdp
'config' 'enable_cdp' 0
119 config_get_bool enable_fdp
'config' 'enable_fdp' 0
120 config_get_bool enable_sonmp
'config' 'enable_sonmp' 0
121 config_get_bool enable_edp
'config' 'enable_edp' 0
122 config_get lldp_class
'config' 'lldp_class'
123 config_get lldp_location
'config' 'lldp_location'
124 config_get_bool lldp_no_version
'config' 'lldp_no_version' 0
125 config_get_bool readonly_mode
'config' 'readonly_mode' 0
126 config_get agentxsocket
'config' 'agentxsocket'
127 config_get filter
'config' 'filter' 15
129 mkdir
-p ${LLDPD_RUN}
130 chown lldp
:lldp
${LLDPD_RUN}
132 # When lldpd starts, it also loads up what we write in this config file
136 procd_set_param
command ${LLDPDBIN}
137 procd_append_param
command -d
139 [ $enable_cdp -gt 0 ] && procd_append_param
command '-c'
140 [ $enable_fdp -gt 0 ] && procd_append_param
command '-f'
141 [ $enable_sonmp -gt 0 ] && procd_append_param
command '-s'
142 [ $enable_edp -gt 0 ] && procd_append_param
command '-e'
143 [ $readonly_mode -gt 0 ] && procd_append_param
command '-r'
144 [ $lldp_no_version -gt 0 ] && procd_append_param
command '-k'
145 [ -n "$lldp_class" ] && procd_append_param
command -M "$lldp_class"
146 [ -n "$agentxsocket" ] && procd_append_param
command -x -X "$agentxsocket"
147 [ -n "$filter" ] && procd_append_param
command -H "$filter"
149 # ChassisID interfaces
151 get_config_cid_ifaces ifnames
152 [ -n "$ifnames" ] && procd_append_param
command -C "$ifnames"
154 # Overwrite default configuration locations processed by lldpcli at start
155 procd_append_param
command -O "$LLDPD_CONF"
158 get_config_restart_hash restart_hash
159 echo -n "$restart_hash" > $LLDPD_RESTART_HASH
161 # set auto respawn behavior
162 procd_set_param respawn
167 procd_add_config_trigger
"config.change" "lldpd" /etc
/init.d
/lldpd reload
173 local running_hash
=""
176 get_config_restart_hash config_hash
177 if [ -f ${LLDPD_RESTART_HASH} ]; then running_hash
=`cat $LLDPD_RESTART_HASH`; fi
179 if [ "x$running_hash" != "x$config_hash" ]; then
181 # Some parameters can't be configured at runtime
186 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
188 unconfigure lldp custom-tlv
189 unconfigure system interface pattern
190 unconfigure system description
191 unconfigure system hostname
192 unconfigure system ip management pattern
195 # If something changed it should be included by the lldpcli call
197 $LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev
/null
198 # Broadcast update over the wire
199 $LLDPCLI -u $LLDPSOCKET &> /dev
/null
<<-EOF
207 rm -rf ${LLDPD_RUN} $LLDPSOCKET 2>/dev
/null