summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2021-12-13 16:12:11 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2021-12-13 16:12:11 +0000
commitb5a48fb59d56fd5cd0c65a32b200d21132781170 (patch)
treec6355e3f69f222d77ba0a2d3d5e63d28a8d24f64
parent34ba099c1c6e42d6bec28053164e9d272b634df7 (diff)
Only generate a new xid on state change.
When we first request a lease (INIT or REBOOTING state) we run with very short timeouts. If the dhcp server is slow to respond we already have a new xid and ignore the server's response. This goes on until we increase the timeout high enough. If we just stick to an xid this will not happen and we accept "late" responses. RFC 2131 has: Selecting a new 'xid' for each retransmission is an implementation decision. A client may choose to reuse the same 'xid' or select a new 'xid' for each retransmitted message. Problem seen by phessler on german train wifi. OK phessler
-rw-r--r--sbin/dhcpleased/engine.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sbin/dhcpleased/engine.c b/sbin/dhcpleased/engine.c
index 7c7cb458c4f..39eca76924e 100644
--- a/sbin/dhcpleased/engine.c
+++ b/sbin/dhcpleased/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.32 2021/12/13 11:03:23 florian Exp $ */
+/* $OpenBSD: engine.c,v 1.33 2021/12/13 16:12:10 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@@ -616,6 +616,7 @@ engine_update_iface(struct imsg_ifinfo *imsg_ifinfo)
if ((iface = calloc(1, sizeof(*iface))) == NULL)
fatal("calloc");
iface->state = IF_DOWN;
+ iface->xid = arc4random();
iface->timo.tv_usec = arc4random_uniform(1000000);
evtimer_set(&iface->timer, iface_timeout, iface);
iface->if_index = imsg_ifinfo->if_index;
@@ -1309,6 +1310,9 @@ state_transition(struct dhcpleased_iface *iface, enum if_state new_state)
char ifnamebuf[IF_NAMESIZE], *if_name;
iface->state = new_state;
+ if (new_state != old_state)
+ iface->xid = arc4random();
+
switch (new_state) {
case IF_DOWN:
if (iface->requested_ip.s_addr == INADDR_ANY) {
@@ -1468,7 +1472,6 @@ request_dhcp_discover(struct dhcpleased_iface *iface)
memset(&imsg, 0, sizeof(imsg));
- iface->xid = arc4random();
imsg.if_index = iface->if_index;
imsg.xid = iface->xid;
@@ -1495,7 +1498,6 @@ request_dhcp_request(struct dhcpleased_iface *iface)
{
struct imsg_req_dhcp imsg;
- iface->xid = arc4random();
imsg.if_index = iface->if_index;
imsg.xid = iface->xid;