Commit Graph

5577 Commits

Author SHA1 Message Date
Petr Menšík
727c78f503
Move dhcp(v4) packet size check earlier (#295)
dhcp_handlebootp handled zero sized packets correctly, but
dhcp_redirect_dhcp did not have such protection. Move size check before
both of them. Size when called from dhcp_packet is checked by
is_packet_udp_bootp call. Only dhcp_recvmsg needs earlier checking to be
added.

Fixes #283
2024-02-16 16:15:35 +00:00
Roy Marples
8ab7ca1eb4 DHCP: DECLINE address on ARP defend failure
Also, drop the lease.
This should get us a new address from the DHCP server when we
re-enter DISCOVER to avoid looping on the same address and fail
again.
2023-12-24 12:07:25 +00:00
pradeep-brightsign
e65e82a58d
dhcpcd: Add support for arp persist defence (#273)
RFC 5227 recommends 3 ways to deal with address conflict detection.
a) Stop everything.
b) Defend and then stop on fail - this is what dhcpcd currently does.
c) Notify and carry on.

The current change implements the option c. A new option arp_persistdefence
has been added and when this is enabled, the a defence is attempted upon a
conflict and when that fails, an error is logged on every other conflict
within the DEFEND_INTERVAL and the current IP address is retained.

Fixes #272
2023-12-21 10:26:09 +00:00
Roy Marples
1c8ae59836 Release dhcpcd-10.0.6 2023-12-18 15:39:51 +00:00
Roy Marples
01de6f23d3 DHCP6: For Prefix Delegation, the - interface means no assignment
- is an invalid interface name.
So we take this to mean don't assign the Delegated Prefix to
any interfaces.
The reject route for the Delegated Prefix is still installed.

Fixes #270
2023-12-18 12:22:13 +00:00
Roy Marples
c7a142affe DHCP6: Improve logging when changing IA type
Changing from PD to IA or IA to PD can result in a diagnostic
when there is no address to confirm AND we haven't loaded
a lease.
This improves the check and no more Success errors should
be reported.
2023-12-18 12:15:10 +00:00
Roy Marples
411e6539fd Fully configure an interface when being activated.
We need the full configuration - for example dhcpcd.conf
might have environment options for the hooks for the interface
being activated.

Because we now guard against starting protocols with IF_ACTIVE_USER
this is safe.

Fixes #257.
2023-12-14 22:56:00 +00:00
Roy Marples
0a0bbfe74e Fix year 2023-12-12 07:13:29 +00:00
Roy Marples
e337bd7ce4 Document that limiting address protocol can affect signalling dhcpcd
Fixes #264
2023-12-10 08:27:30 +00:00
Roy Marples
6788608eb0 Fix an unused var warning for capsicum for prior 2023-11-13 16:05:04 +00:00
Roy Marples
8d12632c67 Fix privsep builds for prior. 2023-11-13 15:54:50 +00:00
Roy Marples
ea53344a24 dhcpcd: Remove stdio callback and detach on daemonise
For some reason, the stdio callback is extremely flaky on
*some* Linux based distributions making it very hard to debug some
things.
Removing it is fine because we now enforce that we have file descriptors
for stdin, stdout and stdrr on launch and dup them to /dev/null on daemonise.

It's also interesting to see behavioural differences between
some socketpair implementations that emit a HANGUP and some don't.

As such, we now close the fork socket on daemonise once more AND
in the fork_cb depending on if we hangup or read zero first.

Fixes #262
2023-11-13 10:29:58 +00:00
Roy Marples
3b4c71859c control: Abort control recv path on hangup
This fixes a crash when we try and re-use it in another function.
2023-11-13 10:24:15 +00:00
Roy Marples
21d020b00e dhcpcd: Detach from launcher before stopping root process
This fixes non privsep builds where the launcher reports dhcpcd
hungup. Unsure why this happens, but it should not be a problem.

While here, shutdown has no effect on non STREAM sockets and
remove the silly error logging in fork_cb that we read an
error. We already printed the error so this makes no sense.

