Page MenuHomeVyOS Platform

Allow multiple static routes in dhcp-server
Closed, ResolvedPublic

Description

The cli currently supports a single static route via:

set service dhcp-server shared-network-name NETWORK subnet 192.0.2.0/24 static-route

To me it looks like the RFC allows for multiple of those, see https://tools.ietf.org/html/rfc3442.

I can see the use case for that, so I think it would be good if it were implemented.

Details

Difficulty level
Unknown (require assessment)
Version
rolling
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Config syntax change (migratable)
Issue type
Feature (new functionality)

Event Timeline

afics created this object in space S1 VyOS Public.

I solved this issue by doing the following:

Config tree:

# tree /opt/vyatta/share/vyatta-cfg/templates/service/dhcp-server/shared-network-name/node.tag/subnet/node.tag/static-route/
|-- node.def
`-- node.tag
    |-- destination-subnet
    |   `-- node.def
    `-- router
        `-- node.def

Files content:

  • /opt/vyatta/share/vyatta-cfg/templates/service/dhcp-server/shared-network-name/node.tag/subnet/node.tag/static-route/node.def
tag:
type: txt
help: Classless static route
  • /opt/vyatta/share/vyatta-cfg/templates/service/dhcp-server/shared-network-name/node.tag/subnet/node.tag/static-route/node.tag/destination-subnet/node.def
type: ipv4net
help: Destination subnet [REQUIRED]
  • /opt/vyatta/share/vyatta-cfg/templates/service/dhcp-server/shared-network-name/node.tag/subnet/node.tag/static-route/node.tag/router/node.def
type: ipv4
help: IP address of router to be used to reach the destination subnet [REQUIRED]

I also modified the config generator to handle multiple static routes:
/!\ WARNING: I removed option windows-static-route (code 249), since I don't use it and it is now superseeded by option rfc3442-static-route (code 121).

# diff -b -d -u /opt/vyatta/sbin/dhcpd-config.pl.old /opt/vyatta/sbin/dhcpd-config.pl
--- /opt/vyatta/sbin/dhcpd-config.pl.old        2020-01-21 10:47:39.077759997 +0100
+++ /opt/vyatta/sbin/dhcpd-config.pl    2020-01-27 15:35:15.324846659 +0100
@@ -415,21 +415,27 @@
                             $genout .= ";\n";
                         }

+                        my @static_route = $vcDHCP->listNodes(
+                            "$name subnet $subnet static-route");
+                        foreach my $static_route (@static_route) {
+                            next if !defined $static_route;
                         my $destination_subnet = $vcDHCP->returnValue(
-"$name subnet $subnet static-route destination-subnet"
+                                "$name subnet $subnet static-route $static_route destination-subnet"
                         );
                         my $router_for_destination = $vcDHCP->returnValue(
-                            "$name subnet $subnet static-route router");
+                                "$name subnet $subnet static-route $static_route router");
                         if (   $destination_subnet ne ''
                             && $router_for_destination ne '' )
                         {
                             if ( $genout_initial_static_route_count == 0 ) {
-                                $genout_initial .=
-"option rfc3442-static-route code 121 = string;\n";
-                                $genout_initial .=
-"option windows-static-route code 249 = string;\n";
+                                    $genout_initial .= "option rfc3442-static-route code 121 = string;\n";
+                                    #$genout_initial .= "option windows-static-route code 249 = string;\n";
+                                    $genout .= "\t\toption rfc3442-static-route ";
                                 $genout_initial_static_route_count = 1;
                             }
+                                else {
+                                    $genout .= ":";
+                                }
                             my $slash_position =
                               rindex( $destination_subnet, '/' ) + 1;
                             my $destination_subnet_prefix =
@@ -446,10 +452,9 @@
                             my $hex_router = converttohex($router_naip);

                             my $hex_route = $prefix_plus_subnet . $hex_router;
-                            $genout .=
-                              "\t\toption rfc3442-static-route $hex_route;\n";
-                            $genout .=
-                              "\t\toption windows-static-route $hex_route;\n";
+                                $genout .= "$hex_route";
+                                #$genout .=
+                                #  "\t\toption windows-static-route $hex_route;\n";
                         }
                         elsif ($destination_subnet eq ''
                             && $router_for_destination eq '' )
