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