Harald Hoyer b2d442
From 67354eebbcd4c358b8194ba5fd1ab1cf7dbd42aa Mon Sep 17 00:00:00 2001
Harald Hoyer b2d442
From: Pingfan Liu <piliu@redhat.com>
Harald Hoyer b2d442
Date: Tue, 24 Apr 2018 16:41:21 +0800
Harald Hoyer b2d442
Subject: [PATCH] 40network: introduce ip=either6 option
Harald Hoyer b2d442
Harald Hoyer b2d442
In kdump, if dump-target is ssh on ipv6, we need to sync until ipv6 addr
Harald Hoyer b2d442
is ready. Currently ip=auto6/dhcp6 provides such function. But in 1st kernel,
Harald Hoyer b2d442
it is hard to know whether the ipv6 addr is got by dhcpv6 or SLAAC.
Harald Hoyer b2d442
E.g ifcfg-eth* contains DHCPV6C=yes direction, but there is no dhcpv6
Harald Hoyer b2d442
server in the network, and then after the system is up, the user
Harald Hoyer b2d442
echo 1 > /proc/sys/net/ipv6/conf/eth0/autoconf && accept_ra by manual
Harald Hoyer b2d442
to obtain a ipv6 addr. Or vice.
Harald Hoyer b2d442
So this patch suggests to make dhcpv6 as auto6 fallback
Harald Hoyer b2d442
Harald Hoyer b2d442
Signed-off-by: Pingfan Liu <piliu@redhat.com>
Harald Hoyer b2d442
---
Harald Hoyer b2d442
 dracut.cmdline.7.asc                 | 4 +++-
Harald Hoyer b2d442
 modules.d/40network/ifup.sh          | 6 +++++-
Harald Hoyer b2d442
 modules.d/40network/net-lib.sh       | 4 ++--
Harald Hoyer b2d442
 modules.d/40network/parse-ip-opts.sh | 1 +
Harald Hoyer b2d442
 4 files changed, 11 insertions(+), 4 deletions(-)
Harald Hoyer b2d442
Harald Hoyer b2d442
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer b2d442
index 8f86efe0..ada15e9f 100644
Harald Hoyer b2d442
--- a/dracut.cmdline.7.asc
Harald Hoyer b2d442
+++ b/dracut.cmdline.7.asc
Harald Hoyer b2d442
@@ -480,7 +480,7 @@ USB Android phone::
Harald Hoyer b2d442
 * enp0s29u1u2
Harald Hoyer b2d442
 =====================
Harald Hoyer b2d442
 
Harald Hoyer b2d442
-**ip=**__{dhcp|on|any|dhcp6|auto6}__::
Harald Hoyer b2d442
+**ip=**__{dhcp|on|any|dhcp6|auto6|either6}__::
Harald Hoyer b2d442
     dhcp|on|any::: get ip from dhcp server from all interfaces. If root=dhcp,
Harald Hoyer b2d442
     loop sequentially through all interfaces (eth0, eth1, ...) and use the first
Harald Hoyer b2d442
     with a valid DHCP root-path.
Harald Hoyer b2d442
@@ -489,6 +489,8 @@ USB Android phone::
Harald Hoyer b2d442
 
Harald Hoyer b2d442
     dhcp6::: IPv6 DHCP
Harald Hoyer b2d442
 
Harald Hoyer b2d442
+    either6::: if auto6 fails, then dhcp6
Harald Hoyer b2d442
+
Harald Hoyer b2d442
 **ip=**__<interface>__:__{dhcp|on|any|dhcp6|auto6}__[:[__<mtu>__][:__<macaddr>__]]::
Harald Hoyer b2d442
     This parameter can be specified multiple times.
Harald Hoyer b2d442
 +
Harald Hoyer b2d442
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
Harald Hoyer b2d442
index 0db3c021..fb672413 100755
Harald Hoyer b2d442
--- a/modules.d/40network/ifup.sh
Harald Hoyer b2d442
+++ b/modules.d/40network/ifup.sh
Harald Hoyer b2d442
@@ -70,16 +70,18 @@ load_ipv6() {
Harald Hoyer b2d442
 }
Harald Hoyer b2d442
 