@@ -464,6 +469,10 @@
 EOM
                             $error = 1;
                         }
+                        }
+                        if ( $genout_initial_static_route_count  == 1 ) {
+                            $genout .= ";\n";
+                        }

                         my $ip_forwarding = $vcDHCP->returnValue(
                             "$name subnet $subnet ip-forwarding enable");
@@ -1177,9 +1186,7 @@
     my $prefix_subnet_string = "";

     if ( $prefix == 0 ) {
-
-        # do nothing as this needs to be an empty string
-
+        return "00:";
     }
     elsif ( ( $prefix >= 1 ) && ( $prefix <= 8 ) ) {
         $prefix_subnet_string = $hex_prefix . ":" . substr( $subnet, 0, 3 );

Final note:
RFC3442 recommends providing the default route in option 121.
Sub prefix_and_subnet implementation was broken when prefix=0. If fixed it to return "00:" instead of nothing.

For 1.3, i use this: https://github.com/Elbandi/vyos-1x/commit/f364770fdb5ea8b61d42cb22ca428604d9c6b1df

static-route 192.168.30.0/24 {
    router 192.168.50.254
}
static-route 192.168.20.0/24 {
    router 192.168.50.253
}
erkin set Issue type to Feature (new functionality).Aug 31 2021, 5:53 PM

I'm also hitting this issue in 1.4-rolling-202109160217
This task has been kicking around for a while now. What needs to be done to get the code from @ruliane or @elbandi into the rolling build?

c-po changed the task status from Open to In progress.EditedSep 18 2021, 7:08 PM
c-po claimed this task.
c-po triaged this task as Normal priority.
c-po removed a project: VyOS 1.3 Equuleus.

The following CLI

cpo@LR1.wue3# show service dhcp-server
 shared-network-name LAN {
     subnet 10.0.0.0/24 {
         default-router 10.0.0.1
         dns-server 194.145.150.1
         lease 88
         range 0 {
             start 10.0.0.100
             stop 10.0.0.200
         }
         static-route 194.145.150.0/24 {
             next-hop 1.1.1.1
         }
         static-route 194.145.151.0/24 {
             router 1.1.1.1
         }
     }
 }

produces:

cpo@LR1.wue3# cat /run/dhcp-server/dhcpd.conf
### Autogenerated by dhcp_server.py ###

# For options please consult the following website:
# https://www.isc.org/wp-content/uploads/2017/08/dhcp43options.html
#
# log-facility local7;


ddns-update-style none;
option rfc3442-static-route code 121 = array of integer 8;
option windows-static-route code 249 = array of integer 8;
option wpad-url code 252 = text;


# Shared network configration(s)
shared-network LAN {
    subnet 10.0.0.0 netmask 255.255.255.0 {
        option domain-name-servers 194.145.150.1;
        option rfc3442-static-route 24,194,145,150,1,1,1,1, 24,194,145,151,1,1,1,1, 0,10,0,0,1;
        option windows-static-route 24,194,145,150,1,1,1,1, 24,194,145,151,1,1,1,1;
        option routers 10.0.0.1;
        default-lease-time 88;
        max-lease-time 88;
        range 10.0.0.100 10.0.0.200;
    }
    on commit {
        set shared-networkname = "LAN";
    }
}

It will be part of the next 1.4 rolling release

I'm clearly missing something. I cannot make the configuration as shown by @c-po. If I try to add a 2nd static route, it replaces the first.

Edit: hey - ignore me. I didn't see the bit about adding it to the next rolling release. It's late and I've had wine.