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

LEDE Commits lede-commits at lists.infradead.org
Mon Mar 11 01:58:34 PDT 2024


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/228d4e7f1b759c11897043dc73ef3c576bc13f7f

commit 228d4e7f1b759c11897043dc73ef3c576bc13f7f
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>
---
 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