Commit Graph

585893 Commits

Author SHA1 Message Date
HardenedBSD Sync Services
dcb84bf33d
Merge branch 'freebsd/current/main' into hardened/current/master 2024-12-17 12:01:17 -07:00
Ruslan Bukin
4f58451269 riscv: connect eswin to the build.
Connect Eswin IP drivers to the build.

Reviewed by: mhorne
Differential Revision: https://reviews.freebsd.org/D48119
2024-12-17 17:42:09 +00:00
Kyle Evans
92e237e1cc arm64: apple: re-align to recent standards
In the time these have lingered in my tree, we've started to drop the
__FBSDID tags.  Make sure we're using SPDX tags (and the correct one)
as well.

Reported by:	mhorne
2024-12-17 09:38:50 -06:00
Olivier Certner
32c45723fa
atomic(9): Update manpage after constifying atomic loads
MFC after:      5 days
Sponsored by:   The FreeBSD Foundation
2024-12-17 15:48:22 +01:00
Olivier Certner
fa368cc86c
x86 atomics: Remove unused WANT_FUNCTIONS
This macro has not been in use since commit "inline atomics and allow tied
modules to inline locks" (r335873, f4b3640475).

Reviewed by:    markj, kib, emaste, imp
MFC after:      5 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D48061
2024-12-17 15:48:22 +01:00
Olivier Certner
f1ddb6fb8c
MAC/do: Fix a compilation warning about an unused function
grant_supplementary_group_from_flags() had been used in previous
versions of the recent changes, but recently has not been needed
anymore.  It has been kept around just in case deliberately, by analogy
with grant_primary_group_from_flags() (this one still being used).
2024-12-17 15:47:42 +01:00
Kyle Evans
04160e0008 arm64: add a driver for the Apple Interrupt Controller
Some limited support for later multi-die SoC is included, but not at all
tested and not expected to be functional yet.  kevans needs to finish
getting his serial boards constructed, as the beefiest AS machine that
actually has multiple die to support in his fleet is currently a
dedicated serial console.

Reviewed by:	andrew
Co-authored-by:	Andrew Turner <andrew@FreeBSD.org>
Co-authored-by:	Mike Karels <karels@FreeBSD.org>
Differential Revision:	https://reviews.freebsd.org/D48079
2024-12-17 08:24:14 -06:00
Kyle Evans
2eace89d00 arm64: add a driver for the Apple watchdog
Ensure it's disarmed upon attach, provide basic reset functionality.

Register definitions/usage obtained from OpenBSD.

Reviewed by:	ray
Differential Revision:	https://reviews.freebsd.org/D39824
2024-12-17 08:24:14 -06:00
Mark Johnston
fa5f4c10a8 atomic: Update interceptor function signatures after commit 5e9a82e898
Fixes:	5e9a82e898 ("atomics: Constify loads")
2024-12-17 14:07:40 +00:00
HardenedBSD Sync Services
38cba23c0c
Merge branch 'freebsd/current/main' into hardened/current/master 2024-12-17 06:01:16 -07:00
Ruslan Bukin
56816e6875 riscv: Eswin hwreset support added.
Add reset controller driver for Eswin EIC7700.

This one has two reset cells in FDT, which is unusual, so provide a
custom hwreset_map method.

Tested on SiFive Premier P550.

Reviewed by: mhorne, jrtc27
Differential Revision: https://reviews.freebsd.org/D47853
2024-12-17 11:46:10 +00:00
Ruslan Bukin
6766e8ceb5 riscv: Add SiFive CCache driver.
Eswin EIC7700 has non-coherent DMAs but predate the standard RISC-V Zicbom
extension, so we need to use the SiFive CCache controller for non-standard
cache management operations.

Tested on SiFive Premier P550.

Reviewed by: mhorne, jrtc27
Differential Revision: https://reviews.freebsd.org/D47831
2024-12-17 11:28:25 +00:00
Ruslan Bukin
a7bf553d17 riscv vmm: add SSTC extension check.
Check if RISC-V SSTC is available and advertise to the guest.

This is needed for Eswin EIC7700 that does not include SSTC.

As we don't have a mechanism for reporting extension presence
from the kernel to userspace, then use vm_cap_type for now.

