Page MenuHomeVyOS Platform

Allow multiple static routes in dhcp-server
Open, Requires assessmentPublic

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)

Event Timeline

afics created this task.Jan 17 2020, 6:21 PM
afics created this object in space S1 VyOS Public.
ruliane added a subscriber: ruliane.EditedJan 27 2020, 2:36 PM

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.

elbandi added a subscriber: elbandi.EditedMar 2 2020, 11:10 PM

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
}
pasik added a subscriber: pasik.Mar 3 2020, 2:20 PM