Blame SOURCES/0200-network-add-rd.route-parameter.patch

a56a5e
From c504204de548d45a0fd0e84ba22e29f94e670dbc Mon Sep 17 00:00:00 2001
83bbb1
From: Harald Hoyer <harald@redhat.com>
83bbb1
Date: Tue, 22 Jul 2014 11:03:56 +0200
83bbb1
Subject: [PATCH] network: add rd.route parameter
83bbb1
83bbb1
(cherry picked from commit 7b46244bb94e3dfd635a8d222044ae7fc920240d)
83bbb1
---
83bbb1
 dracut.cmdline.7.asc             | 15 +++++++++++++-
83bbb1
 modules.d/40network/net-lib.sh   | 42 ++++++++++++++++++++++++++++++++++++++++
83bbb1
 modules.d/45ifcfg/write-ifcfg.sh |  3 +++
83bbb1
 3 files changed, 59 insertions(+), 1 deletion(-)
83bbb1
83bbb1
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
a56a5e
index 24bf449..bce8608 100644
83bbb1
--- a/dracut.cmdline.7.asc
83bbb1
+++ b/dracut.cmdline.7.asc
a56a5e
@@ -489,6 +489,19 @@ WARNING: Do **not** use the default kernel naming scheme for the interface name,
83bbb1
 as it can conflict with the kernel names. So, don't use "eth[0-9]+" for the
83bbb1
 interface name. Better name it "bootnet" or "bluesocket".
83bbb1
 
83bbb1
+**rd.route=**__<net>__/__<netmask>__:__<gateway>__[:__<interface>__]::
83bbb1
+    Add a static route with route options, which are separated by a colon.
83bbb1
+    IPv6 addresses have to be put in brackets.
83bbb1
++
83bbb1
+[listing]
83bbb1
+.Example
83bbb1
+--
83bbb1
+    rd.route=192.168.200.0/24:192.168.100.222:ens10
83bbb1
+    rd.route=192.168.200.0/24:192.168.100.222
83bbb1
+    rd.route=192.168.200.0/24::ens10
83bbb1
+    rd.route=[2001:DB8:3::/8]:[2001:DB8:2::1]:ens10
83bbb1
+--
83bbb1
+
83bbb1
 **bootdev=**__<interface>__::
83bbb1
     specify network interface to use routing and netroot information from.
83bbb1
     Required if multiple ip= lines are used.
a56a5e
@@ -536,7 +549,7 @@ NFS
83bbb1
 ~~~
83bbb1
 **root=**\[_<server-ip>_:]__<root-dir>__[:__<nfs-options>__]::
83bbb1
     mount nfs share from <server-ip>:/<root-dir>, if no server-ip is given, use
83bbb1
-    dhcp next_server. if server-ip is an IPv6 address it has to be put in
83bbb1
+    dhcp next_server. If server-ip is an IPv6 address it has to be put in
83bbb1
     brackets, e.g. [2001:DB8::1]. NFS options can be appended with the prefix
83bbb1
     ":" or "," and are seperated by ",".
83bbb1
 
83bbb1
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
a56a5e
index 90337f3..c8f9204 100755
83bbb1
--- a/modules.d/40network/net-lib.sh
83bbb1
+++ b/modules.d/40network/net-lib.sh
83bbb1
@@ -89,6 +89,7 @@ ifdown() {
83bbb1
 
83bbb1
 setup_net() {
83bbb1
     local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
83bbb1
+    local _p
83bbb1
     [ -e /tmp/net.$netif.did-setup ] && return
83bbb1
     [ -e /sys/class/net/$netif/address ] && \
83bbb1
         [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && return
83bbb1
@@ -103,6 +104,20 @@ setup_net() {
83bbb1
     [ -e /tmp/net.$netif.resolv.conf ] && \
83bbb1
         cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf
83bbb1
 
83bbb1
+    # add static route
83bbb1
+    for _p in $(getargs rd.route); do
83bbb1
+        route_to_var "$_p" || continue
83bbb1
+        [ -n "$route_dev" ] && [ "$route_dev" != "$netif"] && continue
83bbb1
+        ip route add "$route_mask" ${route_gw:+via "$route_gw"} ${route_dev:+dev "$route_dev"}
83bbb1
+        if strstr ":" "$route_mask"; then
83bbb1
+            printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \
83bbb1
+                > /tmp/net.route6."$netif"
83bbb1
+        else
83bbb1
+            printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \
83bbb1
+                > /tmp/net.route."$netif"
83bbb1
+        fi
83bbb1
+    done
83bbb1
+
83bbb1
     # Handle STP Timeout: arping the default gateway.
83bbb1
     # (or the root server, if a) it's local or b) there's no gateway.)
83bbb1
     # Note: This assumes that if no router is present the
a56a5e
@@ -400,6 +415,33 @@ ip_to_var() {
83bbb1
     fi
83bbb1
 }
83bbb1
 
83bbb1
+route_to_var() {
83bbb1
+    local v=${1}:
83bbb1
+    local i
83bbb1
+    set --
83bbb1
+    while [ -n "$v" ]; do
83bbb1
+        if [ "${v#\[*:*:*\]:}" != "$v" ]; then
83bbb1
+            # handle IPv6 address
83bbb1
+            i="${v%%\]:*}"
83bbb1
+            i="${i##\[}"
83bbb1
+            set -- "$@" "$i"
83bbb1
+            v=${v#\[$i\]:}
83bbb1
+        else
83bbb1
+            set -- "$@" "${v%%:*}"
83bbb1
+            v=${v#*:}
83bbb1
+        fi
83bbb1
+    done
83bbb1
+
83bbb1
+    unset route_mask route_gw route_dev
83bbb1
+    case $# in
83bbb1
+        2)  [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2"
83bbb1
+            return 0;;
83bbb1
+        3)  [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2"; [ -n "$3" ] && route_dev="$3"
83bbb1
+            return 0;;
83bbb1
+        *)  return 1;;
83bbb1
+    esac
83bbb1
+}
83bbb1
+
83bbb1
 parse_ifname_opts() {
83bbb1
     local IFS=:
83bbb1
     set $1
83bbb1
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
a56a5e
index fb388bc..5e333e4 100755
83bbb1
--- a/modules.d/45ifcfg/write-ifcfg.sh
83bbb1
+++ b/modules.d/45ifcfg/write-ifcfg.sh
a56a5e
@@ -268,6 +268,9 @@ for netup in /tmp/net.*.did-setup ; do
83bbb1
         echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif
83bbb1
         i=$((i+1))
83bbb1
     done
83bbb1
+
83bbb1
+    [ -f /tmp/net.route6."$netif" ] && cp /tmp/net.route6."$netif" /tmp/ifcfg/route6-"$netif"
83bbb1
+    [ -f /tmp/net.route."$netif" ] && cp /tmp/net.route."$netif" /tmp/ifcfg/route-"$netif"
83bbb1
 done
83bbb1
 
83bbb1
 # Pass network opts