Reviewed by: mhorne, markj
Differential Revision: https://reviews.freebsd.org/D48058
2024-12-17 10:35:44 +00:00
Kristof Provost
5d1219378d pf: teach nat64 to handle 0 UDP checksums
For IPv4 it's valid for a UDP checksum to be 0 (i.e. no checksum). This isn't
the case for IPv6, so if we translate a UDP packet from IPv4 to IPv6 we need to
ensure that the checksum is calculated.

Add a test case to verify this. Rework the server jail so it can listen for TCP
and UDP packets at the same time.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:19 +01:00
Kristof Provost
32cac60448 pf tests: test dummynet on nat64 rules
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
706b42cc4b pf: give the correct address family to dummynet after nat64
Pass the new address family rather than the incoming one. In most (i.e. all but
nat64) that's the same, but for nat64 we want the new address family instead.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
08a512019c pf: fix dummynet + route-to for IPv6
Apply the fixes from c6f1116357 and b8ef285f6c to IPv6 as well.

Ensure that when dummynet re-injects it does so in the correct direction, and
uses the correct dummynet pipes.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
7f3d159b9f pf tests: test using an address range inside a table for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
bdb583afa1 pf tests: test address range as nat64 from address
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
e0dcc51ddb pfctl: do not allow af-to tables without round-robin
Tables can only be used as a redirspec (i.e. in pf_map_addr()) in round-robin mode.
Enforce this for af-to tables as well.

Add a test case to verify.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
b0e3fb7e65 pf: fix nat64 round-robin addresses from a table
We do multiple lookups during the nat64 process, some of which will fail due
to address family mismatches. Do not reset the lookup offset so we actually use
different addresses from the table.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
9e039875cb pf tests: verify pool use for nat64
Verify that if we provide a pool of addresses we use the entire pool.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
125e395278 pf tests: test not having an IPv4 address to nat64 to
This isn't expected to work, for obvious reasons, but we also expect to not
panic doing this. Exercise this special case.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
27fca15016 pf tests: validate ToS translation with nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
1df79d8134 pf: preserve TOS with nat64
When translating packets from one address family to another, pass the
TOS/Traffic Class field of the original packet.  Discussed with mikeb@

Obtained from:	OpenBSD, jca <jca@openbsd.org>, fd92f2bb4f
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
e128e988a2 pf tests: check packet reassembly with nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47805
2024-12-17 11:07:16 +01:00
Kristof Provost
7cae58a449 pf: handle fragmentation for nat64
When we reassemble IPv4 packets tag them just like we tag the IPv6 reassembled
packtes. Use this information as the basis for refragmenting the IPv6 packet.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47804
2024-12-17 11:07:16 +01:00
Kristof Provost
6c5c91a039 pf: update pd->tot_len after reassembly
Ensure that the packet length we track in struct pf_pdesc matches the
reassembled packet size.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47803
2024-12-17 11:07:16 +01:00
Kristof Provost
b717c67686 pf tests: verify that we preserve the hop limit/TTL for ICMP errors
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47802
2024-12-17 11:07:16 +01:00
Kristof Provost
c6210cfd58 pf: fix if-bound with nat64
Just as with reply-to rules we don't know what interface we will send this out
of until we create the state. Create new nat64 rules as floating, but bind them
to the appropriate interface on the first pf_route(), when we do know.

Set state policy if-bound for the nat64 tests to validate this.

See also:	6460322a0
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47801
2024-12-17 11:07:16 +01:00
Kristof Provost
d7e9df4fc6 pfctl: print_rule: rename opts -> ropts
no binary change
1/2 from Lawrence Teo <lteo at devio dot us>
ok sthen dlg myself and gcc

Obtained from:	OpenBSD, henning <henning@openbsd.org>, 6992ade79a
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47800
2024-12-17 11:07:15 +01:00
Kristof Provost
f1ddd7f1da pf: add forgotten fixup for icmp6 id's when translating
ok henning

