summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2021-09-15 06:08:02 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2021-09-15 06:08:02 +0000
commit8851d5e921f6500d78896d4e4743ad7faaa86028 (patch)
treef6ac02dc7a435b3164a317f6d7072f4ca70f7e66
parentaefa8caa65fe053fd93787aa199c63b2fcf03646 (diff)
Remove configured routes no longer present in lease.
Problem reported by claudio OK benno
-rw-r--r--sbin/dhcpleased/engine.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/sbin/dhcpleased/engine.c b/sbin/dhcpleased/engine.c
index 5cf3d3a4af4..3e28c638d44 100644
--- a/sbin/dhcpleased/engine.c
+++ b/sbin/dhcpleased/engine.c
@@ -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,