Hopefully fixes #262.
2023-11-12 12:16:53 +00:00
Roy Marples
584b52db33 control: Fix hangup for non privsep builds
Fix related to #262.
2023-11-12 11:30:26 +00:00
Roy Marples
6baf4df467 Release dhcpcd-10.0.5 2023-11-10 14:25:12 +00:00
Roy Marples
3941274074 privsep: Note that unveil(2) is not needed
As we are in a chroot.
https://www.mail-archive.com/misc@openbsd.org/msg171664.html
2023-11-10 12:02:19 +00:00
Roy Marples
4bb0c8ff02 privsep: Allow dup3 on Linux
It seems some libc will really call dup3 rather than dup2.
Another fix for #260.
2023-11-10 11:04:22 +00:00
Roy Marples
1064814667 dev: Don't fail to start if we cannot open the dev plugin path
We accidently returned stdin fd in this case - return -1 instead.
2023-11-10 11:04:22 +00:00
Roy Marples
c32c88b642 dhcpcd: Close fork_fd on hangup
Closing it early results in zero length reads in some situations.
Logging that we forked via the launcher process also make more sense
and allows us to use log* functions.

While here, handle error condtions better by forcing a return
rather than handling an invalid state.

Fixes #260.
2023-11-10 11:04:22 +00:00
Roy Marples
2913df520a configure: guard config.h with #ifdef CONFIG_H
Rename CONFIG_H guard in defs.h to DEFS_H
This avoids a redeclaration issue on DragonFly.
2023-11-08 10:10:35 +00:00
Roy Marples
2d07224f97 IPv4LL: Don't start if already started
It's just pointless noise.
A follow-on fix for #255.
2023-10-23 15:25:13 +00:00
Roy Marples
d408e74bdc DHCP: re-enter DISCOVER phase if server doesn't reply to our REQUEST
Use the reboot timeout as per the initial DISCOVER timeout.

Fixes #255
2023-10-23 15:24:00 +00:00
Roy Marples
e8b6541979 Expose memset_s on FreeBSD 2023-10-23 15:39:20 +01:00
Roy Marples
47f4bf4188 Fix tests or #252. 2023-10-23 15:31:02 +01:00
Roy Marples
65190fa017 compat: test for memset_explicit, explicit_bzero and memset_s
These won't be optimised away by the compiler and our arc4random
compat function should use them *if* available.
If none are then a warning will be emitted to say it's potentially insecure.

Hopefully only uclibc users will see this message.