Harald Hoyer b2d442
 do_ipv6auto() {
Harald Hoyer b2d442
+    local ret
Harald Hoyer b2d442
     load_ipv6
Harald Hoyer b2d442
     echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
Harald Hoyer b2d442
     echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
Harald Hoyer b2d442
     echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
Harald Hoyer b2d442
     linkup $netif
Harald Hoyer b2d442
     wait_for_ipv6_auto $netif
Harald Hoyer b2d442
+    ret=$?
Harald Hoyer b2d442
 
Harald Hoyer b2d442
     [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
Harald Hoyer b2d442
 
Harald Hoyer b2d442
-    return 0
Harald Hoyer b2d442
+    return $ret
Harald Hoyer b2d442
 }
Harald Hoyer b2d442
 
Harald Hoyer b2d442
 # Handle static ip configuration
Harald Hoyer b2d442
@@ -416,6 +418,8 @@ for p in $(getargs ip=); do
Harald Hoyer b2d442
                 do_dhcp -6 ;;
Harald Hoyer b2d442
             auto6)
Harald Hoyer b2d442
                 do_ipv6auto ;;
Harald Hoyer b2d442
+            either6)
Harald Hoyer b2d442
+                do_ipv6auto || do_dhcp -6 ;;
Harald Hoyer b2d442
             *)
Harald Hoyer b2d442
                 do_static ;;
Harald Hoyer b2d442
         esac
Harald Hoyer b2d442
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
Harald Hoyer b2d442
index 71a665cd..eac1c5eb 100755
Harald Hoyer b2d442
--- a/modules.d/40network/net-lib.sh
Harald Hoyer b2d442
+++ b/modules.d/40network/net-lib.sh
Harald Hoyer b2d442
@@ -458,7 +458,7 @@ ip_to_var() {
Harald Hoyer b2d442
     fi
Harald Hoyer b2d442
 
Harald Hoyer b2d442
     if [ $# -eq 1 ]; then
Harald Hoyer b2d442
-        # format: ip={dhcp|on|any|dhcp6|auto6}
Harald Hoyer b2d442
+        # format: ip={dhcp|on|any|dhcp6|auto6|either6}
Harald Hoyer b2d442
         # or
Harald Hoyer b2d442
         #         ip=<ipv4-address> means anaconda-style static config argument cluster
Harald Hoyer b2d442
         autoconf="$1"
Harald Hoyer b2d442
@@ -485,7 +485,7 @@ ip_to_var() {
Harald Hoyer b2d442
         return 0
Harald Hoyer b2d442
     fi
Harald Hoyer b2d442
 
Harald Hoyer b2d442
-    if [ "$2" = "dhcp" -o "$2" = "on" -o "$2" = "any" -o "$2" = "dhcp6" -o "$2" = "auto6" ]; then
Harald Hoyer b2d442
+    if [ "$2" = "dhcp" -o "$2" = "on" -o "$2" = "any" -o "$2" = "dhcp6" -o "$2" = "auto6" -o "$2" = "either6" ]; then
Harald Hoyer b2d442
         # format: ip=<interface>:{dhcp|on|any|dhcp6|auto6}[:[<mtu>][:<macaddr>]]
Harald Hoyer b2d442
         [ -n "$1" ] && dev="$1"
Harald Hoyer b2d442
         [ -n "$2" ] && autoconf="$2"
Harald Hoyer b2d442
diff --git a/modules.d/40network/parse-ip-opts.sh b/modules.d/40network/parse-ip-opts.sh
Harald Hoyer b2d442
index 5779ef88..10a2d19b 100755
Harald Hoyer b2d442
--- a/modules.d/40network/parse-ip-opts.sh
Harald Hoyer b2d442
+++ b/modules.d/40network/parse-ip-opts.sh
Harald Hoyer b2d442
@@ -76,6 +76,7 @@ for p in $(getargs ip=); do
Harald Hoyer b2d442
                     die "Sorry, automatic calculation of netmask is not yet supported"
Harald Hoyer b2d442
                 ;;
Harald Hoyer b2d442
             auto6);;
Harald Hoyer b2d442
+            either6);;
Harald Hoyer b2d442
             dhcp|dhcp6|on|any) \
Harald Hoyer b2d442
                 [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \
Harald Hoyer b2d442
                     die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"