Remove configured routes no longer present in lease.
authorflorian <florian@openbsd.org>
Wed, 15 Sep 2021 06:08:01 +0000 (06:08 +0000)
committerflorian <florian@openbsd.org>
Wed, 15 Sep 2021 06:08:01 +0000 (06:08 +0000)
Problem reported by claudio
OK benno

sbin/dhcpleased/engine.c

index 5cf3d3a..3e28c63 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: engine.c,v 1.25 2021/08/12 12:41:08 florian Exp $     */
+/*     $OpenBSD: engine.c,v 1.26 2021/09/15 06:08:01 florian Exp $     */
 
 /*
  * Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@@ -105,6 +105,8 @@ struct dhcpleased_iface {
        char                             file[4 * DHCP_FILE_LEN + 1];
        char                             hostname[4 * 255 + 1];
        char                             domainname[4 * 255 + 1];
+       struct dhcp_route                prev_routes[MAX_DHCP_ROUTES];
+       int                              prev_routes_len;
        struct dhcp_route                routes[MAX_DHCP_ROUTES];
        int                              routes_len;
        struct in_addr                   nameservers[MAX_RDNS_COUNT];
@@ -1247,6 +1249,9 @@ parse_dhcp(struct dhcpleased_iface *iface, struct imsg_dhcp *dhcp)
                } else
 #endif /* SMALL */
                {
+                       iface->prev_routes_len = iface->routes_len;
+                       memcpy(iface->prev_routes, iface->routes,
+                           sizeof(iface->prev_routes));
                        iface->routes_len = routes_len;
                        memcpy(iface->routes, routes, sizeof(iface->routes));
                }
@@ -1526,9 +1531,11 @@ void
 send_configure_interface(struct dhcpleased_iface *iface)
 {
        struct imsg_configure_interface  imsg;
+       int                              i, j, found;
 
        log_lease(iface, 0);
 
+       memset(&imsg, 0, sizeof(imsg));
        imsg.if_index = iface->if_index;
        imsg.rdomain = iface->rdomain;
        imsg.addr.s_addr = iface->requested_ip.s_addr;
@@ -1537,6 +1544,21 @@ send_configure_interface(struct dhcpleased_iface *iface)
        strlcpy(imsg.file, iface->file, sizeof(imsg.file));
        strlcpy(imsg.domainname, iface->domainname, sizeof(imsg.domainname));
        strlcpy(imsg.hostname, iface->hostname, sizeof(imsg.hostname));
+       for (i = 0; i < iface->prev_routes_len; i++) {
+               found = 0;
+               for (j = 0; j < iface->routes_len; j++) {
+                       if (memcmp(&iface->prev_routes[i], &iface->routes[j],
+                           sizeof(struct dhcp_route)) == 0) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found)
+                       imsg.routes[imsg.routes_len++] = iface->prev_routes[i];
+       }
+       if (imsg.routes_len > 0)
+               engine_imsg_compose_main(IMSG_WITHDRAW_ROUTES, 0, &imsg,
+                   sizeof(imsg));
        imsg.routes_len = iface->routes_len;
        memcpy(imsg.routes, iface->routes, sizeof(imsg.routes));
        engine_imsg_compose_main(IMSG_CONFIGURE_INTERFACE, 0, &imsg,