net: Reimplement packet loop detection based on mbuf tags The original naive implementation based on mbuf 'm_pkthdr.loop_cnt' was flawed: * There were likely some code paths that allocated mbufs failed to initialize the 'loop_cnt' to be zero. This caused unwanted packet drops in gif(4), as reported by Kyle Butt (iteratee). * The 'loop_cnt' was system-wide and thus cannot distinguish between the nesting of specific drivers. For example, it would break an actually valid setup that makes use of both gif(4) and gre(4). As a result, follow the FreeBSD's way and reimplement the packet loop detection based on mbuf tags. Each driver is allocated a unique mbuf tag cookie, and thus a unique mbuf tag will be created to track the nesting level of each driver. The if_tunnel_check_nesting() was derived from FreeBSD but I changed it to use only one mbuf tag for each cookie (i.e., driver). Although it can no longer directly detect that a packet loops through the same interface, it would still be prevented as that would lead to infinite recursions. Update gif(4), gre(4) and wg(4) to use the new loop detection facility. Bump __DragonFly_version as well. Reported-by: Kyle Butt (iteratee)
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
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
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
kldstat(2): Support to report module's full path Add 'pathname' field to 'kld_file_stat' and 'linker_file' structs, enable the kldstat(2) syscall to report the full path of modules. This also allows kldstat(8) to print the full path of loaded modules, which may be helpful in debugging. Bump __DragonFly_version due to syscall interface change. Obtained-from: FreeBSD (revision 172862, commit 1676805c186f5dea36d331a982480d7d9693b126) See also: https://lists.dragonflybsd.org/pipermail/users/2023-January/428489.html
wait(2): Make WIFSIGNALED(x) exclude WIFCONTINUED(x) So now WIFSIGNALED means the remaining state of not exited, not stopped and not continued. Bump __DragonFly_version. Bug: https://bugs.dragonflybsd.org/issues/3329 Credit: - NetBSD (https://github.com/NetBSD/src/commit/33e727d2) - FreeBSD (https://github.com/freebsd/freebsd-src/commit/f24deb02)
kernel - fbsd kpi support, add sleepq*() API (untested) * Initial sleepq*() API. We use our tsleep*() API underneath it. This is a horrible API so add a note that it should only be used for FreeBSD compat stuff. - Add tsleep/wakeup domains to implement the two sleepq*() queues. - Track blocking refs per queue in the sleepq API - Do not track individual threads (just let tsleep*()/wakeup*() do its thing). - objcache for wchan, 1K hash table for now, and retain a cache of available wchan structures in the hash table (up to 4 per slot). - Include the hash-slot spin lock as FreeBSD compat code will use it for interlock tests. - Relax sleepq_signal() a bit, allowing it to wakeup more than one thread (the DragonFly wakeup_*_one*() is a bit non-deterministic). * For now add discrete fields to the thread structure. Its a bit of bloat but its better than dynamically allocating a side-structure. We already use our tsleep*() API and related fields underneath. Add a few more needed for tracking the wchan structure, the queue, and the timeout. * Add sbintime_t type (as 64-bit ticks), and a sbticks global counter. Monotonic ticks since boot, 64 bits.
world - Fix buildworld bootstrapping on older systems * Adjustments for the buildworld bootstrap stages when building on older systems that do not have sys/byteswap.h. * Note that the first __DragonFly_Version rev containing sys/byteswap,h is 500908 in comments (no functional changes to sys/param.h)
KERN_PROC - Change behavior and bump version to 600302 * Change default behavior to not include pure LWPs. That is, to not include pure kernel threads without a process (pid returned as -1). * Add a flag KERN_PROC_FLAG_LWKT to re-include the LWPs for programs that don't get confused by them. * Adjust /bin/ps and /usr/bin/top to use the flag. Also conditionalized on the existance of the flag so buildworld on older systems doesn't fail. * Clean-up the sysctl kernel interface for KERN_PROC a bit, since adding the flag creates a lot more combinations that need to be handled as discrete sysctls.
ext2fs: Remove sys/gnu/vfs/ext2fs and make sys/vfs/ext2fs the default This commit removes the old+unstable GPL ext2 implementation, and makes the new FreeBSD based ext2 implementation (since cfe603905713d4e92a7956678970d5dff8e913f2) the default. - Remove sys/gnu/vfs. - Rename sys/vfs/ext2fs/ext2fs_freebsd.ko -> ext2fs.ko. - Modify unusual userspace program which includes kernel struct. - Bump __DragonFly_version to 600107.
sys/kern: Add fdatasync(2) Based on the following FreeBSD commits in 2016. 295af703a0d7987c6cf4987e7b7f5f07b3ca1221 1c1cc89580f0fbfabaf6f6c7f0f6440eef0c128e Add the syscall and also add it to pthread's cancellation point. The default behavior is same as fsync(2), which is fine but inefficient.