Blame SOURCES/0225-ifcfg-write-ifcfg-only-write-DEVICE-for-non-kernel-n.patch

a56a5e
From c4c24171bfbffd7bb75a75b8ceae18ce7296cac6 Mon Sep 17 00:00:00 2001
83bbb1
From: Harald Hoyer <harald@redhat.com>
83bbb1
Date: Fri, 24 Oct 2014 15:47:24 +0200
83bbb1
Subject: [PATCH] ifcfg/write-ifcfg: only write DEVICE for non-kernel names
83bbb1
83bbb1
Rename an interface to the kernel namespace is not allowed, so don't add
83bbb1
DEVICE="<iface>", if HWADDR is given.
83bbb1
83bbb1
(cherry picked from commit 3947f07d93cde5e1cf0d788537e93b135d6c27b0)
83bbb1
---
83bbb1
 modules.d/40network/net-lib.sh   | 46 ++++++++++++++++++++++++++++++-
83bbb1
 modules.d/45ifcfg/write-ifcfg.sh | 59 ++++++++++++++++++++++++++--------------
83bbb1
 2 files changed, 84 insertions(+), 21 deletions(-)
83bbb1
83bbb1
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
1755ca
index 22f77546..337817e3 100755
83bbb1
--- a/modules.d/40network/net-lib.sh
83bbb1
+++ b/modules.d/40network/net-lib.sh
a56a5e
@@ -553,7 +553,19 @@ find_iface_with_link() {
83bbb1
 }
83bbb1
 
83bbb1
 is_persistent_ethernet_name() {
83bbb1
-    case "$1" in
83bbb1
+    local _netif="$1"
83bbb1
+    local _name_assign_type="0"
83bbb1
+
83bbb1
+    [ -f "/sys/class/net/$_netif/name_assign_type" ] \
83bbb1
+        && _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
83bbb1
+
83bbb1
+    # NET_NAME_ENUM 1
83bbb1
+    [ "$_name_assign_type" = "1" ] && return 1
83bbb1
+
83bbb1
+    # NET_NAME_PREDICTABLE 2
83bbb1
+    [ "$_name_assign_type" = "2" ] && return 0
83bbb1
+
83bbb1
+    case "$_netif" in
83bbb1
         # udev persistent interface names
83bbb1
         eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*)
83bbb1
             ;;
a56a5e
@@ -573,3 +585,35 @@ is_persistent_ethernet_name() {
83bbb1
     esac
83bbb1
     return 0
83bbb1
 }
83bbb1
+
83bbb1
+is_kernel_ethernet_name() {
83bbb1
+    local _netif="$1"
83bbb1
+    local _name_assign_type="1"
83bbb1
+
83bbb1
+    if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then
83bbb1
+        _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
83bbb1
+
83bbb1
+        case "$_name_assign_type" in
83bbb1
+            2|3|4)
83bbb1
+                # NET_NAME_PREDICTABLE 2
83bbb1
+                # NET_NAME_USER 3
83bbb1
+                # NET_NAME_RENAMED 4
83bbb1
+                return 1
83bbb1
+                ;;
83bbb1
+            1|*)
83bbb1
+                # NET_NAME_ENUM 1
83bbb1
+                return 0
83bbb1
+                ;;
83bbb1
+        esac
83bbb1
+    fi
83bbb1
+
83bbb1
+    # fallback to error prone manual name check
83bbb1
+    case "$_netif" in
83bbb1
+        eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*)
83bbb1
+            return 0
83bbb1
+            ;;
83bbb1
+        *)
83bbb1
+            return 1
83bbb1
+    esac
83bbb1
+
83bbb1
+}
83bbb1
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
1755ca
index aed30698..a1bae72f 100755
83bbb1
--- a/modules.d/45ifcfg/write-ifcfg.sh
83bbb1
+++ b/modules.d/45ifcfg/write-ifcfg.sh
83bbb1
@@ -82,18 +82,41 @@ print_s390() {
83bbb1
     return 0
83bbb1
 }
83bbb1
 
