File kdump-query-systemd-network.service.patch of Package kdump.21349

From: Petr Tesarik <ptesarik@suse.com>
Date: Fri Mar 5 10:45:03 2021 +0100
Subject: Query systemd network.service to find out if wicked is used
References: bsc#1182309
Upstream: merged
Git-commit: 44a25927a0c234eb1c731b919d16cf282d168138

Even if wicked is installed on a system, network may still be
managed by NetworkManager. Improve the logic by checking the
actual Id of the currently configured network.service.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>

---
 init/setup-kdump.functions |   49 ++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 16 deletions(-)

--- a/init/setup-kdump.functions
+++ b/init/setup-kdump.functions
@@ -65,6 +65,21 @@ function kdump_route2dev()						   # {{{
     sed -n 's/.* dev \([^ ]*\) *.*/\1/p'
 }									   # }}}
 
+# Get network manager id
+#
+# Output:
+#   network manager identifier ("wicked" or "NetworkManager")
+function kdump_net_manager()						   # {{{
+{
+    if [ -z "$kdump_cached_net_manager" ] ; then
+	local _id
+	_id=$(systemctl show --property=Id network.service)
+	_id="${_id#Id=}"
+	kdump_cached_net_manager="${_id%.service}"
+    fi
+    echo "$kdump_cached_net_manager"
+}									   # }}}
+
 #
 # Get a wicked configuration value for a device
 #
@@ -130,17 +145,19 @@ function kdump_netdev_mode()						   # {
     local BOOTPROTO
 
     # get mode using wicked if possible
-    if [ -n "$(type -P wicked)" -a \
-	"$(kdump_wicked_conf "$ifname" "%{name}")" = "$ifname" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
-	local dhcpv4 dhcpv6
-	eval $( kdump_wicked_conf "$ifname" \
-		"dhcpv4=%{ipv4:dhcp/enabled}" \
-		"dhcpv6=%{ipv6:dhcp/enabled}" )
-	if [ "$dhcpv4" = true -o "$dhcpv6" = true ] ; then
-	    BOOTPROTO=dhcp
-	else
-	    BOOTPROTO=static
+	if [ "$(kdump_wicked_conf "$ifname" "%{name}")" = "$ifname" ]
+	then
+	    local dhcpv4 dhcpv6
+	    eval $( kdump_wicked_conf "$ifname" \
+		    "dhcpv4=%{ipv4:dhcp/enabled}" \
+		    "dhcpv6=%{ipv6:dhcp/enabled}" )
+	    if [ "$dhcpv4" = true -o "$dhcpv6" = true ] ; then
+		BOOTPROTO=dhcp
+	    else
+		BOOTPROTO=static
+	    fi
 	fi
     fi
 
@@ -188,7 +205,7 @@ function kdump_ifkind()							   # {{{
 	echo ovs-system
 
     # get kind using wicked if possible
-    elif [ -n "$(type -P wicked)" ]
+    elif [ "$(kdump_net_manager)" = "wicked" ]
     then
 	local -a elems=(
 	    infiniband
@@ -269,7 +286,7 @@ function kdump_bridge_config()						   #
     local curslaves
 
     # use wicked to read VLAN configuration, if possible
-    if [ -n "$(type -P wicked)" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
 	curslaves=$( kdump_wicked_conf "$bridge" "%{bridge/ports/port/device}" )
     fi
@@ -308,7 +325,7 @@ function kdump_bond_config()						   # {
     local curslaves opts
 
     # use wicked to read bonding settings, if possible
-    if [ -n "$(type -P wicked)" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
 	local -a optvars=(
 		mode arp_interval arp_validate arp_all_targets arp_ip_target
@@ -437,7 +454,7 @@ function kdump_vlan_config()						   # {
     local vid
 
     # use wicked to read VLAN configuration, if possible
-    if [ -n "$(type -P wicked)" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
 	eval $( kdump_wicked_conf "$if" \
 		"vid=%{vlan/tag}; if=%{vlan/device}" )
@@ -566,7 +583,7 @@ function kdump_ip_routes()						   # {{{
     local _addintf="s/\$/:${_bootif}/p"
 
     # get configured routes using wicked if possible
-    if [ -n "$(type -P wicked)" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
 	wicked show-config | \
 	    wicked xpath --reference \
@@ -647,7 +664,7 @@ function kdump_ip6_routes()						   # {{
     local _addintf="s/\$/:${_bootif}/p"
 
     # get configured routes using wicked if possible
-    if [ -n "$(type -P wicked)" ]
+    if [ "$(kdump_net_manager)" = "wicked" ]
     then
 	wicked show-config | \
 	    wicked xpath \
openSUSE Build Service is sponsored by