udev: Fix renaming bridged interfaces

Message ID 20210407145636.15829-1-michael.tremer@ipfire.org
State Accepted
Commit 087a20011bfb421b99a10fce5092b42026eb8218
Headers
Series udev: Fix renaming bridged interfaces |

Commit Message

Michael Tremer April 7, 2021, 2:56 p.m. UTC
  From: Daniel Weismüller <daniel.weismueller@ipfire.org>

Since using random interface names is always trouble, we will order all
slave interfaces and number them in order as they appear in the SLAVES
variable.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 config/udev/network-hotplug-rename | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
  

Patch

diff --git a/config/udev/network-hotplug-rename b/config/udev/network-hotplug-rename
index 71a25c317..8807e0ab8 100644
--- a/config/udev/network-hotplug-rename
+++ b/config/udev/network-hotplug-rename
@@ -58,18 +58,25 @@  for zone in ${ZONES}; do
 	address="${zone}_MACADDR"
 	device="${zone}_DEV"
 	mode="${zone}_MODE"
+	slaves="${zone}_SLAVES"
 
-	# Skip if address or device is unset
-	[ -n "${!address}" -a -n "${!device}" ] || continue
-
-	# Compare MAC addresses
-	[ "${ADDRESS}" = "${!address,,}" ] || continue
+	# Return DEV when the address matches
+	if [ "${!address,,}" = "${ADDRESS,,}" ]; then
+		echo "${!device}"
+		exit 0
+	fi
 
 	# If a matching interface has been found we will
 	# print the name to which udev will rename it.
 	case "${!mode}" in
 		bridge)
-			echo "${!device%0}phys0"
+			counter=0
+			for slave in ${!slaves}; do
+				if [ "${slave,,}" = "${ADDRESS,,}" ]; then
+					echo "${!device}p${counter}"
+				fi
+				(( counter += 1 ))
+			done
 			;;
 
 		macvtap)
@@ -81,13 +88,7 @@  for zone in ${ZONES}; do
 				echo "${!device%0}phys0"
 			fi
 			;;
-
-		*)
-			echo "${!device}"
-			;;
 	esac
-
-	exit 0
 done
 
 # If we get here we have not found a matching device,