Blob Blame History Raw
From fb0e5184a6506185998fd12d151f7d34d07c07b3 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Fri, 4 Apr 2014 12:48:03 +0200
Subject: [PATCH] ifcfg: do not bind persistent interface names to HWADDR

---
 modules.d/40network/net-lib.sh   | 27 +++++++++++++++++++++++++++
 modules.d/45ifcfg/write-ifcfg.sh |  6 +++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
index 7430e4ce18..5d4ae32cbb 100755
--- a/modules.d/40network/net-lib.sh
+++ b/modules.d/40network/net-lib.sh
@@ -516,3 +516,30 @@ find_iface_with_link() {
     done
     return 1
 }
+
+is_persistent_ethernet_name() {
+    [ -f /sys/class/net/$netif/addr_assign_type ] || return 1
+    [ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] || return 1
+
+    case "$1" in
+        # udev persistent interface names
+        eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*)
+            ;;
+        eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*)
+            ;;
+        ens[0-9]|ens[0-9][0-9]|ens[0-9][0-9][0-9]*)
+            ;;
+        enp[0-9]s[0-9]*|enp[0-9][0-9]s[0-9]*|enp[0-9][0-9][0-9]*s[0-9]*)
+            ;;
+        enP*p[0-9]s[0-9]*|enP*p[0-9][0-9]s[0-9]*|enP*p[0-9][0-9][0-9]*s[0-9]*)
+            ;;
+        # biosdevname
+        em[0-9]|em[0-9][0-9]|em[0-9][0-9][0-9]*)
+            ;;
+        p[0-9]p[0-9]*|p[0-9][0-9]p[0-9]*|p[0-9][0-9][0-9]*p[0-9]*)
+            ;;
+        *)
+            return 1
+    esac
+    return 0
+}
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
index 486c69a3c7..2631fbe2ee 100755
--- a/modules.d/45ifcfg/write-ifcfg.sh
+++ b/modules.d/45ifcfg/write-ifcfg.sh
@@ -164,7 +164,11 @@ for netup in /tmp/net.*.did-setup ; do
         {
             [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
             if ! print_s390 $netif; then
-                [ -n "$macaddr" ] || echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
+                if [ -z "$macaddr" ] && \
+                    ! is_persistent_ethernet_name "$netif" && \
+                    [ -f /sys/class/net/$netif/address ]; then
+                    echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
+                fi
             fi
             echo "TYPE=Ethernet"
             echo "NAME=\"$netif\""
-- 
1.9.3