[openwrt/openwrt] lldpd: extended interface(s) parsing to handle patterns

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


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

commit 0b48b832a945e7153b0028e7b08098e7d6a6ee4a
Author: Paul Donald <newtwen+github at gmail.com>
AuthorDate: Fri Apr 12 21:27:56 2024 +0200

    lldpd: extended interface(s) parsing to handle patterns
    
    For interface type parameters, the man page documents patterns:
    ```
    *,!eth*,!!eth1
    
    uses all interfaces, except interfaces starting with "eth",
    but including "eth1".
    ```
    
    * Renamed `_ifname` to `_l2dev`.
    * get the l2dev via network_get_physdev (and not l3dev)
    * Glob pattern `*` is also valid - use noglob for this
    
    The net result is that now interface 'names' including globs '*' and '!'
    inversions are included in the generated lldpd configs.
    
    Temporarily `set -o noglob` and then `set +o noglob` to disable & enable
    globbing respectively, because when we pass `*` as an interface choice,
    other file and pathnames get sucked in from where the init script runs,
    and the `*` never makes it to lldpd.
    
    Tested extensively on: 22.03.6, 23.05.3
    
    Signed-off-by: Paul Donald <newtwen+github at gmail.com>
    [ squash with commit bumping release version ]
    Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
    (cherry picked from commit 4a81d868db85a7954a73bc6dc4a957bbd6abc813)
    Link: https://github.com/openwrt/openwrt/pull/15299
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 package/network/services/lldpd/Makefile         |  2 +-
 package/network/services/lldpd/files/lldpd.init | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/package/network/services/lldpd/Makefile b/package/network/services/lldpd/Makefile
index 18cdda33ce..5a9a9732d2 100644
--- a/package/network/services/lldpd/Makefile
+++ b/package/network/services/lldpd/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=lldpd
 PKG_VERSION:=1.0.17
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://github.com/lldpd/lldpd/releases/download/$(PKG_VERSION)/
diff --git a/package/network/services/lldpd/files/lldpd.init b/package/network/services/lldpd/files/lldpd.init
index 31cd7fd389..dbe79d2f4a 100644
--- a/package/network/services/lldpd/files/lldpd.init
+++ b/package/network/services/lldpd/files/lldpd.init
@@ -80,12 +80,20 @@ get_config_cid_ifaces() {
 	config_get _ifaces 'config' "$2"
 
 	local _iface _ifnames=""
+	# Set noglob to prevent '*' capturing diverse file names in the for ... in
+	set -o noglob
 	for _iface in $_ifaces; do
-		local _ifname=""
-		if network_get_device _ifname "$_iface" || [ -e "/sys/class/net/$_iface" ]; then
-			append _ifnames "${_ifname:-$_iface}" ","
+
+		local _l2device=""
+		if network_get_physdev _l2device "$_iface" || [ -e "/sys/class/net/$_iface" ]; then
+			append _ifnames "${_l2device:-$_iface}" ","
+		else
+			# Glob case (interface is e.g. '!eth1' or 'eth*' or '*')
+			append _ifnames "$_iface" ","
 		fi
 	done
+	# Turn noglob off i.e. enable glob again
+	set +o noglob
 
 	export -n "${1}=$_ifnames"
 }




More information about the lede-commits mailing list