Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/busybox/udhcpc.script: support RFC3442 static routes
@ 2020-09-21 16:20 Peter Korsgaard
  2020-09-21 20:43 ` Thomas Petazzoni
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Korsgaard @ 2020-09-21 16:20 UTC (permalink / raw)
  To: buildroot

RFC3442 specifies a DHCP extension to provide the client with a list of
static routes to use.  This is already handled by udhcpc and exposed as the
"staticroutes" environment variable, but currently not handled by the action
script.

Extend the script to do so.  The RFC specifies that if this option is
provided by the server then the normal "routes" (3) option should be
ignored, so ensure that is done.

As we may now have more than just a default route on the interface, extend
the route cleanup logic to handle all routes for the interface (except for
the implied local 0.0.0.0 one).

Notice that this option is only sent by servers if explicitly requested by
the client, E.G.  using the -O staticroutes option to udhcpc.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
 package/busybox/udhcpc.script | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
index 0196351cd5..ec4d9f6185 100755
--- a/package/busybox/udhcpc.script
+++ b/package/busybox/udhcpc.script
@@ -61,7 +61,23 @@ case "$1" in
 			wait_for_ipv6_default_route
 		fi
 
-		if [ -n "$router" ] ; then
+		# RFC3442: If the DHCP server returns both a Classless
+		# Static Routes option and a Router option, the DHCP
+		# client MUST ignore the Router option.
+		if [ -n "$staticroutes" ]; then
+			echo "deleting routers"
+			route -n | while read dest gw mask flags metric ref use iface; do
+				[ "$iface" != "$interface" -o "$gw" = "0.0.0.0" ] || \
+					route del -net "$dest" netmask "$mask" gw "$gw" dev "$interface"
+			done
+
+			# format: dest1/mask gw1 ... destn/mask gwn
+			set -- $staticroutes
+			while [ -n "$1" -a -n "$2" ]; do
+				route add -net "$1" gw "$2" dev "$interface"
+				shift 2
+			done
+		elif [ -n "$router" ] ; then
 			echo "deleting routers"
 			while route del default gw 0.0.0.0 dev $interface 2> /dev/null; do
 				:
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Buildroot] [PATCH] package/busybox/udhcpc.script: support RFC3442 static routes
  2020-09-21 16:20 [Buildroot] [PATCH] package/busybox/udhcpc.script: support RFC3442 static routes Peter Korsgaard
@ 2020-09-21 20:43 ` Thomas Petazzoni
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni @ 2020-09-21 20:43 UTC (permalink / raw)
  To: buildroot

On Mon, 21 Sep 2020 18:20:02 +0200
Peter Korsgaard <peter@korsgaard.com> wrote:

> RFC3442 specifies a DHCP extension to provide the client with a list of
> static routes to use.  This is already handled by udhcpc and exposed as the
> "staticroutes" environment variable, but currently not handled by the action
> script.
> 
> Extend the script to do so.  The RFC specifies that if this option is
> provided by the server then the normal "routes" (3) option should be
> ignored, so ensure that is done.
> 
> As we may now have more than just a default route on the interface, extend
> the route cleanup logic to handle all routes for the interface (except for
> the implied local 0.0.0.0 one).
> 
> Notice that this option is only sent by servers if explicitly requested by
> the client, E.G.  using the -O staticroutes option to udhcpc.
> 
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
> ---
>  package/busybox/udhcpc.script | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)

Applied to master, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-21 20:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-21 16:20 [Buildroot] [PATCH] package/busybox/udhcpc.script: support RFC3442 static routes Peter Korsgaard
2020-09-21 20:43 ` Thomas Petazzoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox