dragonfly.git
2 months agowg: Port #8: remove unsupported jail code
Aaron LI [Mon, 25 Sep 2023 08:59:32 +0000 (25 16:59 +0800)]
wg: Port #8: remove unsupported jail code

2 months agowg: Port #7: implement necessary counter(9) bits
Aaron LI [Fri, 22 Sep 2023 07:55:40 +0000 (22 15:55 +0800)]
wg: Port #7: implement necessary counter(9) bits

2 months agowg: Port #6: replace CK_* and *_SAFE list/queue macros
Aaron LI [Fri, 22 Sep 2023 06:22:03 +0000 (22 14:22 +0800)]
wg: Port #6: replace CK_* and *_SAFE list/queue macros

2 months agowg: Port #5: replace sx(9) with lockmgr(9)
Aaron LI [Fri, 22 Sep 2023 03:24:56 +0000 (22 11:24 +0800)]
wg: Port #5: replace sx(9) with lockmgr(9)

2 months agowg: Port #4: replace malloc/mallocarray/free/zfree() functions
Aaron LI [Thu, 21 Sep 2023 13:56:50 +0000 (21 21:56 +0800)]
wg: Port #4: replace malloc/mallocarray/free/zfree() functions

2 months agowg: Port #3: replace uma(9) with objcache(9)
Aaron LI [Thu, 21 Sep 2023 13:31:41 +0000 (21 21:31 +0800)]
wg: Port #3: replace uma(9) with objcache(9)

Note that the ocflags of objcache_get() is only used when a new object
needs to be allocated using the backend allocator, so we cannot depend
on flags such as M_ZERO.  As a result, we manually bzero() the allocated
object before using it.

2 months agowg: Port #2: replace mutex with lockmgr(9)
Aaron LI [Thu, 21 Sep 2023 06:54:32 +0000 (21 14:54 +0800)]
wg: Port #2: replace mutex with lockmgr(9)

Although we also have the mutex(9) API, but our lockmgr(9) API is more
versatile and heavily optimized.  So replace mutex with lockmgr as well.

2 months agowg: Port #1: replace rwlock with lockmgr(9)
Aaron LI [Thu, 21 Sep 2023 05:15:39 +0000 (21 13:15 +0800)]
wg: Port #1: replace rwlock with lockmgr(9)

2 months agowg: Import from FreeBSD without any modifications
Aaron LI [Wed, 20 Sep 2023 13:13:06 +0000 (20 21:13 +0800)]
wg: Import from FreeBSD without any modifications

From FreeBSD main branch as of 2023-09-19.

Kernel module/driver:
- sys/dev/wg/compat.h
- sys/dev/wg/crypto.h
- sys/dev/wg/if_wg.c
- sys/dev/wg/if_wg.h
- sys/dev/wg/version.h
- sys/dev/wg/wg_cookie.c
- sys/dev/wg/wg_cookie.h
- sys/dev/wg/wg_crypto.c
- sys/dev/wg/wg_noise.c
- sys/dev/wg/wg_noise.h

Module makefile:
- sys/modules/if_wg/Makefile

Man page:
- share/man/man4/wg.4

2 months agoif_gre: Minor whitespace cleanups
Aaron LI [Thu, 25 Jan 2024 14:15:12 +0000 (25 22:15 +0800)]
if_gre: Minor whitespace cleanups

2 months agolo.4: Describe RXCSUM/TXCSUM support, other minor updates
Aaron LI [Thu, 8 Feb 2024 03:44:45 +0000 (8 11:44 +0800)]
lo.4: Describe RXCSUM/TXCSUM support, other minor updates

The RXCSUM/TXCSUM support was added in commit 72662a by sephe.  Update
the man page to describe it.  Meanwhile, add some other minor updates
from FreeBSD.

Obtained-from: FreeBSD

2 months agocrypto: Fix the KKASSERT() in blake2s_init_key()
Aaron LI [Wed, 7 Feb 2024 07:10:44 +0000 (7 15:10 +0800)]
crypto: Fix the KKASSERT() in blake2s_init_key()

2 months agonet/if: Add IFT_WIREGUARD for WireGuard VPN tunnel
Aaron LI [Mon, 25 Sep 2023 09:04:19 +0000 (25 17:04 +0800)]
net/if: Add IFT_WIREGUARD for WireGuard VPN tunnel

2 months agoroute.8: Some markup improvements
Aaron LI [Tue, 6 Feb 2024 14:26:57 +0000 (6 22:26 +0800)]
route.8: Some markup improvements

2 months agocrypto: Minor cleanups to blake2s
Aaron LI [Tue, 6 Feb 2024 14:24:18 +0000 (6 22:24 +0800)]
crypto: Minor cleanups to blake2s

- Adjust the KKASSERT() to be easier to read.
- Add KKASSERT() to blake2s_hmac(), avoiding the possible misuse of
  passing a too large 'outlen', which could cause panic or data
  corruption.
- Minor style cleanups.

2 months agocrypto: Add two comments to _chacha20poly1305_final()
Aaron LI [Tue, 6 Feb 2024 14:21:06 +0000 (6 22:21 +0800)]
crypto: Add two comments to _chacha20poly1305_final()

It's actually not hard to understand, but add comments to make it quite
clear.

3 months agokernel - Fix improper error on certain O_EXCL open() operations
Matthew Dillon [Sun, 4 Feb 2024 22:59:41 +0000 (4 14:59 -0800)]
kernel - Fix improper error on certain O_EXCL open() operations