83bbb1
+hw_bind() {
83bbb1
+    local _netif="$1"
83bbb1
+    local _macaddr="$2"
83bbb1
+
83bbb1
+    [ -n "$_macaddr" ] \
83bbb1
+        && echo "MACADDR=\"$_macaddr\""
83bbb1
+
83bbb1
+    print_s390 "$_netif" \
83bbb1
+        && return 0
83bbb1
+
83bbb1
+    [ -n "$_macaddr" ] && return 0
83bbb1
+
83bbb1
+    is_persistent_ethernet_name "$_netif" && return 0
83bbb1
+
83bbb1
+    [ -f "/sys/class/net/$_netif/addr_assign_type" ] \
83bbb1
+        && [ "$(cat "/sys/class/net/$_netif/addr_assign_type")" != "0" ] \
83bbb1
+        && return 1
83bbb1
+
83bbb1
+    [ -f "/sys/class/net/$_netif/address" ] \
83bbb1
+        || return 1
83bbb1
+
83bbb1
+    echo "HWADDR=\"$(cat /sys/class/net/$_netif/address)\""
83bbb1
+}
83bbb1
+
83bbb1
 interface_bind() {
83bbb1
-    local netif="$1"
83bbb1
-    local macaddr="$2"
83bbb1
-    if ! print_s390 $netif; then
83bbb1
-        if [ -z "$macaddr" ] && \
83bbb1
-            ! is_persistent_ethernet_name "$netif" && \
83bbb1
-            [ -f /sys/class/net/$netif/addr_assign_type ] && \
83bbb1
-            [ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] && \
83bbb1
-            [ -f /sys/class/net/$netif/address ]; then
83bbb1
-            echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
83bbb1
-        fi
83bbb1
+    local _netif="$1"
83bbb1
+    local _macaddr="$2"
83bbb1
+
83bbb1
+    # see, if we can bind it to some hw parms
83bbb1
+    if hw_bind "$_netif" "$_macaddr"; then
83bbb1
+        # only print out DEVICE, if it's user assigned
83bbb1
+        is_kernel_ethernet_name "$_netif" && return 0
83bbb1
     fi
83bbb1
+
83bbb1
+    echo "DEVICE=\"$_netif\""
83bbb1
 }
83bbb1
 
83bbb1
 for netup in /tmp/net.*.did-setup ; do
83bbb1
@@ -131,7 +154,8 @@ for netup in /tmp/net.*.did-setup ; do
83bbb1
 
83bbb1
     {
83bbb1
         echo "# Generated by dracut initrd"
83bbb1
-        echo "DEVICE=\"$netif\""
83bbb1
+        echo "NAME=\"$netif\""
83bbb1
+        interface_bind "$netif" "$macaddr"
83bbb1
         echo "ONBOOT=yes"
83bbb1
         echo "NETBOOT=yes"
83bbb1
         echo "UUID=\"$uuid\""
83bbb1
@@ -177,10 +201,7 @@ for netup in /tmp/net.*.did-setup ; do
83bbb1
     if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
83bbb1
         # standard interface
83bbb1
         {
83bbb1
-            [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
83bbb1
-            interface_bind "$netif" "$macaddr"
83bbb1
             echo "TYPE=Ethernet"
83bbb1
-            echo "NAME=\"$netif\""
83bbb1
             [ -n "$mtu" ] && echo "MTU=\"$mtu\""
83bbb1
         } >> /tmp/ifcfg/ifcfg-$netif
83bbb1
     fi
83bbb1
@@ -207,16 +228,15 @@ for netup in /tmp/net.*.did-setup ; do
83bbb1
             # write separate ifcfg file for the raw eth interface
83bbb1
             (
83bbb1
                 echo "# Generated by dracut initrd"
83bbb1
-                echo "DEVICE=\"$slave\""
83bbb1
+                echo "NAME=\"$slave\""
83bbb1
                 echo "TYPE=Ethernet"
83bbb1
                 echo "ONBOOT=yes"
83bbb1
                 echo "NETBOOT=yes"
83bbb1
                 echo "SLAVE=yes"
83bbb1
                 echo "MASTER=\"$netif\""
83bbb1
-                echo "NAME=\"$slave\""
83bbb1
                 echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
83bbb1
+                unset macaddr
83bbb1
                 [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
83bbb1
-                [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
83bbb1
                 interface_bind "$slave" "$macaddr"
83bbb1
             ) >> /tmp/ifcfg/ifcfg-$slave
83bbb1
         done
83bbb1
@@ -232,15 +252,14 @@ for netup in /tmp/net.*.did-setup ; do
83bbb1
             # write separate ifcfg file for the raw eth interface
83bbb1
             (
83bbb1
                 echo "# Generated by dracut initrd"
83bbb1
-                echo "DEVICE=\"$slave\""
83bbb1
+                echo "NAME=\"$slave\""
83bbb1
                 echo "TYPE=Ethernet"
83bbb1
                 echo "ONBOOT=yes"
83bbb1
                 echo "NETBOOT=yes"
83bbb1
                 echo "BRIDGE=\"$bridgename\""
83bbb1
-                echo "NAME=\"$slave\""
83bbb1
                 echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
83bbb1
+                unset macaddr
83bbb1
                 [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
83bbb1
-                [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
83bbb1
                 interface_bind "$slave" "$macaddr"
83bbb1
             ) >> /tmp/ifcfg/ifcfg-$slave
83bbb1
         done