lldpd: refactor out ifaces derivation; reuse function
authorPaul Donald <newtwen@gmail.com>
Thu, 8 Feb 2024 21:05:11 +0000 (22:05 +0100)
committerRobert Marko <robimarko@gmail.com>
Tue, 17 Sep 2024 10:36:03 +0000 (12:36 +0200)
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@gmail.com>
(cherry picked from commit 228d4e7f1b759c11897043dc73ef3c576bc13f7f)
Link: https://github.com/openwrt/openwrt/pull/15299
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/network/services/lldpd/files/lldpd.init

index 4841027432150b9cd9d7e11f2974beb4b817752c..e13128e2d6bfcbca8bc6716a8c62ec6e727883ad 100644 (file)
@@ -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