Blame 0032-network-dhclient-script.sh-add-classless-static-rout.patch

Harald Hoyer b38677
From caf12d6717379769e4f12296405edc4d547d46f8 Mon Sep 17 00:00:00 2001
Harald Hoyer b38677
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer b38677
Date: Mon, 29 Feb 2016 14:52:16 +0100
Harald Hoyer b38677
Subject: [PATCH] network/dhclient-script.sh: add classless-static-routes
Harald Hoyer b38677
 support
Harald Hoyer b38677
Harald Hoyer b38677
https://bugzilla.redhat.com/show_bug.cgi?id=1260955
Harald Hoyer b38677
(cherry picked from commit a48ea27debb926a30810c9f1a42f096494c727e2)
Harald Hoyer b38677
---
Harald Hoyer b38677
 modules.d/40network/dhclient-script.sh | 48 ++++++++++++++++++++++++++++++++++
Harald Hoyer b38677
 modules.d/40network/dhclient.conf      |  5 +++-
Harald Hoyer b38677
 2 files changed, 52 insertions(+), 1 deletion(-)
Harald Hoyer b38677
Harald Hoyer b38677
diff --git a/modules.d/40network/dhclient-script.sh b/modules.d/40network/dhclient-script.sh
Harald Hoyer b38677
index 9aac2b1..13d2dc2 100755
Harald Hoyer b38677
--- a/modules.d/40network/dhclient-script.sh
Harald Hoyer b38677
+++ b/modules.d/40network/dhclient-script.sh
Harald Hoyer b38677
@@ -95,6 +95,51 @@ setup_interface6() {
Harald Hoyer b38677
     [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
+function parse_option_121() {
Harald Hoyer b38677
+    while [ $# -ne 0 ]; do
Harald Hoyer b38677
+        mask="$1"
Harald Hoyer b38677
+        shift
Harald Hoyer b38677
+
Harald Hoyer b38677
+        # Is the destination a multicast group?
Harald Hoyer b38677
+        if [ $1 -ge 224 -a $1 -lt 240 ]; then
Harald Hoyer b38677
+            multicast=1
Harald Hoyer b38677
+        else
Harald Hoyer b38677
+            multicast=0
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
+
Harald Hoyer b38677
+        # Parse the arguments into a CIDR net/mask string
Harald Hoyer b38677
+        if [ $mask -gt 24 ]; then
Harald Hoyer b38677
+            destination="$1.$2.$3.$4/$mask"
Harald Hoyer b38677
+            shift; shift; shift; shift
Harald Hoyer b38677
+        elif [ $mask -gt 16 ]; then
Harald Hoyer b38677
+            destination="$1.$2.$3.0/$mask"
Harald Hoyer b38677
+            shift; shift; shift
Harald Hoyer b38677
+        elif [ $mask -gt 8 ]; then
Harald Hoyer b38677
+            destination="$1.$2.0.0/$mask"
Harald Hoyer b38677
+            shift; shift
Harald Hoyer b38677
+        else
Harald Hoyer b38677
+            destination="$1.0.0.0/$mask"
Harald Hoyer b38677
+            shift
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
+
Harald Hoyer b38677
+        # Read the gateway
Harald Hoyer b38677
+        gateway="$1.$2.$3.$4"
Harald Hoyer b38677
+        shift; shift; shift; shift
Harald Hoyer b38677
+
Harald Hoyer b38677
+        # Multicast routing on Linux
Harald Hoyer b38677
+        #  - If you set a next-hop address for a multicast group, this breaks with Cisco switches
Harald Hoyer b38677
+        #  - If you simply leave it link-local and attach it to an interface, it works fine.
Harald Hoyer b38677
+        if [ $multicast -eq 1 ]; then
Harald Hoyer b38677
+            temp_result="$destination dev $interface"
Harald Hoyer b38677
+        else
Harald Hoyer b38677
+            temp_result="$destination via $gateway dev $interface"
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
+
Harald Hoyer b38677
+        echo "/sbin/ip route add $temp_result"
Harald Hoyer b38677
+    done
Harald Hoyer b38677
+}
Harald Hoyer b38677
+
Harald Hoyer b38677
+
Harald Hoyer b38677
 case $reason in
Harald Hoyer b38677
     PREINIT)
Harald Hoyer b38677
         echo "dhcp: PREINIT $netif up"
Harald Hoyer b38677
@@ -129,6 +174,9 @@ case $reason in
Harald Hoyer b38677
         {
Harald Hoyer b38677
             echo '. /lib/net-lib.sh'
Harald Hoyer b38677
             echo "setup_net $netif"
Harald Hoyer b38677
+            if [ -n "$new_classless_static_routes" ]; then
Harald Hoyer b38677
+                modify_routes add "$(parse_option_121 $new_classless_static_routes)"
Harald Hoyer b38677
+            fi
Harald Hoyer b38677
             echo "source_hook initqueue/online $netif"
Harald Hoyer b38677
             [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
Harald Hoyer b38677
             echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
Harald Hoyer b38677
diff --git a/modules.d/40network/dhclient.conf b/modules.d/40network/dhclient.conf
Harald Hoyer b38677
index dbf5882..7b06763 100644
Harald Hoyer b38677
--- a/modules.d/40network/dhclient.conf
Harald Hoyer b38677
+++ b/modules.d/40network/dhclient.conf
Harald Hoyer b38677
@@ -1,3 +1,6 @@
Harald Hoyer b38677
+
Harald Hoyer b38677
+option classless-routes code 121 = array of unsigned integer 8;
Harald Hoyer b38677
+
Harald Hoyer b38677
 request subnet-mask, broadcast-address, time-offset, routers,
Harald Hoyer b38677
         domain-name, domain-name-servers, domain-search, host-name,
Harald Hoyer b38677
-        root-path, interface-mtu;
Harald Hoyer b38677
+        root-path, interface-mtu classless-routes;