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

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