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