* O_EXCL|O_CREAT open()s were converting EACCES to EEXIST without
  determining whether the error was due to an interemdiate directory
  component.  In fact it needs to return the error caused by the
  intermediate directory component.

  EACCES is only converted to EEXIST by an O_EXCL|O_CREAT open()
  when the error is caused by the last component of the path.
  Because in that case the last component does in fact exist and
  it is not relevant whether it is accessible or not.

* Fix by specifying whether the error came from an intermediate
  directory check using a previously unused field in struct
  nlookupdata.  A bit messy bit this was the easiest way since
  we've run out of NLC flag bits.

Reported-by: tuxillo
3 months agoif_gre: Reimplement output loop detection using mbuf 'loop_cnt'
Aaron LI [Thu, 25 Jan 2024 14:22:43 +0000 (25 22:22 +0800)]
if_gre: Reimplement output loop detection using mbuf 'loop_cnt'

The original method made use the 'called' member inside the interface
softc struct, which was quite rudimentary and not MP-safe.

Reimplement the loop detection using the newly added mbuf(9)
'm_pkthdr.loop_cnt' field.  In addition, change the errno of this case
from EIO to ELOOP.

3 months agoif_gif: Reimplement output loop detection using mbuf 'loop_cnt'
Aaron LI [Thu, 25 Jan 2024 14:19:48 +0000 (25 22:19 +0800)]
if_gif: Reimplement output loop detection using mbuf 'loop_cnt'

The original method made use the 'called' static variable, which was
ad-hoc and fragile.  Reimplement the loop detection using the newly
added mbuf(9) 'm_pkthdr.loop_cnt' field.  In addition, change the errno
of this case from EIO to ELOOP.

3 months agoVarious minor whitespace cleanups
Aaron LI [Mon, 30 Oct 2023 06:05:03 +0000 (30 14:05 +0800)]
Various minor whitespace cleanups

Accumulated along the way.

3 months agolock.9: Minor markup improvements
Aaron LI [Thu, 25 Jan 2024 13:20:42 +0000 (25 21:20 +0800)]
lock.9: Minor markup improvements

Meanwhile, tweak a wording a bit.

3 months agoobjcache.9: Add ctor/dtor/alloc/free function typedefs to SYNOPSIS
Aaron LI [Thu, 25 Jan 2024 13:46:37 +0000 (25 21:46 +0800)]
objcache.9: Add ctor/dtor/alloc/free function typedefs to SYNOPSIS

Also add the 'objcache_malloc_args' struct definition.

3 months agoobjcache.9: Improve one markup
Aaron LI [Thu, 25 Jan 2024 13:43:32 +0000 (25 21:43 +0800)]
objcache.9: Improve one markup

3 months agoobjcache.9: Use 'destructor' instead of 'deconstructor'
Aaron LI [Thu, 25 Jan 2024 13:43:02 +0000 (25 21:43 +0800)]
objcache.9: Use 'destructor' instead of 'deconstructor'

Well, the 'destructor' is now the most common terminology in
programming.

3 months agogif.4: Remove one duplicate "be" word
Aaron LI [Thu, 25 Jan 2024 13:28:35 +0000 (25 21:28 +0800)]
gif.4: Remove one duplicate "be" word

3 months agonetstat(1): Fix alignment of 'Drop' and 'Time' columns
Aaron LI [Tue, 23 Jan 2024 13:49:10 +0000 (23 21:49 +0800)]
netstat(1): Fix alignment of 'Drop' and 'Time' columns

3 months agonvmm: Add KCFLAGS in Makefile to improve standalone module build
Aaron LI [Thu, 18 Jan 2024 05:31:53 +0000 (18 13:31 +0800)]
nvmm: Add KCFLAGS in Makefile to improve standalone module build

When a module is build alone, the '-g -DINVARIANTS' flags are not
present in the default compiler flags, which can hurts developing and
debuging the module.  Add these flags via 'KCFLAGS' to help it.

3 months agoSort directories in makefiles
Aaron LI [Tue, 16 Jan 2024 02:02:38 +0000 (16 10:02 +0800)]
Sort directories in makefiles

3 months agombuf(9): Add 'M_PROTOFLAGS' to group all M_PROTO* flags
Aaron LI [Sat, 13 Jan 2024 13:37:04 +0000 (13 21:37 +0800)]
mbuf(9): Add 'M_PROTOFLAGS' to group all M_PROTO* flags

Obtained-from: FreeBSD

3 months agombuf(9): Add 'm_pkthdr.loop_cnt' for loop detection
Aaron LI [Sat, 13 Jan 2024 13:36:13 +0000 (13 21:36 +0800)]
mbuf(9): Add 'm_pkthdr.loop_cnt' for loop detection

Extend the 'm_pkthdr' struct to provide the 'loop_cnt' member by using
currently unused space.  Therefore, drivers (e.g., gif, gre, wg) can
make use of this new member to easily implement loop detection.

Bump __DragonFly_version.

Discussed-with: dillon
Referred-to: OpenBSD

3 months agosocket: Implement the SO_USER_COOKIE option
Aaron LI [Tue, 31 Oct 2023 01:06:01 +0000 (31 09:06 +0800)]
socket: Implement the SO_USER_COOKIE option

This socket option allows to attach an arbitrary uint32_t value to a
socket as the user-defined cookie/metadata, and then the cookie can be
used in the kernel help manipulate the traffic of the socket.

For example, this socket option can be set by WireGuard and then matched
in IPFW to help control the WireGuard traffic.

