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

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