]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(network): add errors and warnings when network interface does not exist
authorPavel Valena <pvalena@redhat.com>
Mon, 22 Nov 2021 15:40:39 +0000 (16:40 +0100)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Thu, 25 Nov 2021 08:58:37 +0000 (08:58 +0000)
End with error, or show a warning when nonexistent device is specified for network setup like
`ip=10.12.8.12::10.12.255.254:255.255.0.0:xk12:eth0:off`.

I've added the error only for `write-ifcfg.sh`, as I think no such setup should be written.

Resolves: #1712424

modules.d/35network-legacy/ifup.sh
modules.d/35network-legacy/parse-ip-opts.sh
modules.d/45ifcfg/write-ifcfg.sh

index a05c4698080f285c1f5d5f400127cb6971f23be1..0dc9541c8b26a4c53900ef667be135edbab90d02 100755 (executable)
@@ -446,7 +446,11 @@ for p in $(getargs ip=); do
 
     # If this option isn't directed at our interface, skip it
     if [ -n "$dev" ]; then
-        [ "$dev" != "$netif" ] && continue
+        if [ "$dev" != "$netif" ]; then
+            [ ! -e "/sys/class/net/$dev" ] \
+                && warn "Network interface '$dev' does not exist!"
+            continue
+        fi
     else
         iface_is_enslaved "$netif" && continue
     fi
index 35917bbfbc5dc73131c707e45c91a1c82b59a1e2..19af8789653025ecdfbfcfc77f945274da45e9c0 100755 (executable)
@@ -97,6 +97,11 @@ for p in $(getargs ip=); do
         fi
         # IFACES list for later use
         IFACES="$IFACES $dev"
+
+        # Interface should exist
+        if [ ! -e "/sys/class/net/$dev" ]; then
+            warn "Network interface '$dev' does not exist"
+        fi
     fi
 
     # Do we need to check for specific options?
index 5f71515ac7adca84c5a9c270de1036d10c7cc3d2..345863f9956908b5972d8e2064454e51f76dacca 100755 (executable)
@@ -103,6 +103,11 @@ interface_bind() {
     local _netif="$1"
     local _macaddr="$2"
 
+    if [ ! -e "/sys/class/net/$_netif" ]; then
+        derror "Cannot find network interface '$_netif'!"
+        return 1
+    fi
+
     # 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