This commit is mostly derived from FreeBSD, but I decided to also
support this option in getsockopt().

Note that the support of this option in IPFW (and PF and others) is
still need to be implemented.  I'd like to do it in the future but it
may take quite some efforts.  This commit alone doesn't achieve much
benefits, but it helps port the WireGuard code from FreeBSD, so commit
it first.

Bump __DragonFly_version.

Credit: https://github.com/freebsd/freebsd-src/commit/d5e8d236f4009fc2611f996c317e94b2c8649cf5

3 months agokernel - Fix long-standing bug in kqueue backend for *poll*()
Matthew Dillon [Tue, 23 Jan 2024 21:00:54 +0000 (23 13:00 -0800)]
kernel - Fix long-standing bug in kqueue backend for *poll*()

* The poll() family of system calls passes an fds[] array with a
  series of descriptors and event requests.  Our kernel implementation
  uses kqueue but a long standing bug breaks situations where
  more than one fds[] entry for the poll corresponds to the same
  { ident, filter } for kqueue, causing only the last such entry
  to be registered with kqueue and breaking poll().

* Added feature to kqueue to supply further distinctions between
  knotes beyond the nominal { kq, filter, ident } tuple, allowing
  us to fix poll().

* Added a FreeBSD feature where poll() implements an implied POLLHUP
  when events = 0.  This is used by X11 and (perhaps mistakenly) also
  by sshd.  Our poll previous ignored fds[] entries with events = 0.

* Note that sshd can generate poll fds[] arrays with both an events = 0
  and an events = POLLIN for the same descriptor, which broke sshd
  when I initially added the events = 0 support due to the first bug.

  Now with that fixed, sshd works properly.  However it is unclear whether
  the authors of sshd intended events = 0 to detect POLLHUP or not.

Reported-by: servik (missing events = 0 poll feature)
Testing: servik, dillon

3 months agoconfig.8: Remove markup in the -width, also make it non-compact.
Sascha Wildner [Wed, 17 Jan 2024 14:34:56 +0000 (17 15:34 +0100)]
config.8: Remove markup in the -width, also make it non-compact.

3 months agonetproto/mpls: Fix 'cpuid' to be 'mycpuid' and thus fix build
Aaron LI [Wed, 17 Jan 2024 05:21:31 +0000 (17 13:21 +0800)]
netproto/mpls: Fix 'cpuid' to be 'mycpuid' and thus fix build

The typo was made by me in commit
6823c302c37b3feda6c2c8b524a99daa1bcff11f.

After this fix, LINT64 builds fine.

3 months agodsynth - Adjust /boot mounts for chroot
Matthew Dillon [Tue, 16 Jan 2024 22:52:27 +0000 (16 14:52 -0800)]
dsynth - Adjust /boot mounts for chroot

* Fix issue where Intel microcode couldn't be installed within the
  chroot due to trying to write into /boot.

* Replace /boot null-mount with a /boot tmpfs and mkdir /boot/modules.local.
  Leave other /boot directories unpopulated for now (we'll fix that if we
  hit problems).  i.e. no /boot/kernel or anything else is in the chroot
  any more.

* This also allows us to remove the /boot/modules.local tmpfs mount we had
  before, improving performance slightly.

Reported-by: tuxillo
3 months agoAdd integrated dports build feature to build-all and install-all targets
Matthew Dillon [Tue, 2 Jan 2024 04:57:00 +0000 (1 20:57 -0800)]
Add integrated dports build feature to build-all and install-all targets

When WITH_DPORTS=YES is used build-all and install-all, these targets will
also build the base set of ports and all of their dependencies using
configuration data and the "dragonfly/base" dport found in
"/usr/src/dports.base".

This feature is intended to be used by the nrelease build in an upcoming
commit, and may also be used manually.

The /usr/dports tree must exist and contains the dports repo to use as the
basis of the dports build.  It will be null-mounted in the chroot and the
"/usr/src/dports.base/dragonfly" directory will be null-mounted under it
to provide the "dragonfly/base" meta-port.   The DPORTSBASE make variable
may be used to override the location of the main dports repo.

The build-all and install-all targets use a sophisticated chrooted
environment to do a completely clean dports build with dsynth.  It
It will actually "make installworld" plus a clean "make distribution"
inside the chroot environment to create the environment, and the host
system's /etc/resolv.conf will be copied in.

build-all - Augmented when used WITH_DPORTS=YES
install-all - Augmented when used WITH_DPORTS=YES
buildportschroot - Build a fresh chroot environment for dsynth
mountports - Do all null mounts and cp's needed for the env
buildports - Run dsynth build dragonfly/base in the env
installports - Install the built ports on the host system (see note)
umountports - Remove the null mounts

WITH_DPORTS=YES - executes buildportschroot, mountports, buildports,
  and umountports when run from build-all.

  executes mountports, installports, umountports
  when run from install-all.

DPORTSBASE=path - Defaults to /usr/dports, may be used to override
  the location where the main dports tree can be
  found.

NOTE: Installports may require interactivity as the base system might already
      have installed ports.  Generally speaking it is best to not revert any
      ports you might already have installed, so feel free to tell it not to
      install anything.

* Added various make targets and augmented build-all and install-all

* /usr/local/sbin added and the stale /usr/pkg/bin removed from _HOSTPATH.

* Add /usr/src/dports.base infrastructure.

  It contains the dsynth.ini and pkg.conf files that will be used for the
  local dsynth operations.  Some paths are replaced with SED when copied
  to the chroot.  The dsynth.ini is relative to the chroot.

  It also contains the dragonfly/base dport which is the meta-port that
  dsynth will be told to build.

  All other dports related files and directories are null-mounted from
  /usr/dports.

