From 2edea3cb9c69e2f348bc9a4d27a3bfd51e4e1bce Mon Sep 17 00:00:00 2001 From: martijn Date: Fri, 9 Apr 2021 14:46:39 +0000 Subject: [PATCH] When a DHCP server sends an invalid T1 or T2 default back to the default values as specified in RFC2131 section 4.4.5. Allows my Comtrend VI-3223u to work. OK florian@ --- sbin/dhcpleased/engine.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sbin/dhcpleased/engine.c b/sbin/dhcpleased/engine.c index a98dc3d59e7..e301c20939c 100644 --- a/sbin/dhcpleased/engine.c +++ b/sbin/dhcpleased/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.11 2021/03/22 15:34:07 otto Exp $ */ +/* $OpenBSD: engine.c,v 1.12 2021/04/09 14:46:39 martijn Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -972,23 +972,24 @@ parse_dhcp(struct dhcpleased_iface *iface, struct imsg_dhcp *dhcp) } /* RFC 2131 4.4.5 */ + /* Ignore invalid T1/T2 options */ + if (renewal_time >= rebinding_time) { + log_warnx("%s: renewal_time(%u) >= rebinding_time(%u) " + "from %s: using defaults", + __func__, renewal_time, rebinding_time, from); + renewal_time = rebinding_time = 0; + } else if (rebinding_time >= lease_time) { + log_warnx("%s: rebinding_time(%u) >= lease_time(%u) " + "from %s: using defaults", + __func__, rebinding_time, lease_time, from); + renewal_time = rebinding_time = 0; + } + if(renewal_time == 0) renewal_time = lease_time / 2; if (rebinding_time == 0) rebinding_time = lease_time - (lease_time / 8); - if (renewal_time >= rebinding_time) { - log_warnx("%s: renewal_time >= rebinding_time " - "(%u >= %u) from %s", __func__, renewal_time, - rebinding_time, from); - return; - } - if (rebinding_time >= lease_time) { - log_warnx("%s: rebinding_time >= lease_time" - "(%u >= %u) from %s", __func__, rebinding_time, - lease_time, from); - return; - } clock_gettime(CLOCK_MONOTONIC, &iface->request_time); iface->server_identifier.s_addr = server_identifier.s_addr; iface->requested_ip.s_addr = dhcp_hdr->yiaddr.s_addr; -- 2.20.1