On Sat 17/07/2021 17:12, Florian Obser wrote:
> 
> 
> On 17 July 2021 13:16:59 CEST, Bjorn Ketelaars <b...@openbsd.org> wrote:
> >An inconsistency exists between dhclient(8) and dhcpleased(8) when
> >receiving the Classless Static Routes option: dhcpleased creates a
> >default route, while dhclient does not.
> >
> >If I'm not mistaken, the behaviour of dhclient is correct. From
> >rfc3442:
> >"If the DHCP server returns both a Classless Static Routes option and a
> >Router option, the DHCP client MUST ignore the Router option."
> >
> 
> Correct. But you are fixing it in the wrong place. It doesn't say to ignore a 
> default route, which can be transmitted via classless static routes option 
> (it's 0/0).

That makes sense. New diff...


diff --git sbin/dhcpleased/engine.c sbin/dhcpleased/engine.c
index ad8202c9a33..b3a86e68398 100644
--- sbin/dhcpleased/engine.c
+++ sbin/dhcpleased/engine.c
@@ -613,7 +613,7 @@ parse_dhcp(struct dhcpleased_iface *iface, struct imsg_dhcp 
*dhcp)
        uint32_t                 rebinding_time = 0;
        uint8_t                 *p, dho = DHO_PAD, dho_len;
        uint8_t                  dhcp_message_type = 0;
-       int                      routes_len = 0;
+       int                      routes_len = 0, csr_len = 0, n;
        char                     from[sizeof("xx:xx:xx:xx:xx:xx")];
        char                     to[sizeof("xx:xx:xx:xx:xx:xx")];
        char                     hbuf_src[INET_ADDRSTRLEN];
@@ -979,6 +979,7 @@ parse_dhcp(struct dhcpleased_iface *iface, struct imsg_dhcp 
*dhcp)
                                dho_len -= sizeof(routes[routes_len].gw);
 
                                routes_len++;
+                               csr_len++;
                        }
 
                        if (dho_len != 0) {
@@ -996,6 +997,20 @@ parse_dhcp(struct dhcpleased_iface *iface, struct 
imsg_dhcp *dhcp)
                }
 
        }
+
+       /*
+       * RFC3442 states that if the DHCP server returns both a Classless Static
+       * Routes option and a Router option, the DHCP client MUST ignore the
+       * Router option.
+       */
+       if (csr_len > 0) {
+               log_warnx("%s: ignoring router option", __func__);
+               for (n = 0; n < routes_len - csr_len; n++) {
+                       routes[n] = routes[n + 1];
+                       routes_len--;
+               }
+       }
+
        while (rem != 0) {
                if (*p != DHO_PAD)
                        break;

Reply via email to