lldpd: fix reload function for when interfaces change

The problem is that interfaces are specified at start as
command line arguments, making them unchange-able via reload.

That means, we have to move (since lldpd allows this) the
interfaces-match-pattern option to be in a config file and reload
the configuration.
It's either that, or do a 'restart'.

Since we're generating the lldpd.conf file, we'll have to
move the 'sysconfdir' of lldpd to /tmp, where the files will
get written ; this will prevent any unncessary flash writes.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
This commit is contained in:
Alexandru Ardelean 2015-10-21 16:11:09 +03:00 committed by Jo-Philipp Wich
parent ccf0648e72
commit 909f063066
2 changed files with 45 additions and 21 deletions

View file

@ -94,6 +94,7 @@ CONFIGURE_ARGS += \
--with-embedded-libevent=no \ --with-embedded-libevent=no \
--disable-hardening \ --disable-hardening \
--without-xml \ --without-xml \
--sysconfdir=/tmp \
$(if $(CONFIG_LLDPD_WITH_CDP),,--disable-cdp) \ $(if $(CONFIG_LLDPD_WITH_CDP),,--disable-cdp) \
$(if $(CONFIG_LLDPD_WITH_FDP),,--disable-fdp) \ $(if $(CONFIG_LLDPD_WITH_FDP),,--disable-fdp) \
$(if $(CONFIG_LLDPD_WITH_EDP),,--disable-edp) \ $(if $(CONFIG_LLDPD_WITH_EDP),,--disable-edp) \

View file

@ -7,6 +7,8 @@ STOP=01
USE_PROCD=1 USE_PROCD=1
LLDPCLI=/usr/sbin/lldpcli LLDPCLI=/usr/sbin/lldpcli
LLDPSOCKET=/var/run/lldpd.socket LLDPSOCKET=/var/run/lldpd.socket
LLDPD_CONF=/tmp/lldpd.conf
LLDPD_CONFS_DIR=/tmp/lldpd.d
find_release_info() find_release_info()
{ {
@ -17,27 +19,14 @@ find_release_info()
echo "${PRETTY_NAME:-Unknown Lede release} @ $(cat /proc/sys/kernel/hostname)" echo "${PRETTY_NAME:-Unknown Lede release} @ $(cat /proc/sys/kernel/hostname)"
} }
start_service() { write_lldpd_conf()
{
. /lib/functions/network.sh . /lib/functions/network.sh
local enable_cdp
local enable_fdp
local enable_sonmp
local enable_edp
local lldp_class
local lldp_location
local lldp_description local lldp_description
local readonly_mode
config_load 'lldpd' 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'
config_get lldp_description 'config' 'lldp_description' "$(find_release_info)" config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
config_get_bool readonly_mode 'config' 'readonly_mode' 0
local ifaces local ifaces
config_get ifaces 'config' 'interface' config_get ifaces 'config' 'interface'
@ -50,21 +39,50 @@ start_service() {
fi fi
done 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() {
local enable_cdp
local enable_fdp
local enable_sonmp
local enable_edp
local lldp_class
local lldp_location
local readonly_mode
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'
config_get_bool readonly_mode 'config' 'readonly_mode' 0
mkdir -p /var/run/lldp mkdir -p /var/run/lldp
chown lldp:lldp /var/run/lldp chown lldp:lldp /var/run/lldp
# When lldpd starts, it also loads up what we write in this config file
write_lldpd_conf
procd_open_instance procd_open_instance
procd_set_param command /usr/sbin/lldpd procd_set_param command /usr/sbin/lldpd
procd_append_param command -d # don't daemonize, procd will handle that for us procd_append_param command -d # don't daemonize, procd will handle that for us
[ -n "$ifnames" ] && procd_append_param command -I "$ifnames"
[ $enable_cdp -gt 0 ] && procd_append_param command '-c' [ $enable_cdp -gt 0 ] && procd_append_param command '-c'
[ $enable_fdp -gt 0 ] && procd_append_param command '-f' [ $enable_fdp -gt 0 ] && procd_append_param command '-f'
[ $enable_sonmp -gt 0 ] && procd_append_param command '-s' [ $enable_sonmp -gt 0 ] && procd_append_param command '-s'
[ $enable_edp -gt 0 ] && procd_append_param command '-e' [ $enable_edp -gt 0 ] && procd_append_param command '-e'
[ $readonly_mode -gt 0 ] && procd_append_param command '-r' [ $readonly_mode -gt 0 ] && procd_append_param command '-r'
[ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class" [ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
[ -n "$lldp_description" ] && procd_append_param command -S "$lldp_description"
# set auto respawn behavior # set auto respawn behavior
procd_set_param respawn procd_set_param respawn
@ -80,10 +98,15 @@ service_running() {
reload_service() { reload_service() {
running || return 1 running || return 1
# Custom TLVs are special and should be $LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
# reloaded from config during lldpd reload unconfigure lldp custom-tlv
$LLDPCLI -u $LLDPSOCKET unconfigure lldp custom-tlv &> /dev/null unconfigure system interface pattern
$LLDPCLI -u $LLDPSOCKET -c /etc/lldpd.conf -c /etc/lldpd.d &> /dev/null 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
# Broadcast update over the wire # Broadcast update over the wire
$LLDPCLI -u $LLDPSOCKET update &> /dev/null $LLDPCLI -u $LLDPSOCKET update &> /dev/null
return 0 return 0