[openwrt/openwrt] lldpd: refactor out ifaces derivation; reuse function

LEDE Commits lede-commits at lists.infradead.org
Tue Sep 17 03:36:40 PDT 2024


robimarko pushed a commit to openwrt/openwrt.git, branch openwrt-23.05:
https://git.openwrt.org/b88694869247cb1eaa9aca11a3d4e0f5f4f5ee6b

commit b88694869247cb1eaa9aca11a3d4e0f5f4f5ee6b
Author: Paul Donald <newtwen at gmail.com>
AuthorDate: Thu Feb 8 22:05:11 2024 +0100

    lldpd: refactor out ifaces derivation; reuse function
    
    from commit 909f0630663d7ae1471c76154516e3299992a150
    
    Now pass two params to get_config_cid_ifaces() for:
    
    cid_interface
    interface
    
    Each of which is a CSV of interfaces.
    
    Tested on 22.03.5
    
    Signed-off-by: Paul Donald <newtwen at gmail.com>
    (cherry picked from commit 228d4e7f1b759c11897043dc73ef3c576bc13f7f)
    Link: https://github.com/openwrt/openwrt/pull/15299
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 package/network/services/lldpd/files/lldpd.init | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/package/network/services/lldpd/files/lldpd.init b/package/network/services/lldpd/files/lldpd.init
index 4841027432..e13128e2d6 100644
--- a/package/network/services/lldpd/files/lldpd.init
+++ b/package/network/services/lldpd/files/lldpd.init
@@ -76,7 +76,7 @@ get_config_restart_hash() {
 
 get_config_cid_ifaces() {
 	local _ifaces
-	config_get _ifaces 'config' 'cid_interface'
+	config_get _ifaces 'config' "$2"
 
 	local _iface _ifnames=""
 	for _iface in $_ifaces; do
@@ -99,16 +99,8 @@ write_lldpd_conf()
 	local lldp_hostname
 	config_get lldp_hostname 'config' 'lldp_hostname' "$(cat /proc/sys/kernel/hostname)"
 
-	local ifaces
-	config_get ifaces 'config' 'interface'
-
-	local iface ifnames=""
-	for iface in $ifaces; do
-		local ifname=""
-		if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
-			append ifnames "${ifname:-$iface}" ","
-		fi
-	done
+	local ifnames
+	get_config_cid_ifaces ifnames "interface"
 
 	local lldp_mgmt_ip
 	config_get lldp_mgmt_ip 'config' 'lldp_mgmt_ip'
@@ -141,7 +133,7 @@ write_lldpd_conf()
 
 	# Clear out the config file first
 	echo -n > "$LLDPD_CONF"
-	[ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF"
+	[ -n "$ifnames" ] && echo "configure system interface pattern $ifnames" >> "$LLDPD_CONF"
 	[ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF"
 	[ -n "$lldp_hostname" ] && echo "configure system hostname" "\"$lldp_hostname\"" >> "$LLDPD_CONF"
 	[ -n "$lldp_mgmt_ip" ] && echo "configure system ip management pattern" "\"$lldp_mgmt_ip\"" >> "$LLDPD_CONF"
@@ -299,7 +291,8 @@ start_service() {
 
     # ChassisID interfaces
 	local ifnames
-	get_config_cid_ifaces ifnames
+	get_config_cid_ifaces ifnames "cid_interface"
+
 	[ -n "$ifnames" ] && procd_append_param command -C "$ifnames"
 
     # Overwrite default configuration locations processed by lldpcli at start




More information about the lede-commits mailing list