* Add /usr/distfiles.base to mtree/BSD.usr.dist.  This directory is also
  created by the build if it does not exist since the host system might
  not have run a new installworld recently.

  This directory will be used during build-all (buildports) to store the
  distfiles required to build dragonfly/base, so they only need to be
  fetched once.

* Add the "-C ConfigBase" option to dsynth to make running it from the
  chrooted environment easier.  This overrides the /etc/dsynth directory
  and removes /etc/dsynth as a fallback.

* dsynth conditionalizes calling syscap_set() for backwards compatibility
  with older host systems that might not have been upgraded to include the
  feature yet.

3 months agoatomic.9: Some small updates
Aaron LI [Sun, 14 Jan 2024 07:31:51 +0000 (14 15:31 +0800)]
atomic.9: Some small updates

- Add some more description obtained from FreeBSD.
- Uncomment the 64-bit variant contents.
- Minor wording tweaks.

3 months agoatomic(9): Add relaxed load/store variants from FreeBSD
Aaron LI [Sun, 14 Jan 2024 07:27:33 +0000 (14 15:27 +0800)]
atomic(9): Add relaxed load/store variants from FreeBSD

Obtained from FreeBSD.  However, the original atomic_store_ptr() macro
was causing '-Wcast-qual' warnings, so I changed it based on the
NetBSD's atomic_store_relaxed().

Actually, I found NetBSD's version more clean, but we import the FreeBSD
version to help import code/drivers in the future.

Discussed-with: dillon

3 months agocrypto/chachapoly: Allow output be NULL in decrypting empty plaintext
Aaron LI [Mon, 8 Jan 2024 10:35:41 +0000 (8 18:35 +0800)]
crypto/chachapoly: Allow output be NULL in decrypting empty plaintext

Don't distinguish the input cipher data from AD by checking whether the
output buffer is NULL, because it's actually valid to pass it as NULL
when to decrypt a message of empty plaintext.  And it's really used by
WireGuard.

So separate the AD process code into a separate helper function named
_chacha20poly1305_update_ad().   Update the assertions to not blindly
assert 'out != NULL'.  Also add a note about this special case to the
header file.

3 months agocrypto: Implement chacha20poly1305 in-place process for mbuf chains
Aaron LI [Fri, 24 Nov 2023 05:39:56 +0000 (24 13:39 +0800)]
crypto: Implement chacha20poly1305 in-place process for mbuf chains

Implement the chacha20poly1305_{encrypt,decrypt}_mbuf() functions that
performs in-place encryption and decryption for data in an mbuf chain.

The in-kernel WireGuard will use these two functions to encrypt/decrypt
packets.

3 months agocrypto: Refactor the chacha20poly1305 code to be more flexible
Aaron LI [Thu, 23 Nov 2023 09:56:45 +0000 (23 17:56 +0800)]
crypto: Refactor the chacha20poly1305 code to be more flexible

Introduce the 'chacha20poly1305_ctx' struct to hold the context, and
implement the _init()/_update()/_final() functions as the building
blocks to perform encryption/decryption in a more generic way.

The main intention is to help implement the in-place encryption and
decryption of data in an mbuf chain.  That would reduce the unnecessary
memory allocations and data copies in packet manipulations, as needed by
the in-kernel WireGuard.  This API will be done in a later commit.

Rewrite the original chacha20poly1305_{encrypt,decrypt}() functions
using the new blocks.

3 months agocrypto: Add ChaCha20-Poly1305 and XChaCha20-Poly1305 AEAD
Aaron LI [Wed, 22 Nov 2023 01:39:42 +0000 (22 09:39 +0800)]
crypto: Add ChaCha20-Poly1305 and XChaCha20-Poly1305 AEAD

Derived from OpenBSD with significant modifications by me:

- Removed unused code to hook into the cryptosoft framework.
- Adjusted the interface to align with the IETF RFC document
  (e.g., make the nonce a byte string other than a uint64_t),
  so that the code becomes more generic.

References:
- RFC 8439: ChaCha20 and Poly1305 for IETF Protocols
- RFC draft: XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305

3 months agocrypto: Add brief descriptions to every chacha20 public function
Aaron LI [Thu, 23 Nov 2023 09:34:00 +0000 (23 17:34 +0800)]
crypto: Add brief descriptions to every chacha20 public function

One important note is that chacha_encrypt_bytes() supports in-place
decryption/encryption.  This point ensures that the chacha20poly1305
code also supports in-place operations.

3 months agocrypto: Add hchacha20() for implementing XChaCha20-Poly1305 AEAD
Aaron LI [Tue, 21 Nov 2023 09:58:29 +0000 (21 17:58 +0800)]
crypto: Add hchacha20() for implementing XChaCha20-Poly1305 AEAD

Derived from OpenBSD.  I changed memcpy() to multiple U32TO8_LITTLE()s,
so the output key is in the standard little-endian format.

Reference:
- RFC draft: XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305

3 months agocrypto: Adjust curve25519 and hook to build
Aaron LI [Fri, 17 Nov 2023 02:28:16 +0000 (17 10:28 +0800)]
crypto: Adjust curve25519 and hook to build

- Fix header inclusions.
- Add necessary '__inline' for '__always_inline' to fix build.
- Replace 'letoh32()' with 'le32toh()'.
- Adjust style a bit to be more consistent.

