[openwrt/openwrt] lldpd: set CDP version and allow forcing CDP on

LEDE Commits lede-commits at lists.infradead.org
Thu Feb 8 02:36:01 PST 2024


stintel pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/b67182008fd124706be0ec3ce67347447554ffd5

commit b67182008fd124706be0ec3ce67347447554ffd5
Author: Stephen Howell <howels at allthatwemight.be>
AuthorDate: Sun Dec 17 00:21:12 2023 +0000

    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 at allthatwemight.be>
---
 package/network/services/lldpd/Makefile         |  3 +-
 package/network/services/lldpd/files/lldpd.init | 44 ++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/package/network/services/lldpd/Makefile b/package/network/services/lldpd/Makefile
index 9e4ee0727e..a83378bcba 100644
--- a/package/network/services/lldpd/Makefile
+++ b/package/network/services/lldpd/Makefile
@@ -68,7 +68,8 @@ define Package/lldpd/install
 	$(INSTALL_BIN) ./files/lldpd.init $(1)/etc/init.d/lldpd
 	$(INSTALL_CONF) ./files/lldpd.config $(1)/etc/config/lldpd
 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
 ifneq ($(CONFIG_LLDPD_WITH_FDP),y)
 	sed -i -e '/fdp/d' $(1)/etc/init.d/lldpd $(1)/etc/config/lldpd
diff --git a/package/network/services/lldpd/files/lldpd.init b/package/network/services/lldpd/files/lldpd.init
index 98e7e97193..faf100b198 100644
--- a/package/network/services/lldpd/files/lldpd.init
+++ b/package/network/services/lldpd/files/lldpd.init
@@ -4,6 +4,7 @@
 START=90
 STOP=01
 
+CONFIG_LLDPD_WITH_CDP=y
 CONFIG_LLDPD_WITH_LLDPMED=y
 
 USE_PROCD=1
@@ -44,7 +45,12 @@ get_config_restart_hash() {
 	fi
 	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' 'enable_cdp'; append _string "$v" ","
+	if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
+		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_fdp'; append _string "$v" ","
 	config_get_bool v 'config' 'enable_sonmp'; append _string "$v" ","
@@ -135,6 +141,9 @@ start_service() {
 	local enable_lldp
 	local force_lldp
 	local enable_cdp
+	local cdp_version
+	local force_cdp
+	local force_cdpv2
 	local enable_fdp
 	local enable_sonmp
 	local enable_edp
@@ -149,7 +158,12 @@ start_service() {
 	config_load 'lldpd'
 	config_get_bool enable_lldp 'config' 'enable_lldp' 1
 	config_get_bool force_lldp 'config' 'force_lldp' 0
-	config_get_bool enable_cdp 'config' 'enable_cdp' 0
+	if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
+		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_sonmp 'config' 'enable_sonmp' 0
 	config_get_bool enable_edp 'config' 'enable_edp' 0
@@ -182,12 +196,34 @@ start_service() {
 		procd_append_param command '-ll'
 	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_sonmp -gt 0 ] && procd_append_param command '-s'
 	[ $enable_edp -gt 0 ] && procd_append_param command '-e'
 	[ $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'
 	[ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
 	[ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket"




More information about the lede-commits mailing list