]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
network/dhclient-script.sh: add classless-static-routes support
authorHarald Hoyer <harald@redhat.com>
Mon, 29 Feb 2016 13:52:16 +0000 (14:52 +0100)
committerHarald Hoyer <harald@redhat.com>
Mon, 29 Feb 2016 14:00:46 +0000 (15:00 +0100)
https://bugzilla.redhat.com/show_bug.cgi?id=1260955

modules.d/40network/dhclient-script.sh
modules.d/40network/dhclient.conf

index 6d4b9dd13425a4018de0b669376837e3beca74ef..95538585688cb8226811a1ebd17108cfdaf841b7 100755 (executable)
@@ -95,6 +95,51 @@ setup_interface6() {
     [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
 }
 
+function parse_option_121() {
+    while [ $# -ne 0 ]; do
+        mask="$1"
+        shift
+
+        # Is the destination a multicast group?
+        if [ $1 -ge 224 -a $1 -lt 240 ]; then
+            multicast=1
+        else
+            multicast=0
+        fi
+
+        # Parse the arguments into a CIDR net/mask string
+        if [ $mask -gt 24 ]; then
+            destination="$1.$2.$3.$4/$mask"
+            shift; shift; shift; shift
+        elif [ $mask -gt 16 ]; then
+            destination="$1.$2.$3.0/$mask"
+            shift; shift; shift
+        elif [ $mask -gt 8 ]; then
+            destination="$1.$2.0.0/$mask"
+            shift; shift
+        else
+            destination="$1.0.0.0/$mask"
+            shift
+        fi
+
+        # Read the gateway
+        gateway="$1.$2.$3.$4"
+        shift; shift; shift; shift
+
+        # Multicast routing on Linux
+        #  - If you set a next-hop address for a multicast group, this breaks with Cisco switches
+        #  - If you simply leave it link-local and attach it to an interface, it works fine.
+        if [ $multicast -eq 1 ]; then
+            temp_result="$destination dev $interface"
+        else
+            temp_result="$destination via $gateway dev $interface"
+        fi
+
+        echo "/sbin/ip route add $temp_result"
+    done
+}
+
+
 case $reason in
     PREINIT)
         echo "dhcp: PREINIT $netif up"
@@ -129,6 +174,9 @@ case $reason in
         {
             echo '. /lib/net-lib.sh'
             echo "setup_net $netif"
+            if [ -n "$new_classless_static_routes" ]; then
+                modify_routes add "$(parse_option_121 $new_classless_static_routes)"
+            fi
             echo "source_hook initqueue/online $netif"
             [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
             echo "rm -f -- $hookdir/initqueue/setup_net_$netif.sh"
index dbf58821848e3936e887bf41a8a86d458a785f7f..7b067632d606ea6e435ef13301043f84115a371a 100644 (file)
@@ -1,3 +1,6 @@
+
+option classless-routes code 121 = array of unsigned integer 8;
+
 request subnet-mask, broadcast-address, time-offset, routers,
         domain-name, domain-name-servers, domain-search, host-name,
-        root-path, interface-mtu;
+        root-path, interface-mtu classless-routes;