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

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