f226d6
From 94ec96c35678f56bc74b9c12c3229971bc40c9b3 Mon Sep 17 00:00:00 2001
f226d6
From: Pavel Valena <pvalena@redhat.com>
f226d6
Date: Mon, 22 Nov 2021 16:40:39 +0100
f226d6
Subject: [PATCH] fix(network): add errors and warnings when network interface
f226d6
 does not exist
f226d6
f226d6
End with error, or show a warning when nonexistent device is specified for network setup like
f226d6
`ip=10.12.8.12::10.12.255.254:255.255.0.0:xk12:eth0:off`.
f226d6
f226d6
I've added the error only for `write-ifcfg.sh`, as I think no such setup should be written.
f226d6
f226d6
(cherry picked from commit 7938935267dd8824f074adf84c219340ad4c8db6)
f226d6
f226d6
Resolves: #2050562
f226d6
---
f226d6
 modules.d/35network-legacy/ifup.sh          | 6 +++++-
f226d6
 modules.d/35network-legacy/parse-ip-opts.sh | 5 +++++
f226d6
 modules.d/45ifcfg/write-ifcfg.sh            | 5 +++++
f226d6
 3 files changed, 15 insertions(+), 1 deletion(-)
f226d6
f226d6
diff --git a/modules.d/35network-legacy/ifup.sh b/modules.d/35network-legacy/ifup.sh
f226d6
index a05c4698..0dc9541c 100755
f226d6
--- a/modules.d/35network-legacy/ifup.sh
f226d6
+++ b/modules.d/35network-legacy/ifup.sh
f226d6
@@ -446,7 +446,11 @@ for p in $(getargs ip=); do
f226d6
 
f226d6
     # If this option isn't directed at our interface, skip it
f226d6
     if [ -n "$dev" ]; then
f226d6
-        [ "$dev" != "$netif" ] && continue
f226d6
+        if [ "$dev" != "$netif" ]; then
f226d6
+            [ ! -e "/sys/class/net/$dev" ] \
f226d6
+                && warn "Network interface '$dev' does not exist!"
f226d6
+            continue
f226d6
+        fi
f226d6
     else
f226d6
         iface_is_enslaved "$netif" && continue
f226d6
     fi
f226d6
diff --git a/modules.d/35network-legacy/parse-ip-opts.sh b/modules.d/35network-legacy/parse-ip-opts.sh
f226d6
index 35917bbf..19af8789 100755
f226d6
--- a/modules.d/35network-legacy/parse-ip-opts.sh
f226d6
+++ b/modules.d/35network-legacy/parse-ip-opts.sh
f226d6
@@ -97,6 +97,11 @@ for p in $(getargs ip=); do
f226d6
         fi
f226d6
         # IFACES list for later use
f226d6
         IFACES="$IFACES $dev"
f226d6
+
f226d6
+        # Interface should exist
f226d6
+        if [ ! -e "/sys/class/net/$dev" ]; then
f226d6
+            warn "Network interface '$dev' does not exist"
f226d6
+        fi
f226d6
     fi
f226d6
 
f226d6
     # Do we need to check for specific options?
f226d6
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
f226d6
index 5f71515a..345863f9 100755
f226d6
--- a/modules.d/45ifcfg/write-ifcfg.sh
f226d6
+++ b/modules.d/45ifcfg/write-ifcfg.sh
f226d6
@@ -103,6 +103,11 @@ interface_bind() {
f226d6
     local _netif="$1"
f226d6
     local _macaddr="$2"
f226d6
 
f226d6
+    if [ ! -e "/sys/class/net/$_netif" ]; then
f226d6
+        derror "Cannot find network interface '$_netif'!"
f226d6
+        return 1
f226d6
+    fi
f226d6
+
f226d6
     # see, if we can bind it to some hw parms
f226d6
     if hw_bind "$_netif" "$_macaddr"; then
f226d6
         # only print out DEVICE, if it's user assigned
f226d6