3 months agocrypto: Import Curve25519 implementation from OpenBSD
Aaron LI [Fri, 17 Nov 2023 01:26:03 +0000 (17 09:26 +0800)]
crypto: Import Curve25519 implementation from OpenBSD

Required by the in-kernel WireGuard VPN.

3 months agocrypto: Some minor cleanups to poly1305
Aaron LI [Wed, 22 Nov 2023 02:26:07 +0000 (22 10:26 +0800)]
crypto: Some minor cleanups to poly1305

- Use 'uint8_t' instead of 'unsigned char', being more consistent with
  other crypto code (e.g., chacha20)
- Add two more macros: POLY1305_KEY_SIZE, POLY1305_MAC_SIZE

3 months agocrypto: Adjust poly1305 and hook to build
Aaron LI [Fri, 17 Nov 2023 02:52:40 +0000 (17 10:52 +0800)]
crypto: Adjust poly1305 and hook to build

- Use all uppercase for macro constant (i.e., POLY1305_BLOCK_SIZE).
- Add 'inline' to two helper functions: U8TO32(), U32TO8()

3 months agocrypto: Import Poly1305 implementation from OpenBSD
Aaron LI [Fri, 17 Nov 2023 02:30:52 +0000 (17 10:30 +0800)]
crypto: Import Poly1305 implementation from OpenBSD

This hash algorithm is required to implement the Chacha20-Poly1305 AEAD
cipher as required by the in-kernel WireGuard VPN.

3 months agocrypto: Remove unnecessary 'const' qualifiers in blake2s
Aaron LI [Wed, 22 Nov 2023 05:35:47 +0000 (22 13:35 +0800)]
crypto: Remove unnecessary 'const' qualifiers in blake2s

3 months agocrypto: Adjust blake2 and hook to build
Aaron LI [Fri, 17 Nov 2023 02:26:02 +0000 (17 10:26 +0800)]
crypto: Adjust blake2 and hook to build

Make necessary changes to make it build.  Meanwhile, adjust the style a
bit to look more consistent.

3 months agocrypto: Import BLAKE2s implementation from OpenBSD
Aaron LI [Fri, 17 Nov 2023 01:27:14 +0000 (17 09:27 +0800)]
crypto: Import BLAKE2s implementation from OpenBSD

Required by the in-kernel WireGuard VPN.

3 months agocrypto: Adjust siphash a bit and hook to build
Aaron LI [Fri, 17 Nov 2023 01:13:27 +0000 (17 09:13 +0800)]
crypto: Adjust siphash a bit and hook to build

3 months agocrypto: Import SipHash implementation from FreeBSD
Aaron LI [Fri, 17 Nov 2023 00:43:37 +0000 (17 08:43 +0800)]
crypto: Import SipHash implementation from FreeBSD

Required by the in-kernel WireGuard VPN.

3 months ago<sys/cdefs.h>: Add __min_size(x) macro
Aaron LI [Thu, 16 Nov 2023 07:56:31 +0000 (16 15:56 +0800)]
<sys/cdefs.h>: Add __min_size(x) macro

C99 allows to use the 'static' keyword in function array parameter
declarators, which helps the compiler better validate the passed
argument and optimize code.  However, this syntax isn't allowed in C++.

This macro allows us both to use this C99 feature and to use the headers
in C++.

Obtained-from: FreeBSD
URL: https://reviews.freebsd.org/D8277

3 months ago<sys/bitops.h>: Import ilog2(n) from NetBSD
Aaron LI [Fri, 29 Dec 2023 01:26:33 +0000 (29 09:26 +0800)]
<sys/bitops.h>: Import ilog2(n) from NetBSD

And thus remove the local define from 'nvmm_os.h'.

3 months agoobjcache(9): Remove the unused ocflag arg from objcache_reclaimlist()
Aaron LI [Fri, 22 Dec 2023 14:59:46 +0000 (22 22:59 +0800)]
objcache(9): Remove the unused ocflag arg from objcache_reclaimlist()

3 months agosockbuf: Improve sbcreatecontrol() parameter types to save casts
Aaron LI [Fri, 12 Jan 2024 04:08:41 +0000 (12 12:08 +0800)]
sockbuf: Improve sbcreatecontrol() parameter types to save casts

- Change 'caddr_t p' to 'const void *p' to save casts for the callers.
  The 'const' qualifier is also added meanwhile.
- Change 'int size' to 'size_t size', given that callers generally pass
  this parameter as sizeof().
- Update all relevant callers.

For the reference, OpenBSD also did this for sbcreatecontrol().

3 months agombuf(9): Add assertions of off/len parameters for _m_copyback2()
Aaron LI [Fri, 12 Jan 2024 00:50:32 +0000 (12 08:50 +0800)]
mbuf(9): Add assertions of off/len parameters for _m_copyback2()

Similar to the similar assertions in several other functions.

4 months agoevdev: Translate KEY_102ND in evdev_scancode2key()
Aaron LI [Thu, 4 Jan 2024 00:23:47 +0000 (4 08:23 +0800)]
evdev: Translate KEY_102ND in evdev_scancode2key()

This is the extra key on AT 102/105-keys keyboards, located just on the
right of the Left Shift key.  For instance on a French layout, this key
is used to type '<' and '>'.

This fixes an issue where the key fires no evdev event and thus remains
inactive in an evdev/libinput-enabled X.Org server.  The issue only
occurred on an AT keyboard; the same key on a USB keyboard worked fine.