Fixes #252.
2023-10-23 15:28:40 +01:00
Roy Marples
beace2c04c Improve comment about capturing script output. 2023-10-20 06:53:20 +00:00
Roy Marples
3cb2426565 Release dhcpcd-10.0.4 2023-10-19 12:15:31 +01:00
Roy Marples
9c20aab025 dhcpcd: Improve script status handling 2023-10-19 12:06:33 +01:00
Roy Marples
fd2e62e72d privsep: Allow dup2 with SECCOMP 2023-10-19 11:34:30 +01:00
Roy Marples
ac4a70dc89 privsep: Notify processes when dhcpcd has daemonised
This allows us to dup stdout and stderr onto stdin which is
guaranteed to be dupped to /dev/null.
This in turn avoids SIGPIPE when the privileged proccess launches
the script and it wants to write to stdout/stderr or stupidly
read from stdin.
2023-10-19 11:14:57 +01:00
Fabrice Fontaine
57070736a5
compat/arc4random.c: use memset instead of explicit_bzero (#252)
Use memset instead of explicit_bzero to avoid the following build
failure with uclibc-ng since version 10.0.3 and
837d09e34c:

/home/fabrice/buildroot/output/host/lib/gcc/arm-buildroot-linux-uclibcgnueabi/12.3.0/../../../../arm-buildroot-linux-uclibcgnueabi/bin/ld: ../compat/arc4random.o: in function `_rs_stir_if_needed':
arc4random.c:(.text+0x8cc): undefined reference to `explicit_bzero'

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2023-10-16 18:03:41 +01:00
Oleg Lyovin
52f1b730a8
privsep: allow __NR_clock_gettime32 syscall (#254)
musl libc doesn't have __NR_clock_gettime definition,
but has __NR_clock_gettime32. clock_gettime implementation
fallbacks to 32-bit version if 64-bit is not supported by the kernel.

Signed-off-by: Oleg Lyovin <ovlevin@sberdevices.ru>
2023-10-16 17:59:00 +01:00
Oleg Lyovin
6ada94b856
privsep: allow __NR_mmap2 syscall (#253)
The issue occured while compiled by musl toolchain:

    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = ?
    +++ killed by SIGSYS +++

This patchs allows seccomp to make __NR_mmap2 syscall.

Signed-off-by: Oleg Lyovin <ovlevin@sberdevices.ru>
2023-10-12 17:47:05 +01:00
Roy Marples
b976d55ebd dhcpcd: freopen of stdin/stdout may change the fd
So use dup2 instead.
2023-10-09 14:03:37 +01:00
Roy Marples
617a3ae207 privsep: Log script exit status. 2023-10-09 12:20:08 +01:00
Roy Marples
45fb8fd8dd Release dhcpcd-10.0.3 2023-10-06 09:27:53 +01:00
Roy Marples
d287090496 DHCP6: Set all requested addrs as not stale when starting discovery
Hopefully fixes #249.
2023-10-04 17:38:08 +01:00
Roy Marples
6b22ccb2ae doc: mention using --with-openssl
Fixes #225
2023-10-04 13:47:57 +01:00
Roy Marples
3c36bfc83d IPv6: Be explicit that lifetime zero means no longer a default router
Fixes #244
2023-10-04 13:38:44 +01:00
Roy Marples
500cd81362 options: introduce the uri option as opposed to a string
Currently we don't attempt to validate a uri given, aside from
not allowing any space characters within.

If the option is `array uri` then the first two bytes are the
length of the uri in network order and the rest is a uri element.
The uri's are space separated for the variable because space is not
allowed within the uri.

This allows us to implement RFC 8572, Secure Zero Touch Provisioning.
2023-10-04 13:08:20 +01:00
Roy Marples
0b9d882529 options: andsf6 is DHCPv6, not DHCP 2023-10-02 11:01:39 +01:00
Roy Marples
dc96a61d14 Cast a compile warning away 2023-10-02 10:54:36 +01:00
Tobias Heider
cd34035851
compat: use OpenSSL RAND_priv_bytes() for entropy (#248)
* compat: use OpenSSL RAND_priv_bytes() for entropy

Use OpenSSL random number generator to seed arc4random() if available,
if it fails fall back to /dev/urandom.

* tests: link eloop-bench against LDADD lib

arc4random might depend on libcrypto so we need to link it.
2023-09-29 08:57:41 +01:00
Christian Tomahogh
f2bc729e55
Send correct amount of used buffer for prefix exclude option (#250)
The payload of the prefix exclude option was correctly created
but the amount of bytes to send in the DHCPv6 request was
always set to 0 which resulted in an invalid prefix exclude option

This patch fixes this behavior by calculating the correct amount
of bytes to send.
2023-09-29 00:04:37 +01:00
Roy Marples
dcaf729bca Guard against handling many SIGTERM/SIGINT.
Privsep has a mini-eloop for reading data from other processes.
This mini-eloop processes signals as well so we can reap children.
During teardown we don't want to process SIGTERM or SIGINT again,
as that could trigger memory issues.

Hopefully fixes #247.
2023-09-25 10:34:12 +01:00
Petr Gotthard
8ac0147364
Use a local variable instead of the optind (#86)
The optind get overwritten by reload_config(), so the reconf_reboot()
used a wrong argument count.

Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
2023-09-25 10:00:27 +01:00
Tobias Heider
8e316164a8
Support libcrypto for hmac and sha256 (#223)
* compat: Add OpenSSL libcrypto compatibility layer

Detect libcrypto in configure script.  Only fall back
to using libcrypto when /usr libs are allowed and no
other compatible implementation is available or when
--with-openssl is passed explicitly.
Make sure libcrypto and libmd are never linked at the
same time.

Add OpenSSL based SHA256 and HMAC compat shims in
compat/crypt_openssl. Depeding on version and build flags,
libcrypto ships with a compatible SHA256 API in
"openssl/sha.h".  OpenSSL 3 has deprecated the SHA API,
so if it is not detected we fall back to an EVP_DIGEST
based version.
Because the API might still be in use in OpenSSL internally,
the compatibility wrappers have a dhcpcd_ prefix to avoid
symbol conflicts.

* Add sha256 tests based on the existing hmac-md5 tests.
2023-09-25 09:49:00 +01:00
Ido Rosen
e0923934fc
Fix some grammar in README.md 2023-09-11 22:16:26 -07:00
Ido Rosen
4a3be174e4 Clarify persistent wording to address confusion.
When persistent is not specified, dhcpcd de-configures the interface at exit.
However, the default dhcpcd.conf example provided enables the option.
See https://github.com/NetworkConfiguration/dhcpcd/discussions/140
2023-09-08 23:41:45 -07:00