lldpd: set CDP version and allow forcing CDP on

add option to specify CDPv1 or CDPv2 and separately enable or force each

Signed-off-by: Stephen Howell <howels@allthatwemight.be>
This commit is contained in:
Stephen Howell 2023-12-17 00:21:12 +00:00 committed by Stijn Tintel
parent 61dbe756d8
commit b67182008f
2 changed files with 42 additions and 5 deletions

View File

@ -68,7 +68,8 @@ define Package/lldpd/install
$(INSTALL_BIN) ./files/lldpd.init $(1)/etc/init.d/lldpd $(INSTALL_BIN) ./files/lldpd.init $(1)/etc/init.d/lldpd
$(INSTALL_CONF) ./files/lldpd.config $(1)/etc/config/lldpd $(INSTALL_CONF) ./files/lldpd.config $(1)/etc/config/lldpd
ifneq ($(CONFIG_LLDPD_WITH_CDP),y) ifneq ($(CONFIG_LLDPD_WITH_CDP),y)
sed -i -e '/cdp/d' $(1)/etc/init.d/lldpd $(1)/etc/config/lldpd sed -i -e 's/CONFIG_LLDPD_WITH_CDP=y/CONFIG_LLDPD_WITH_CDP=n/g' $(1)/etc/init.d/lldpd
sed -i -e '/cdp/d' $(1)/etc/config/lldpd
endif endif
ifneq ($(CONFIG_LLDPD_WITH_FDP),y) ifneq ($(CONFIG_LLDPD_WITH_FDP),y)
sed -i -e '/fdp/d' $(1)/etc/init.d/lldpd $(1)/etc/config/lldpd sed -i -e '/fdp/d' $(1)/etc/init.d/lldpd $(1)/etc/config/lldpd

View File

@ -4,6 +4,7 @@
START=90 START=90
STOP=01 STOP=01
CONFIG_LLDPD_WITH_CDP=y
CONFIG_LLDPD_WITH_LLDPMED=y CONFIG_LLDPD_WITH_LLDPMED=y
USE_PROCD=1 USE_PROCD=1
@ -44,7 +45,12 @@ get_config_restart_hash() {
fi fi
config_get_bool v 'config' 'enable_lldp' 1; append _string "$v" "," config_get_bool v 'config' 'enable_lldp' 1; append _string "$v" ","
config_get_bool v 'config' 'force_lldp'; append _string "$v" "," config_get_bool v 'config' 'force_lldp'; append _string "$v" ","
if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
config_get_bool v 'config' 'enable_cdp'; append _string "$v" "," config_get_bool v 'config' 'enable_cdp'; append _string "$v" ","
config_get v 'config' 'cdp_version'; append _string "$v" ","
config_get_bool v 'config' 'force_cdp'; append _string "$v" ","
config_get_bool v 'config' 'force_cdpv2'; append _string "$v" ","
fi
config_get_bool v 'config' 'enable_edp'; append _string "$v" "," config_get_bool v 'config' 'enable_edp'; append _string "$v" ","
config_get_bool v 'config' 'enable_fdp'; append _string "$v" "," config_get_bool v 'config' 'enable_fdp'; append _string "$v" ","
config_get_bool v 'config' 'enable_sonmp'; append _string "$v" "," config_get_bool v 'config' 'enable_sonmp'; append _string "$v" ","
@ -135,6 +141,9 @@ start_service() {
local enable_lldp local enable_lldp
local force_lldp local force_lldp
local enable_cdp local enable_cdp
local cdp_version
local force_cdp
local force_cdpv2
local enable_fdp local enable_fdp
local enable_sonmp local enable_sonmp
local enable_edp local enable_edp
@ -149,7 +158,12 @@ start_service() {
config_load 'lldpd' config_load 'lldpd'
config_get_bool enable_lldp 'config' 'enable_lldp' 1 config_get_bool enable_lldp 'config' 'enable_lldp' 1
config_get_bool force_lldp 'config' 'force_lldp' 0 config_get_bool force_lldp 'config' 'force_lldp' 0
if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
config_get_bool enable_cdp 'config' 'enable_cdp' 0 config_get_bool enable_cdp 'config' 'enable_cdp' 0
config_get cdp_version 'config' 'cdp_version' 'cdpv1v2'
config_get_bool force_cdp 'config' 'force_cdp' 0
config_get_bool force_cdpv2 'config' 'force_cdpv2' 0
fi
config_get_bool enable_fdp 'config' 'enable_fdp' 0 config_get_bool enable_fdp 'config' 'enable_fdp' 0
config_get_bool enable_sonmp 'config' 'enable_sonmp' 0 config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
config_get_bool enable_edp 'config' 'enable_edp' 0 config_get_bool enable_edp 'config' 'enable_edp' 0
@ -182,12 +196,34 @@ start_service() {
procd_append_param command '-ll' procd_append_param command '-ll'
fi fi
[ $enable_cdp -gt 0 ] && procd_append_param command '-c' if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ] && [ $enable_cdp -gt 0 ]; then
if [ $cdp_version == "cdpv2" ]; then
if [ $force_cdp -gt 0 ]; then
# CDPv1 disabled, CDPv2 forced
procd_append_param command '-ccccc'
else
# CDPv1 disabled, CDPv2 enabled
procd_append_param command '-cccc'
fi
elif [ $cdp_version == "cdpv1v2" ]; then
if [ $force_cdp -gt 0 ] && [ $force_cdpv2 -gt 0 ]; then
# CDPv1 enabled, CDPv2 forced
procd_append_param command '-ccc'
elif [ $force_cdp -gt 0 ]; then
# CDPv1 forced, CDPv2 enabled
procd_append_param command '-cc'
else
# CDPv1 and CDPv2 enabled
procd_append_param command '-c'
fi
fi
fi
[ $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'
[ $lldp_no_version -gt 0 ] && procd_append_param command '-k' [ $lldp_no_version -gt 0 ] && procd_append_param commanpackage/network/services/lldpd/Makefile package/network/services/lldpd/files/lldpd.initd '-k'
[ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_no_inventory -gt 0 ] && procd_append_param command '-i' [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_no_inventory -gt 0 ] && procd_append_param command '-i'
[ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class" [ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
[ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket" [ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket"