summaryrefslogtreecommitdiff
path: root/sbin/dhclient/dhclient.c
AgeCommit message (Collapse)Author
2022-07-02dhclient(8) has been undergoing replacement with "ifconfig xxx inet auto"Theo de Raadt
for a couple of years, backed by dhcpleased(8), which provides much better dns handling. The next step is to make the dhclient simply execve ifconfig in that way, and provide syslog warnings about deprecated options along the way. This way, we can find the last few dhclient users, and what they are missing. ok florian krw
2021-10-24For open/openat, if the flags parameter does not contain O_CREAT, theTheo de Raadt
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past have passed mode_t (0, 044, 0644, or such), which might lead future people to copy this broken idiom, and perhaps even believe this parameter has some meaning or implication or application. Delete them all. This comes out of a conversation where tb@ noticed that a strange (but intentional) pledge behaviour is to always knock-out high-bits from mode_t on a number of system calls as a safety factor, and his bewilderment that this appeared to be happening against valid modes (at least visually), but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef. ok millert
2021-08-25Don't use log_procname before it is initialized. In particularKenneth R Westerback
set_iff_up() is called from initialize_interface() and was using log_procname instead of ifi->name in its fatal()'s. Diagnosed by tb@ from a recent reddit post by zielonykid1234.
2021-07-27Having 'taken charge' of the interface by eliminating otherKenneth R Westerback
dhclient instances for the interface, check if the IPv4 AUTOCONF flag is set. If it is, go quietly into that good night and let dhcpleased do its thing, comforted by the fact that dhcpleased knows that a new lease has been requested. requested, tested & ok florian@
2021-07-12Change the error reporting pattern throughout the tree when unveilBob Beck
fails to report the path that the failure occured on. Suggested by deraadt@ after some tech discussion. Work done and verified by Ashton Fagg <ashton@fagg.id.au> ok deraadt@ semarie@ claudio@
2021-05-02Shuffle some code to eliminate get_address(), bring interface_state() andKenneth R Westerback
initialize_interface() logic into closer alignment, and try harder to initialize link_state at start up.
2021-04-07"oldlladddr" -> "oldlladdr" in fatal() verbiage.Kenneth R Westerback
2021-04-01Tweak log_debug() verbiage to reduce repetitive infoKenneth R Westerback
(ACK/NAK), add details (DISCOVER/REQUEST) and provide before/after info for SSID/LLADDR/MTU changes.
2021-04-01Also immediately accept the *first* OFFER if it matches the requested address,Kenneth R Westerback
rather than waiting for select_timeout to expire before accepting the same OFFER.
2021-03-31Set 'select_timeout' to 'now' when an OFFER is received for the IP addressKenneth R Westerback
requested in the DISCOVER. i.e. immediately accept the OFFER rather than waiting for select_timeout to expire before accepting the same OFFER. A corner case since select-timeout is 0 by default.
2021-03-31Add two missing checks for strdup() returning NULL.Kenneth R Westerback
2021-03-31Fix some debug output when running in foreground.Kenneth R Westerback
Call tick_msg() at startup so it knows if the link is up. Don't emit 'link timeout expired' messages after the link has been up.
2021-03-28Now that the real time and monotonic time streams don'tKenneth R Westerback
cross flip CLOCK_REALTIME to CLOCK_MONOTONIC. Suggested by cheloha@, millert@, otto@ at various stages in the time_t -> timespec conversion.
2021-03-28Convert remaining timers (lease renew, rebind, expiry) toKenneth R Westerback
timespec values. Translate from the epoch values in leases to timespec values in one place. Final step to allow CLOCK_REALTIME -> CLOCK_MONOTONIC time accounting for the active lease.
2021-03-24More timespec conversions. Less 'seconds' arithmetic.Kenneth R Westerback
2021-03-16Nuke unused time_t variable.Kenneth R Westerback
2021-03-11Use timespec timers to determine when select-timeout and timeout intervalsKenneth R Westerback
are exceeded. Feedback from otto@, cheloha@
2021-03-09Replace time_t startup_time with struct timespec link_timeout.Kenneth R Westerback
Feedback from otto@
2021-03-04Notice when link-timeout expires even if istty(STDERR) hints that dhclient hasKenneth R Westerback
already gone daemon. Sometimes it's just that 2>/dev/null or something has been done. Should fix problem with sysupgrade when an interface (e.g. a wired interface that has no cable plugged in) never comes up. Problem reported and debug info from kettenis@, Jean-Philippe Luigi, Thomas L. and Markus Lude. Thanks!
2021-03-02Eliminate redundant checks for expired leases in ifi->leasedb. SimplyKenneth R Westerback
toss expired leases when writing the list to disk. And write the list to disk before using a lease from it. Just make sure ifi->active isn't tossed.
2021-02-28Move tick_msg(TICK_WAIT) calls after related log_debug()Kenneth R Westerback
calls to avoid losing those debug messages if tick_msg() notices link-timeout has expired and daemonizes dhclient.
2021-02-28Reduce non-debug output further by allowing up to the usual 3 secondKenneth R Westerback
grace period of silence before emitting "<if>: no lease...", even if the link has taken a few secocnds to come up. 'link-timoeut' remains the hard deadline for going daemon.
2021-02-27Stop checking 'epoch' in get_recorded_lease() and just set it asKenneth R Westerback
required in read_lease_db(). It's already set in packet_to_lease() and thus both paths to TAILQ_INSERT(lease_db) ensure there is a non-zero epoch in all lease_db entries.
2021-02-27Disentangle log_debug() output from tick_msg() output.Kenneth R Westerback
Simplifies -v output, and reduces non-'-v' output. Reduce non-'-v' output further by only displaying the first 'link up' event. Restore behaviour specified in dhclient.conf(5) of going daemon after link-timeout seconds, rather than waiting another link-timeout seconds for a lease to be accepted. Lease verbiage problem reported, and fix tested by Mihai Popescu. Thanks! Link verbiage problems reported, fix tested & ok tb@.
2021-02-24Complete deleting ifi->active before calling write_lease_db().Kenneth R Westerback
No functional change but a bit more obvious and shrinks upcoming diff.
2021-02-24No need to get time() twice. Just use the alreadyKenneth R Westerback
obtained cur_time to initialize a missing lease->epoch.
2021-02-24No need to check ifi->active for NULL when looking for duplicate/obsoleteKenneth R Westerback
leases. It can't be NULL, and is unconditionally dereferenced a few lines later anyway.
2021-02-24Fix annoying typo in a comment.Kenneth R Westerback
2021-02-24Remove incomplete/incorrect connection with autoconf, clearing groundKenneth R Westerback
for future attempts at making it more IPv6-like. ok florian@
2021-02-22Switch reboot timing to timespec, the better to handle theKenneth R Westerback
default reboot interval of 1 sec. Gives the DHCP server a fairer shot at replying before the timeout expires. ok millert@
2021-02-21Rename struct client_config fields 'timeout', 'link_timeout' andKenneth R Westerback
'reboot_timeout' to 'offer_interval', 'link_interval' and 'reboot_interval' to be consistant with other '_interval' fields that specify a number of seconds to wait.
2021-02-21No need for state_preboot() to double check timeout beingKenneth R Westerback
tracked in tick_msg() and explicitly calling tick_msg(TICK_SLEEP). One fewer use of each of time(), ifi->startup_time and config->link_timeout. Makes code easier to follow. No intentional functional change.
2021-02-20tick_msg("lease", TICK_SUCCESS) in bind_lease() should *not* beKenneth R Westerback
invoked when log_getverbose() returns 0.
2021-02-19Put duplicated code calculating backoff interval and packet 'secs'Kenneth R Westerback
into new set_interval()/set_secs() functions. send_request() and send_discover() become much easier to understand. No intentional functional change.
2021-02-15Extraneous blank line.Kenneth R Westerback
2021-02-15Rework tick_msg() to make messages displayed during startup moreKenneth R Westerback
reliable and consistant. Eliminate unused time_t parameter since we only tick during the first link_timeout seconds. Replace it with 'action' parameter to clearly indicated what tick_msg() is supposed to do. Fix issuance of '\n' before log_debug() messages. Properly reinitialize static variables. Use more precise 'timespec' timers, hewing to idiom suggested by cheloha@.
2021-02-02dhclient(8): fork_privchld, take_charge, propose_release: poll(2) -> ppoll(2)cheloha
Switch from poll(2) to ppoll(2) in a few more functions. Because we're working with ppoll(2) and clock_gettime(2) it is easier to encode the various timeouts as static const timespecs instead of preprocessor macros. This way we aren't packing timespecs in the middle of the code, which distracts from the (more important) logic of what the code is doing. Part of a larger campaign improve "time stuff" in dhclient(8). Prompted by and discussed with krw@. Based on a diff by krw@. ok krw@
2020-12-10Simplify '-i' handling, failing immediately during command line parsingKenneth R Westerback
when an invalid option name is encountered.
2020-12-06fatal() immediately whem parsing command line option '-c' reveals a non-existantKenneth R Westerback
file. Original diff, tweaks & ok kn@
2020-12-01Extract another couple of chunks from main() into helper functions,Kenneth R Westerback
get_routefd() and set_user().
2020-11-27Shuffle code relating to initializing the physical interface and theKenneth R Westerback
internal structure reflecting the interface into a function that in turn calls simple helper functions to do the different actions involved. Simplifies the overly lengthy main(), correctly starts the state machine with the state of the interface link as DOWN when IFF_UP is 0, tests more initialization actions when '-n' is used.
2020-11-21No need to update ifi->state just before setting quit to TERMINATE.Kenneth R Westerback
Check quit != TERMINATE before trying to open leases file.
2020-11-21No need to update resolv.conf when renewing a lease does not result in anyKenneth R Westerback
configuration changges.
2020-11-21When REBOOT'ing it is necessary to apply_defaults() to the recordedKenneth R Westerback
lease and use the updated values to initialize ifi->expiry and ifi->rebinding. Fixes odd behaviour, bouncing the link in particular, when using dhclient.conf to change the lease renew/rebind/expiry timing. e.g. when debugging wifi interface behaviour.
2020-11-20The default lease rebind time is 7 * (expiry/8), not 8 * (expiry/7).Kenneth R Westerback
2020-11-19Avoid spurious resolv.conf updates whenKenneth R Westerback
1) The RTM_PROPOSAL telling unwind(8) about DNS servers is seen. 2) The interface is in the process of getting a new or renewed lease. 3) The default route is not UP. Edge cases discovered while debugging urtwn(4) link bouncing.
2020-11-18Recognize get_link_ifa() failure (a.k.a. "invalid interface") as a fatal errorKenneth R Westerback
in interface_state() as it is elsewhere. Avoids any possible NULL pointer dereference.
2020-11-18No need to call get_hw_address() from interface_state() since theKenneth R Westerback
appropriate ifa is already known and ifi->rdomain does not need to be updated because a change of rdomain causes a link bounce and thus reinitialization of ifi. One less invocation of getifaddrs() during route message processing.
2020-11-06Remove the -L option. A debugging tool that is no longer required.Kenneth R Westerback
man page and usage() tweaks from jmc@. ok lteo@
2020-07-31Ensure DECLINE messages always contain the address from the OFFER.Kenneth R Westerback
DECLINE messages emitted when required options were missing did not contain the address. Reported via tech@ and fix tested by Dominik Schreilechner.