Obtained from:	OpenBSD, mikeb <mikeb@openbsd.org>, 7dde5f4db5
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47799
2024-12-17 11:07:15 +01:00
Kristof Provost
373d6dbf34 pf tests: verify that ICMP destination unreachable makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47798
2024-12-17 11:07:15 +01:00
Kristof Provost
bc66cb3bfa pf tests: verify that ICMP port unreachable makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47797
2024-12-17 11:07:15 +01:00
Kristof Provost
a4e0403295 pf tests: verify that TCP RST makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47796
2024-12-17 11:07:15 +01:00
Kristof Provost
86bcaedd35 pfctl: basic nat64 parser test
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47795
2024-12-17 11:07:14 +01:00
Kristof Provost
a43589dcbf pf tests: add an SCTP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47794
2024-12-17 11:07:14 +01:00
Kristof Provost
7e309356b0 pf tests: add a UDP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47793
2024-12-17 11:07:14 +01:00
Kristof Provost
22c634905b pf tests: add a TCP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47792
2024-12-17 11:07:14 +01:00
Kristof Provost
0656a68056 pf tests: basic nat64 test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47791
2024-12-17 11:07:14 +01:00
Kristof Provost
eaf484fdb7 pf.conf.5: document af-to (aka nat64)
the patch was started by todd about a year ago and have been
finally finished by phessler and myself today; discussed with
and tweaks from jmc, ok sthen, henning

Obtained from:	OpenBSD, mikeb <mikeb@openbsd.org>, 4d5e14dff3
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:14 +01:00
Kristof Provost
aa69fdf154 pfctl: change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@

Obtained from:	OpenBSD, claudio <claudio@openbsd.org>, 0cde32ce3f
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47790
2024-12-17 11:07:13 +01:00
Kristof Provost
b8e5384438 pf: drop packets if they fail nat64 translation
If we can't map ICMPv4 onto ICMPv6 or vice versa drop the packet rather than
continuing with an untranslated packet.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:13 +01:00
Kristof Provost
d89a5d853e pf: support nat64 for SCTP
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47789
2024-12-17 11:07:13 +01:00
Kristof Provost
ea9113be3f pf: extra route lookup in pf_route(6)()
In the NAT64 case we use pf_route(6)() to emit the translated packet. This
requires a new route lookup, so perform this, but only in the NAT64/NAT46 case.
Update the destination sockaddr to send packets to the gateway if appropriate.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47788
2024-12-17 11:07:13 +01:00
Kristof Provost
ebe11b4698 pf: fix state export in the face of NAT64
Now that we can NAT64 we can have states where the wire and stack address
families (and protocol) are different.  Update the state export code to account
for this.

We keep exporting address family and protocol outside of the key, for backwards
compatibility. This'll return misleading information to userspace in the NAT64
case, but it's assumed that userspace will either understand NAT64 (and thus
look for them in the correct place), or not configure it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47787
2024-12-17 11:07:13 +01:00
Kristof Provost
fcdb520c1b pf: nat64
Since the IPv6 madness is not enough introduce NAT64 -- which is actually
"af-to" a generic IP version translator for pf(4).
Not everything perfect yet but lets fix these things in the tree.
Insane amount of work done by sperreault@, mikeb@ and reyk@.
Looked over by mcbride@ henning@ and myself at eurobsdcon.
OK mcbride@ and general put it in from deraadt@

Obtained from:	OpenBSD, claudio <claudio@openbsd.org>, 97326e01c9
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47786
2024-12-17 11:07:12 +01:00
Kristof Provost
e4e0f49742 in: add in_mask2len()
Similar to the existing in6_mask2len() function, but for IPv4. This will be used
by pf's nat64 code.

Obtained from:	OpenBSD
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47785
2024-12-17 11:07:12 +01:00
Kristof Provost
2d7e68d5cd pf: add post-NAT src/dst address/port to pf_pdesc
stuff nsaddr/ndaddr/nsport/ndport (addrs/ports after NAT, used a lot while
walking the ruleset and up until state is fully set up) into pf_pdesc instead
of passing around those 4 seperately all the time, also shrinks the argument
count for a few functions that have/partialy had an insane count of arguments.
kinda preparational since we'll need them elsewhere too, soon
ok ryan jsing

Obtained from:	OpenBSD, henning <henning@openbsd.org>, ccf63ac6cb
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47784
2024-12-17 11:07:12 +01:00
Kristof Provost
e11dacbf84 pf: partially import OpenBSD's NAT rewrite
We won't follow this fully, because it involves breaking syntax changes
(removing nat/rdr rules and moving this functionality into regular rules) as
well as behaviour changes because NAT is now done after the rules evaluation,
rather than before it.

We import some related changes anyway, because it paves the way for nat64
support.
This change introduces a new pf_kpool in struct pf_krule, for nat. It is not yet
used (but will be for nat64) and renames the existing 'rpool' to 'rdr'.

Obtained from:	OpenBSD, henning <henning@openbsd.org>, 0ef3d4febe
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47783
2024-12-17 11:07:12 +01:00