Reported-by: daftaupe
Tested-by: daftaupe, Kentish
Obtained-from: FreeBSD (https://reviews.freebsd.org/D12883)

4 months agombuf(9): Add assertion of 'offset == 0' for m_devget()
Aaron LI [Wed, 3 Jan 2024 04:01:39 +0000 (3 12:01 +0800)]
mbuf(9): Add assertion of 'offset == 0' for m_devget()

As commented above the m_devget() function, the 'offset' argument is
ill-defined and unused; all callers should specify 0 for it.  So add an
assertion for that.

Meanwhile, fix two callers that didn't satisfy this.

4 months agombuf(9): Tweak a wrongly wrapped conditional in m_free()
Aaron LI [Wed, 3 Jan 2024 03:58:08 +0000 (3 11:58 +0800)]
mbuf(9): Tweak a wrongly wrapped conditional in m_free()

4 months agombuf(9): Fix a serious bug: remove extra pointer to caddr_t/c_caddr_t
Aaron LI [Wed, 3 Jan 2024 03:51:57 +0000 (3 11:51 +0800)]
mbuf(9): Fix a serious bug: remove extra pointer to caddr_t/c_caddr_t

The 'caddr_t' and 'c_caddr_t' types are already *pointer* to 'char' and
'const char', respectively, so no need and can't add one more pointer to
them.

This bug was my mistake in commit
ef09a3ed3479755d29ff48a4e81912847e96139a.
It broke the pointer arithmetic and caused some weird issues (e.g.,
system panic, SSH connection lost when transferring lots of data).

4 months agonetbt: Add back m_len/m_pkthdr.len assignments in rfcomm_session_send_mcc()
Aaron LI [Tue, 2 Jan 2024 02:25:22 +0000 (2 10:25 +0800)]
netbt: Add back m_len/m_pkthdr.len assignments in rfcomm_session_send_mcc()

Similar to the fix in the previous commit.

4 months agonetbt: Add back m_len/m_pkthdr.len assignments in l2cap_send_signal()
Aaron LI [Tue, 2 Jan 2024 01:54:51 +0000 (2 09:54 +0800)]
netbt: Add back m_len/m_pkthdr.len assignments in l2cap_send_signal()

In case the 'length' being zero, the m_len/m_pkthdr.len will not be
updated by m_copyback2() and hence are wrong.  Fix it to match the
original behavior.

4 months agonet: Remove unnecessary casts for m_copyback() in ip_mroute.c
Aaron LI [Mon, 1 Jan 2024 13:56:58 +0000 (1 21:56 +0800)]
net: Remove unnecessary casts for m_copyback() in ip_mroute.c

It was missed in my previous commit
05d02a3813e2bef176c69d68035311fd2efbd031.

4 months agonet: Update rt_msg_mbuf() to pre-allocate the required mbuf (chain)
Aaron LI [Mon, 1 Jan 2024 13:44:50 +0000 (1 21:44 +0800)]
net: Update rt_msg_mbuf() to pre-allocate the required mbuf (chain)

Pre-calculate the required mbuf (chain) length and allocate it, and thus
just use m_copyback() instead of m_copyback2() as there is no longer
need to extend it.

Suggested-by: dillon
4 months agonet: Fix my mistake in rt_msg_mbuf()
Aaron LI [Mon, 1 Jan 2024 13:25:24 +0000 (1 21:25 +0800)]
net: Fix my mistake in rt_msg_mbuf()

The given rtinfo->rti_info[] array can be empty, and hence no
m_copydata2() will be called to properly update the 'm_pkthdr.len' and
'm_len' fields.  This was breaking WiFi (at least iwm, and very likely
others).  Bring back the 'm_pkthdr.len' and 'm_len' assignments that was
removed in my previous commit 44647b48cc48ca54dc839a0c8652cd4960416c2b.

Reported-by: Kentish, noob237 (Gonzalo Nemmi)
Investigated-by: dillon
4 months agonet: Fix my mistake in route_output()
Aaron LI [Mon, 1 Jan 2024 13:09:16 +0000 (1 21:09 +0800)]
net: Fix my mistake in route_output()

The 'rtm' is created in this function and its message length (rtm_msglen)
can actually be smaller than the original mbuf length (m_pkthdr.len), so
the original m_adj() must be restored.  It was erroneously removed in
my previous commit 44647b48cc48ca54dc839a0c8652cd4960416c2b.  Fix it.

4 months agokernel: Remove unnecessary casts for updated mbuf(9) functions
Aaron LI [Thu, 28 Dec 2023 06:17:26 +0000 (28 14:17 +0800)]
kernel: Remove unnecessary casts for updated mbuf(9) functions

4 months agombuf(9): Various minor updates and style cleanups
Aaron LI [Thu, 28 Dec 2023 05:17:14 +0000 (28 13:17 +0800)]
mbuf(9): Various minor updates and style cleanups

- Fix the comment that MSIZE/MCLBYTES is defined in <sys/param.h>
  instead of <machine/param.h>; update the man page accordingly.
- Adjust some type casts in mtod() to be more consistent.
- Add the '__unused' attribute to actually unused parameters.
- Remove unused NCL_INIT/NMB_INIT macros from 'uipc_mbuf.c'.
- Use '__func__' instead of hard-coding function names.
- Fix several typos.
- Various style cleanups, mainly whitesapce adjustments.

4 months agombuf(9): Use 'void *' in several public APIs to save casts in callers
Aaron LI [Thu, 28 Dec 2023 03:31:06 +0000 (28 11:31 +0800)]
mbuf(9): Use 'void *' in several public APIs to save casts in callers

Update the following public APIs to use 'void *' or 'const void *'
instead of 'caddr_t'/'c_caddr_t'/'char *', so that callers no longer
need to do explicit casts:

- m_append()
- m_copyback()
- m_copyback2()
- m_copydata()
- m_devget()
- m_extadd()

4 months agoFix typos: uknown -> unknown
Sascha Wildner [Wed, 27 Dec 2023 14:28:30 +0000 (27 15:28 +0100)]
Fix typos: uknown -> unknown

4 months agombuf(9): Use 'c_caddr_t' (const) for m_copyback()/m_copyback2()
Aaron LI [Fri, 22 Dec 2023 07:59:49 +0000 (22 15:59 +0800)]
mbuf(9): Use 'c_caddr_t' (const) for m_copyback()/m_copyback2()

4 months agombuf(9): Fix a code bug in m_dup_data()
Aaron LI [Fri, 22 Dec 2023 07:45:25 +0000 (22 15:45 +0800)]
mbuf(9): Fix a code bug in m_dup_data()

4 months agoopencrypto: Update crypto_copyback() to use m_copyback2(how=M_WAITOK)
Aaron LI [Thu, 21 Dec 2023 07:13:25 +0000 (21 15:13 +0800)]
opencrypto: Update crypto_copyback() to use m_copyback2(how=M_WAITOK)

crypto_copyback() has no return value and isn't expected to fail by the
caller, e.g., swcr_compdec(), so update it to use m_copyback2() with
how=M_WAITOK.

Note that caller swcr_compdec() uses 'M_INTWAIT' for kmalloc(), but that
doesn't make sense to mbuf functions, so use M_WAITOK instead for the
moment.

Discussed-with: dillon

4 months agokernel: Change some m_copyback() to m_copyback2()
Aaron LI [Thu, 21 Dec 2023 02:09:55 +0000 (21 10:09 +0800)]
kernel: Change some m_copyback() to m_copyback2()

For those require mbuf expansion, change m_copyback() to m_copyback2().

4 months agombuf(9): Restrict m_copyback() to forbid mbuf expansion
Aaron LI [Thu, 21 Dec 2023 01:44:28 +0000 (21 09:44 +0800)]
mbuf(9): Restrict m_copyback() to forbid mbuf expansion

Most uses of m_copyback() are in-place updates to a portion (e.g., the
header) of a packet, so no mbuf allocation is required.  It's more clear
to make m_copyback() forbid mbuf expansion instead of let it implicitly
do allocation with how=M_NOWAIT.  Due to the lack of a return value, the
caller is hard to identify an m_copyback() failure, so diagnostics info
will be printed to the console in that case.

Change the original m_copyback2() to be an inline function, and
implement both m_copyback() and m_copyback2() as wrappers of it.

Bump __DragonFly_version for this behavior change.

Discussed-with: dillon

4 months agombuf(9): Improve m_copyback2() to use the trailing space
Aaron LI [Fri, 22 Dec 2023 06:34:50 +0000 (22 14:34 +0800)]
mbuf(9): Improve m_copyback2() to use the trailing space

Make use of the trailing space of the last mbuf if available, both in
skipping the offset and in copying back the data.

As a side benefit of this change, the 'm0->m_len' field no longer needs
to be initialized and can simply be 0, as in a newly allocated mbuf.

Referred to both OpenBSD and FreeBSD; however, they only try to use the
trailing space in copying the data.

4 months agombuf(9): Improve m_copyback2() to support mbuf clusters
Aaron LI [Fri, 22 Dec 2023 05:45:20 +0000 (22 13:45 +0800)]
mbuf(9): Improve m_copyback2() to support mbuf clusters

Update to use m_getl() to allocate mbuf clusters whenever necessary.

Referred to OpenBSD.

4 months agombuf(9): Minor cleanups to m_copyback2()
Aaron LI [Fri, 22 Dec 2023 06:52:11 +0000 (22 14:52 +0800)]
mbuf(9): Minor cleanups to m_copyback2()

4 months agombuf(9): Add m_copyback2() for a better m_copyback()
Aaron LI [Fri, 22 Dec 2023 06:51:49 +0000 (22 14:51 +0800)]
mbuf(9): Add m_copyback2() for a better m_copyback()

The existing m_copyback() may extends the mbuf chain if necessary, but
it doesn't return a value to indicate whether the allocation fails.  In
addition, it doesn't allow to specify the M_WAITOK/M_NOWAIT flag for
mbuf allocation.

Extend m_copyback() and name it m_copyback2() that has the 'how'
parameter to specify M_WAITOK/M_NOWAIT flag and return an error code to
indication the success/failure.

Reimplement the original m_copyback() using m_copyback2() with
how=M_NOWAIT.

Referred-to: OpenBSD

4 months agokernel: Replace the deprecated m_copy() with m_copym()
Aaron LI [Fri, 22 Dec 2023 01:37:00 +0000 (22 09:37 +0800)]
kernel: Replace the deprecated m_copy() with m_copym()

4 months agonet/ip_mroute: Remove unnecessary m_len/m_pkthdr.len assignments
Aaron LI [Thu, 21 Dec 2023 02:16:38 +0000 (21 10:16 +0800)]
net/ip_mroute: Remove unnecessary m_len/m_pkthdr.len assignments

The 'm_len' and 'm_pkthdr.len' are already set to 0 by m_gethdr().

4 months agosys/vfs/hammer2: Remove obsolete comment on device buffer size
Tomohiro Kusumi [Thu, 21 Dec 2023 10:13:07 +0000 (21 02:13 -0800)]
sys/vfs/hammer2: Remove obsolete comment on device buffer size

Remove a comment from 01eabad4d93a8dc8f0f01a6209b384b1e010bb8c in 2012.
A device buffer size is currently always 64KB regardless of chain bytes.
HAMMER2_MIN_ALLOC no longer exists.

4 months agosys/vfs/hammer2: Remove obsolete comments on chain statistics
Tomohiro Kusumi [Thu, 21 Dec 2023 09:23:13 +0000 (21 01:23 -0800)]
sys/vfs/hammer2: Remove obsolete comments on chain statistics

Remove comments for removed code from
b3659de2a6ee73b51bf3edb4babfb4653134813f in 2014.

4 months agosys/platform: Add missing copyright for two header files
Aaron LI [Mon, 18 Dec 2023 02:14:15 +0000 (18 10:14 +0800)]
sys/platform: Add missing copyright for two header files

4 months agoqueue(3): Simplify STAILQ_LAST() by using __containerof()
Aaron LI [Thu, 30 Nov 2023 02:13:01 +0000 (30 10:13 +0800)]
queue(3): Simplify STAILQ_LAST() by using __containerof()

Note that it's necessary to use 'field.stqe_next' instead of 'field';
otherwise, __containerof() would warn about the type mismatch.

Obtained-from: FreeBSD

4 months ago<sys/cdefs.h>: Add __containerof(x, s, m) macro
Aaron LI [Wed, 29 Nov 2023 07:39:38 +0000 (29 15:39 +0800)]
<sys/cdefs.h>: Add __containerof(x, s, m) macro

Obtained from FreeBSD.

4 months agoifconfig.8: More markup tweaks
Aaron LI [Tue, 19 Dec 2023 01:26:48 +0000 (19 09:26 +0800)]
ifconfig.8: More markup tweaks

The main change is replacing 'Sy' with 'Cm', since those symbols are
intended to be given on the command line as arguments.

4 months agoifconfig.8: Alphabetically sort the general parameters
Aaron LI [Thu, 14 Dec 2023 10:06:14 +0000 (14 18:06 +0800)]
ifconfig.8: Alphabetically sort the general parameters

4 months agoifconfig.8: Remove the legacy and commented eon(5) and OSI stuffs
Aaron LI [Thu, 14 Dec 2023 09:53:17 +0000 (14 17:53 +0800)]
ifconfig.8: Remove the legacy and commented eon(5) and OSI stuffs

The eon(5) seems to be related to RFC 986, "which appears to be a rough
ISO equivalent of the IPv6 6to4 transition mechanism." [0]

The "nsellength" thing seems to be related to OSI networking.

These commented contents has been there since 1996 in FreeBSD codebase.
I don't see a point to still keep them, so just remove these legacy
stuffs.

[0] https://gnats.netbsd.org/10500

4 months agoifconfig.8: Some more minor fixes/tweaks/cleanups
Aaron LI [Thu, 14 Dec 2023 07:35:09 +0000 (14 15:35 +0800)]
ifconfig.8: Some more minor fixes/tweaks/cleanups

4 months agoifconfig.8: Replace some 'Fl' with 'Cm' for consistency
Aaron LI [Thu, 14 Dec 2023 07:34:07 +0000 (14 15:34 +0800)]
ifconfig.8: Replace some 'Fl' with 'Cm' for consistency

4 months agoifconfig.8: Various markup improvements to WLAN parameters
Aaron LI [Thu, 14 Dec 2023 05:28:40 +0000 (14 13:28 +0800)]
ifconfig.8: Various markup improvements to WLAN parameters

Referred-to: FreeBSD

4 months agoifconfig.8: Group all IPv6-only parameters to its own subsection
Aaron LI [Thu, 14 Dec 2023 05:23:04 +0000 (14 13:23 +0800)]
ifconfig.8: Group all IPv6-only parameters to its own subsection

Referred-to: FreeBSD

4 months agoifconfig.8: Add subsection headers to group parameters
Aaron LI [Thu, 14 Dec 2023 05:22:05 +0000 (14 13:22 +0800)]
ifconfig.8: Add subsection headers to group parameters

Referred-to: FreeBSD

4 months agoifconfig.8: Minor updates and cleanups to generic parameters
Aaron LI [Thu, 14 Dec 2023 01:47:52 +0000 (14 09:47 +0800)]
ifconfig.8: Minor updates and cleanups to generic parameters

4 months agoifconfig.8: Remove legacy AppleTalk 'range' and 'phase' options
Aaron LI [Thu, 14 Dec 2023 01:36:46 +0000 (14 09:36 +0800)]
ifconfig.8: Remove legacy AppleTalk 'range' and 'phase' options

The AppleTalk code was already removed in commit
d22a69a46a0f55de79a4311db073809348bb5dd0 in 2011.

4 months agoifconfig.8: Rearrange options and perform various updates
Aaron LI [Wed, 13 Dec 2023 10:44:29 +0000 (13 18:44 +0800)]
ifconfig.8: Rearrange options and perform various updates

- Move the general options from the bottom part to the beginning.
- Arrange the options in alphabetic order.
- Update and/or cleanup the option descriptions.
- Adjust various markups and styles.
- Fix some mistakes.
- Remove some obsolete information and commented content.

Mostly obtained from FreeBSD.  Also referred to OpenBSD.