]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
ifcfg/write-ifcfg: only write DEVICE for non-kernel names
authorHarald Hoyer <harald@redhat.com>
Fri, 24 Oct 2014 13:47:24 +0000 (15:47 +0200)
committerHarald Hoyer <harald@redhat.com>
Tue, 28 Oct 2014 14:13:35 +0000 (15:13 +0100)
Rename an interface to the kernel namespace is not allowed, so don't add
DEVICE="<iface>", if HWADDR is given.

modules.d/40network/net-lib.sh
modules.d/45ifcfg/write-ifcfg.sh

index 8b5fbc64b52bf5322d1eb144c3523e5224c5cdf0..48e70141d5b4cf7343eeb4aa7ffb0d48ef1cc4c3 100755 (executable)
@@ -551,7 +551,19 @@ find_iface_with_link() {
 }
 
 is_persistent_ethernet_name() {
-    case "$1" in
+    local _netif="$1"
+    local _name_assign_type="0"
+
+    [ -f "/sys/class/net/$_netif/name_assign_type" ] \
+        && _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
+
+    # NET_NAME_ENUM 1
+    [ "$_name_assign_type" = "1" ] && return 1
+
+    # NET_NAME_PREDICTABLE 2
+    [ "$_name_assign_type" = "2" ] && return 0
+
+    case "$_netif" in
         # udev persistent interface names
         eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*)
             ;;
@@ -571,3 +583,35 @@ is_persistent_ethernet_name() {
     esac
     return 0
 }
+
+is_kernel_ethernet_name() {
+    local _netif="$1"
+    local _name_assign_type="1"
+
+    if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then
+        _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
+
+        case "$_name_assign_type" in
+            2|3|4)
+                # NET_NAME_PREDICTABLE 2
+                # NET_NAME_USER 3
+                # NET_NAME_RENAMED 4
+                return 1
+                ;;
+            1|*)
+                # NET_NAME_ENUM 1
+                return 0
+                ;;
+        esac
+    fi
+
+    # fallback to error prone manual name check
+    case "$_netif" in
+        eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*)
+            return 0
+            ;;
+        *)
+            return 1
+    esac
+
+}
index bb706f6f7ae5c31d2d4591af60989abaf0fb8f7b..3dcf3042491798b65a48563a09986dfcdc49a553 100755 (executable)
@@ -80,18 +80,41 @@ print_s390() {
     return 0
 }
 
+hw_bind() {
+    local _netif="$1"
+    local _macaddr="$2"
+
+    [ -n "$_macaddr" ] \
+        && echo "MACADDR=\"$_macaddr\""
+
+    print_s390 "$_netif" \
+        && return 0
+
+    [ -n "$_macaddr" ] && return 0
+
+    is_persistent_ethernet_name "$_netif" && return 0
+
+    [ -f "/sys/class/net/$_netif/addr_assign_type" ] \
+        && [ "$(cat "/sys/class/net/$_netif/addr_assign_type")" != "0" ] \
+        && return 1
+
+    [ -f "/sys/class/net/$_netif/address" ] \
+        || return 1
+
+    echo "HWADDR=\"$(cat /sys/class/net/$_netif/address)\""
+}
+
 interface_bind() {
-    local netif="$1"
-    local macaddr="$2"
-    if ! print_s390 $netif; then
-        if [ -z "$macaddr" ] && \
-            ! is_persistent_ethernet_name "$netif" && \
-            [ -f /sys/class/net/$netif/addr_assign_type ] && \
-            [ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] && \
-            [ -f /sys/class/net/$netif/address ]; then
-            echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
-        fi
+    local _netif="$1"
+    local _macaddr="$2"
+
+    # see, if we can bind it to some hw parms
+    if hw_bind "$_netif" "$_macaddr"; then
+        # only print out DEVICE, if it's user assigned
+        is_kernel_ethernet_name "$_netif" && return 0
     fi
+
+    echo "DEVICE=\"$_netif\""
 }
 
 for netup in /tmp/net.*.did-setup ; do
@@ -129,7 +152,8 @@ for netup in /tmp/net.*.did-setup ; do
 
     {
         echo "# Generated by dracut initrd"
-        echo "DEVICE=\"$netif\""
+        echo "NAME=\"$netif\""
+        interface_bind "$netif" "$macaddr"
         echo "ONBOOT=yes"
         echo "NETBOOT=yes"
         echo "UUID=\"$uuid\""
@@ -175,10 +199,7 @@ for netup in /tmp/net.*.did-setup ; do
     if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
         # standard interface
         {
-            [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
-            interface_bind "$netif" "$macaddr"
             echo "TYPE=Ethernet"
-            echo "NAME=\"$netif\""
             [ -n "$mtu" ] && echo "MTU=\"$mtu\""
         } >> /tmp/ifcfg/ifcfg-$netif
     fi
@@ -205,16 +226,15 @@ for netup in /tmp/net.*.did-setup ; do
             # write separate ifcfg file for the raw eth interface
             (
                 echo "# Generated by dracut initrd"
-                echo "DEVICE=\"$slave\""
+                echo "NAME=\"$slave\""
                 echo "TYPE=Ethernet"
                 echo "ONBOOT=yes"
                 echo "NETBOOT=yes"
                 echo "SLAVE=yes"
                 echo "MASTER=\"$netif\""
-                echo "NAME=\"$slave\""
                 echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
+                unset macaddr
                 [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
-                [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
                 interface_bind "$slave" "$macaddr"
             ) >> /tmp/ifcfg/ifcfg-$slave
         done
@@ -230,15 +250,14 @@ for netup in /tmp/net.*.did-setup ; do
             # write separate ifcfg file for the raw eth interface
             (
                 echo "# Generated by dracut initrd"
-                echo "DEVICE=\"$slave\""
+                echo "NAME=\"$slave\""
                 echo "TYPE=Ethernet"
                 echo "ONBOOT=yes"
                 echo "NETBOOT=yes"
                 echo "BRIDGE=\"$bridgename\""
-                echo "NAME=\"$slave\""
                 echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
+                unset macaddr
                 [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
-                [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
                 interface_bind "$slave" "$macaddr"
             ) >> /tmp/ifcfg/ifcfg-$slave
         done