From nobody Tue Aug 20 05:02:11 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wny4g5xmcz5VFpY; Tue, 20 Aug 2024 05:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wny4g43tzz4QjR; Tue, 20 Aug 2024 05:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724130131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=77PHJQK8Sgy6k/Qs9BOD3iF8y/gj68oIlGnX/cpSeC8=; b=XBvDMyhoxStF43OilkGRCdAEftcLs84/hK+RXSiVr5nyYV/RrABBOoE+kT3mMzF1CKcIo0 nxvcYmldhkjmTmUPK6+zgFXdAJUxT1Y3PeJsgS4DMrRAWBAo2w9pO1Fszp0z7mHovYS8Jh cTFNj4JldPA2bwpwIBF5bEgq+xrovltixR/+NgDgmLy0tWyI1xkQYisW3c1/4fYQGIwInY Jo4uKM7rRNnAA8xUIfnxx5Tc7fGjX1UhgEWKyV12GStgOpoE/CE1J60u1MYASQAFxEu9Vs YxDjpoU27NXnwUmlKcKosF4yNbvWEtR/0YqXurR2mcgo5WAWhHbrIFjwM17eQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724130131; a=rsa-sha256; cv=none; b=WbqJ2tBPEm8RlhYrJVn9jCVIgOfkTOSqWmqe7rBen02IgmfozNz4qvbNBvIp0b1C39BGm8 Grclk59pz70wgtDmeIPiMpmwKRxrxsUJ1fV7JOvN+KOuJOUdL9xg4CMgBe9x7mCkwNi7qu kcxZPqVH85jUrsw8mqohzMA9XL+CXtu38ViNy0xnQxgxPXKv5eao9oc/mqx/qzRGvh/x+l kHxxztk9moIWFS57a/KiXO865CxALTP0M9SmL/WZ812sHAPs8vhOx6L8LkBWmPZCFmnbfZ ccKiB2hRC7l27MlKDD+69+IHkr/1tiLlehVt2Hn9GDUhBBOb3hSQO0pmdrLLvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724130131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=77PHJQK8Sgy6k/Qs9BOD3iF8y/gj68oIlGnX/cpSeC8=; b=ivFF3mJR8vhROpsK8tAe+cGwPN6D+70iNFMIaCDT21sCjPH/np5/chOub1QHg0PsB2xhSe qRctytY1EDPxbwmMHvjjnALf1+6Ngk2Go7cox85jyXgRGvPV02CvgS8bkvnWrGG2V7v3Ao MguqpyDH7pevKOE2IJCr5U7CpOGi4l1R9+1zrjx93sxCl97d6VwczbgrXRHtqXygQ5OG2V Y/XvOyZnKuwroVG9M5quTyOyV49NZf596Mh/MBE6qavqMcvkC/HoxPxufEYsmL4r+Jk4Nj NN0a5Opv9g6HzOTQBSCDbWtD+5kNBpLpfDH1tQ7hJSKx9E1jJVIcxFn2irHuzg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wny4g2YWszn7g; Tue, 20 Aug 2024 05:02:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47K52BPq072105; Tue, 20 Aug 2024 05:02:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K52B4M072102; Tue, 20 Aug 2024 05:02:11 GMT (envelope-from git) Date: Tue, 20 Aug 2024 05:02:11 GMT Message-Id: <202408200502.47K52B4M072102@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 850e82126771 - stable/13 - dhclient: Timeouts for entering state_selecting List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 850e8212677157fe7a086e1b7f7b2f33fba668ae Auto-Submitted: auto-generated The branch stable/13 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=850e8212677157fe7a086e1b7f7b2f33fba668ae commit 850e8212677157fe7a086e1b7f7b2f33fba668ae Author: Isaac Cilia Attard AuthorDate: 2024-07-08 06:11:08 +0000 Commit: Colin Percival CommitDate: 2024-08-20 04:58:35 +0000 dhclient: Timeouts for entering state_selecting Use the new add_timeout_timespec() API to handle timeouts for state_selecting within dhclient.c. No functional change intended. Sponsored by: Google LLC (GSoC 2024) Signed-off-by: Isaac Cilia Attard MFC after: 10 days Reviwed by: cperciva, brooks, Tom Hukins, Alexander Ziaee Pull Request: https://github.com/freebsd/freebsd-src/pull/1368 (cherry picked from commit 76e0ffd9f8fd09f8790a4d96581782225d9019ea) --- sbin/dhclient/dhclient.c | 38 ++++++++++++++++++++++++++++---------- sbin/dhclient/dhcpd.h | 1 + sbin/dhclient/dispatch.c | 3 ++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 1bdd0eb68f8f..1a39ab1517c2 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -91,6 +91,7 @@ cap_channel_t *capsyslog; time_t cur_time; +struct timespec time_now; static time_t default_lease_time = 43200; /* 12 hours... */ const char *path_dhclient_conf = _PATH_DHCLIENT_CONF; @@ -120,6 +121,8 @@ struct pidfh *pidfile; */ #define TIME_MAX ((((time_t) 1 << (sizeof(time_t) * CHAR_BIT - 2)) - 1) * 2 + 1) +static struct timespec arp_timeout = { .tv_sec = 2, .tv_nsec = 0 }; +static const struct timespec zero_timespec = { .tv_sec = 0, .tv_nsec = 0 }; int log_priority; static int no_daemon; static int unknown_ok = 1; @@ -1022,7 +1025,11 @@ dhcpoffer(struct packet *packet) struct interface_info *ip = packet->interface; struct client_lease *lease, *lp; int i; - int arp_timeout_needed, stop_selecting; + struct timespec arp_timeout_needed; + struct timespec stop_selecting = { .tv_sec = 0, .tv_nsec = 0 }; + time_now.tv_sec = cur_time; + time_now.tv_nsec = 0; + const char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ? "DHCPOFFER" : "BOOTREPLY"; @@ -1079,12 +1086,13 @@ dhcpoffer(struct packet *packet) /* If the script can't send an ARP request without waiting, we'll be waiting when we do the ARPCHECK, so don't wait now. */ if (script_go()) - arp_timeout_needed = 0; + arp_timeout_needed = zero_timespec; + else - arp_timeout_needed = 2; + arp_timeout_needed = arp_timeout; /* Figure out when we're supposed to stop selecting. */ - stop_selecting = + stop_selecting.tv_sec = ip->client->first_sending + ip->client->config->select_interval; /* If this is the lease we asked for, put it at the head of the @@ -1100,9 +1108,13 @@ dhcpoffer(struct packet *packet) offer would take us past the selection timeout, then don't extend the timeout - just hope for the best. */ + + struct timespec interm_struct; + timespecadd(&time_now, &arp_timeout_needed, &interm_struct); + if (ip->client->offered_leases && - (cur_time + arp_timeout_needed) > stop_selecting) - arp_timeout_needed = 0; + timespeccmp(&interm_struct, &stop_selecting, >)) + arp_timeout_needed = zero_timespec; /* Put the lease at the end of the list. */ lease->next = NULL; @@ -1119,16 +1131,22 @@ dhcpoffer(struct packet *packet) /* If we're supposed to stop selecting before we've had time to wait for the ARPREPLY, add some delay to wait for the ARPREPLY. */ - if (stop_selecting - cur_time < arp_timeout_needed) - stop_selecting = cur_time + arp_timeout_needed; + struct timespec time_left; + timespecsub(&stop_selecting, &time_now, &time_left); + + if (timespeccmp(&time_left, &arp_timeout_needed, <)) { + timespecadd(&time_now, &arp_timeout_needed, &stop_selecting); + } /* If the selecting interval has expired, go immediately to state_selecting(). Otherwise, time out into state_selecting at the select interval. */ - if (stop_selecting <= 0) + + + if (timespeccmp(&stop_selecting, &zero_timespec, <=)) state_selecting(ip); else { - add_timeout(stop_selecting, state_selecting, ip); + add_timeout_timespec(stop_selecting, state_selecting, ip); cancel_timeout(send_discover, ip); } } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 8e4c1344843a..abe652c06fec 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -361,6 +361,7 @@ char *piaddr(struct iaddr); extern cap_channel_t *capsyslog; extern const char *path_dhclient_conf; extern char *path_dhclient_db; +extern struct timespec time_now; extern time_t cur_time; extern int log_priority; extern int log_perror; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index c02cb2c52796..e6b06d8616c8 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -167,7 +167,8 @@ dispatch(void) struct protocol *l; struct pollfd *fds; struct timespec howlong; - struct timespec time_now = { .tv_sec = cur_time, .tv_nsec = 0 }; + time_now.tv_sec = cur_time; + time_now.tv_nsec = 0; for (l = protocols; l; l = l->next) nfds++;