kdump/kdump-add-IPv6-KDUMP_NETCONFIG-modes.patch

201 lines
6.0 KiB
Diff

From: Petr Tesarik <ptesarik@suse.cz>
Date: Tue Sep 23 16:12:34 2014 +0200
Subject: Add KDUMP_NETCONFIG modes to support IPv6
References: bnc#885897
Patch-mainline: v0.8.16
Git-commit: 72be4138d5ac03af8c5579099c6a39ab7d272503
KDUMP_NETCONFIG had only two modes: static and dhcp, where dhcp
actually only means DHCP4. New modes are needed to get an IPv6
address on the interface.
Note that automatic configuration (KDUMP_NETCONFIG=auto) still uses
only IPv4, because dracut does not implement multiple alternative
ip configurations, and there's no way to determine in advance
which stack should be used.
Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
---
doc/man/kdump.5.txt.in | 35 ++++++++++++++++++++++++++++++-----
init/module-setup.sh | 42 ++++++++++++++++++++++++++++++++++--------
init/setup-kdump.functions | 39 ++++++++++++++++++++++++++++++++++++++-
sysconfig.kdump.in | 4 ++--
4 files changed, 104 insertions(+), 16 deletions(-)
--- a/doc/man/kdump.5.txt.in
+++ b/doc/man/kdump.5.txt.in
@@ -513,13 +513,38 @@ KDUMP_NETCONFIG
Network configuration for kdump. Because the dump process runs in initrd, the
network configuration is different from the normal network configuration. Use
-_auto_ to auto-detect the network configuration, this is also the default.
+_auto_ to auto-detect the network configuration (see *auto* mode below). The
+interface with the default route will be used. This is the default.
+
+Auto-detection cannot be used to set up dual-stack (IPv4 and IPv6) hosts
+because of limitations in the implementation of the _ip=_ initrd command line
+option.
Use a _netdevice:mode_ string to force a specific network device to be used. A
-_netdevice_ is for example "eth0". The _mode_ can be either "dhcp" or "static".
-If you use "static", you have to set the IP address with _ip=ipspec_. _ipspec_
-is <client>:<server>:<gateway>:<netmask>:<hostname>:<device>:<proto>. See
-*mkinitrd*(8) for details.
+_netdevice_ is for example "eth0". The _mode_ can be:
+
+*static*::
+ Always re-use the current configuration of _netdevice_ (both IPv4 and IPv6).
+ Note that only permanent global IPv6 addresses are stored, because temporary
+ addresses are likely to expire before the system crashes, and link-local
+ addresses are set up automatically.
+
+*auto6*::
+ Use IPv6 autoconfiguration to get an address on the interface.
+
+*dhcp*::
+*dhcp4*::
+ Use DHCP to configure an IPv4 address on the interface.
+
+*dhcp6*::
+ Use DHCP6 to configure an IPv6 address on the interface.
+
+*auto*::
+ Select the mode depending on the current state of the interface:
+
+ * use DHCP4 if it has an IPv4 address (IPv6 not set up),
+ * use DHCP6 if it has a permanent IPv6 address (IPv4 not set up),
+ * use IPv6 auto-configuration if it has neither (IPv4 not set up).
You can set KDUMP_NETCONFIG to "" if you want no network in initrd, i.e. you use
disk dumping.
--- a/init/module-setup.sh
+++ b/init/module-setup.sh
@@ -65,24 +65,50 @@ kdump_cmdline_ip() {
[ "$kdump_neednet" = y ] || return 0
echo -n "rd.neednet=1"
+
+ local _if _mode
if [ "$KDUMP_NETCONFIG" = "auto" ] ; then
- echo -n " ip=any"
+ _if=default
+ _mode=auto
else
set -- ${KDUMP_NETCONFIG//:/ }
local _if=$1
local _mode=$2
+ fi
- if [ "$_if" = "default" ] ; then
- _if=$(kdump_default_netdev)
- fi
- printf " %s" $(kdump_ifname_config "$_if")
+ [ "$_if" = "default" ] && _if=$(kdump_default_netdev)
- if [ "$_mode" = "static" ] ; then
- printf " %s" $(kdump_ip_config "$_if")
+ printf " %s" $(kdump_ifname_config "$_if")
+
+ if [ "$_mode" = "auto" ] ; then
+ if [ -n $(kdump_ip_config) ] ; then
+ _mode=dhcp4
+ elif [ -n $(kdump_ip6_config) ] ; then
+ _mode=dhcp6
else
- echo -n " ip=${_if}:dhcp"
+ _mode=auto6
fi
fi
+
+ case "$_mode" in
+ static)
+ printf " %s" \
+ $(kdump_ip_config "$_if") \
+ $(kdump_ip6_config "$_if")
+ ;;
+ dhcp|dhcp4)
+ echo " ip=${_if}:dhcp"
+ ;;
+ dhcp6)
+ echo " ip=${_if}:dhcp6"
+ ;;
+ auto6)
+ echo " ip=${_if}:auto6"
+ ;;
+ *)
+ derror "Wrong KDUMP_NETCONFIG mode: $_mode"
+ ;;
+ esac
}
cmdline() {
--- a/init/setup-kdump.functions
+++ b/init/setup-kdump.functions
@@ -230,7 +230,7 @@ kdump_prefix2netmask() { # {{{
} # }}}
#
-# Get the ip= parameter for a given device
+# Get the IPv4 ip= parameter for a given device
#
# Parameters:
# 1) device device name
@@ -267,6 +267,43 @@ function kdump_ip_config() # {{{
} # }}}
#
+# Get the IPv6 ip= parameter for a given device
+#
+# Parameters:
+# 1) device device name
+# Output:
+# ip configuration string that can be used for the ip= initrd parameter
+function kdump_ip6_config() # {{{
+{
+ local iface="$1"
+ local ipaddr peeraddr gwaddr hostname
+ local family cidr rest prefix
+
+ hostname=$(hostname)
+ gwaddr=$(ip -6 route show ::/0 | sed -n 's/.* via \([^ ]*\).*/[\1]/p')
+
+ while read family cidr rest
+ do
+ [ "$family" = "inet6" ] || continue
+
+ ipaddr="${cidr%/*}"
+ prefix="${cidr:${#ipaddr}}"
+ ipaddr="[$ipaddr]$prefix"
+ set -- $rest
+
+ if [ "$1" == "peer" ] ; then
+ peeraddr="${2%/*}"
+ prefix="${2:${#peeraddr}}"
+ peeraddr="[$peeraddr]"
+ else
+ peeraddr=
+ fi
+
+ echo "ip=$ipaddr:$peeraddr:$gwaddr::$hostname:$iface:none"
+ done < <(ip -6 address show dev "$iface" permanent scope global)
+} # }}}
+
+#
# Get the save directory and protocol.
#
# Output variables:
--- a/sysconfig.kdump.in
+++ b/sysconfig.kdump.in
@@ -279,8 +279,8 @@ KDUMPTOOL_FLAGS=""
## ServiceRestart: kdump
#
# Network configuration. Use "auto" for auto-detection in initrd, or a string
-# that contains the network device and the mode (dhcp,static), separated by
-# a colon. Example: "eth0:static" or "eth1:dhcp".
+# that contains the network device and the mode (static, dhcp, dhcp6, auto6),
+# separated by a colon. Example: "eth0:static" or "eth1:dhcp".
#
# For static configuration, you have to add the configuration to
# KDUMP_COMMANDLINE_APPEND.