Commit Graph

1556 Commits

Author SHA1 Message Date
Ahmad Khalifa 9b2478f60b ng_tty: avoid the sign extention of char
When c is compared to sc->hotchar, both undergo integer promotion, which
can lead to c being sign extended. Fix this by casting c to an unsigned
char.

Reviewed by:	kevans
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D54544
2026-01-06 04:10:11 +02:00
Gleb Smirnoff 0bd0c3295a ng_ether: refactor to use interface EVENTHANDLER(9)s 2025-12-21 18:23:14 -08:00
Gleb Smirnoff 104827151e ng_iface: don't recursively enter epoch in the rcvdata method
Reviewed by:		p.mousavizadeh_protonmail.com, zlei
Differential Revision:	https://reviews.freebsd.org/D54241
2025-12-17 14:05:53 -08:00
Gordon Bergling 756712d745 ng_hci(4): Fix a typo in a source code comment
- s/depricated/deprecated/

MFC after:	3 days
2025-12-13 10:54:30 +01:00
Quentin Thébault a505b80b2f ng_device: add kqueue support
Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr>

Sponsored by:	Defenso
Reviewed by:	markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D52541
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1880
2025-10-27 12:45:30 +00:00
Bjoern A. Zeeb 0ee6e36ea9 bluetooth: ng_ubt_rtl/rtlbtfw: remove duplicate entry in device table
Remove the single 8822CU entry in all three places.
It seems the only entry referencing a USB device.  The same device is
listed with the 8822CE devices.

MFC after:	3 days
Reviewed by:	wulf
Differential Revision: https://reviews.freebsd.org/D52324
2025-10-17 16:45:58 +00:00
Mateusz Guzik e0b571d773 mtx: rename MTX_CONTESTED to MTX_WAITERS
Using the word "contested" for the case where there are threads blocked
on the lock is misleading at best (the lock is already contested if it
is being held by one thread and wanted by another). It also diverges
from naming used in other primitives (which refer to them as "waiters").

Rename it for some consistency.

There were uses of the flag outside of mutex code itself.

This is an abuse of the interface. The netgraph thing looks suspicious
at best, the sctp thing is fundamentally wrong. Fixing those up is left
as an exercise for the reader.

While here touch up stale commentary.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
2025-10-06 02:19:38 +00:00
Ahmad Khalifa e05521121f ng_tty: copy to the correct mbuf
memcpy should copy to the current mbuf, otherwise we're copying to the
first mbuf in the chain over and over.

Reported by:	kevans
Reviewed by:	glebius
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D52713
2025-09-25 19:55:28 +03:00
Ahmad Khalifa 57d5a8feda ng_tty: don't increment m_data
Stop incrementing m_data so the callee can read the mbuf.

MFC after:	3 days
Reviewed by:	glebius
Differential Revision:	https://reviews.freebsd.org/D52702
2025-09-24 18:03:12 +03:00
Mark Johnston 18fd3f8ec5 ng_btsocket_rfcomm: Mark a couple buffers as const in a helper function
Fixes:	680f9acc36 ("ng_hci: Cast NG_HCI_BDADDR_ANY to const bdaddr_t *")
2025-09-15 13:57:19 +00:00
Christos Margiolis 680f9acc36 ng_hci: Cast NG_HCI_BDADDR_ANY to const bdaddr_t *
This is needed to address some compiler errors cleanly, where consumer
functions want this address to be a const pointer.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D52310
2025-09-15 16:09:42 +03:00
Quentin Thébault bcdbeaeffc ng_device.c: improve compliance with style(9)
Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr>
Reviewed by: imp, jhb
Pull Request: https://github.com/freebsd/freebsd-src/pull/1827
2025-09-12 10:24:44 -06:00
Quentin Thébault 9fadaee7ec ng_device: enable setting the device to non-blocking mode
Return success when FIONBIO or FIOASYNC ioctl are received in order to support
being set to non-blocking through fcntl(2). We return an error on FIOASYNC with
non-zero data argument since we do not support O_ASYNC.

Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr>
Reviewed by: imp, jhb
Pull Request: https://github.com/freebsd/freebsd-src/pull/1827
2025-09-12 10:24:38 -06:00
Quentin Thébault 593d432e58 ng_device: replace dependency on vnode.h with fcntl.h
Update to current convention of using fcntl.h O_* flags instead of vnode.h IO_*
ones, as explained in sys/fs/devfs/devfs_vnops.c.

Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr>
Reviewed by: imp, jhb
Pull Request: https://github.com/freebsd/freebsd-src/pull/1827
2025-09-12 10:24:26 -06:00
Ed Maste 375527545c ng_parse: Add upper bound to avoid possible overflow
Also move num initialization for clarity.

We still need to check num in ng_unparse_composite (reported by des@ in
D52151) but this is another incremental improvement in netgraph input
validation.

Reviewed by:	des
PR:		267334
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52151
2025-09-01 17:12:45 -04:00
Maxim Sobolev f74c0dc583 ng_nat: fix potential crash when attaching to L2 directly
Fix potential crash in the ng_nat module when attaching directly
to the layer 2 (ethernet) while calculating TCP checksum.

The issue is due to in_delayed_cksum() expecting to access IP
header at the offset 0 from the mbuf start, while if we are
attached to the L2 directly, the IP header at going to be at the
certain offset.

Reviewed by:	markj, tuexen
Approved by:	tuexen
Sponsored by:	Sippy Software, Inc.
Differential Revision:	https://reviews.freebsd.org/D49677
MFC After:	2 weeks
2025-08-25 21:34:45 -07:00
Olivier Certner 8ecc419180 Internal scheduling priorities: Always use symbolic ones
Replace priorities specified by a base priority and some hardcoded
offset value by symbolic constants.  Hardcoded offsets prevent changing
the difference between priorities without changing their relative
ordering, and is generally a dangerous practice since the resulting
priority may inadvertently belong to a different selection policy's
range.

Since RQ_PPQ is 4, differences of less than 4 are insignificant, so just
remove them.  These small differences have not been changed for years,
so it is likely they have no real meaning (besides having no practical
effect).  One can still consult the changes history to recover them if
ever needed.

No functional change (intended).

MFC after:      1 month
Event:          Kitchener-Waterloo Hackathon 202506
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D45390
2025-06-17 22:08:02 -04:00
Zhenlei Huang c43d6dadf7 ng_iface(4): Remove a redundant assignment of if_type
That is unnecessary since change [1], as if_alloc(IFT_PROPVIRTUAL) has
set if_type already.

[1] fc74a9f93a Stop embedding struct ifnet at the top of driver softcs

No functional change intended.

MFC after:	1 week
2025-06-13 18:07:18 +08:00
Brooks Davis e453e498cb machine/stdarg.h -> sys/stdarg.h
Switch to using sys/stdarg.h for va_list type and va_* builtins.

Make an attempt to insert the include in a sensible place.  Where
style(9) was followed this is easy, where it was ignored, aim for the
first block of sys/*.h headers and don't get too fussy or try to fix
other style bugs.

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
2025-06-11 17:39:02 +01:00
Seyed Pouria Mousavizadeh Tehrani 95c414dd27 ng_sample: fix style nits
MFC after:	3 days
Reviewed by:	ivy, kp, des
Approved by:	des (mentor)
Differential Revision:	https://reviews.freebsd.org/D50343
2025-05-16 21:29:47 +01:00
Vladimir Kondratyev 3e72d0b400 rtlbtfw(8): Sync device VID/PID list with Linux 6.15-rc4
Sponsored by:	Future Crew, LLC
MFC after:	1 month
2025-05-14 17:38:10 +03:00
Dag-Erling Smørgrav a0da2f73b6 Remove remaining mentions of pr_usrreq.
When struct pr_usrreq was folded into struct protosw and the function
pointers it contained were renamed from pru_* to pr_* in 2022, a
number of references to the old names in comments and error messages
were missed.  Chase them down and fix them.

Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	kevans, glebius
Differential Revision:	https://reviews.freebsd.org/D50190
2025-05-08 16:29:15 +02:00
Vladimir Kondratyev 7a7ab347fc rtlbtfw(8): Add Mercusys MA530 VID/PID for Realtek 8761BUV
Tested by:	Yusuf Yaman <nxjoseph@protonmail.com>
PR:		286369
MFC after:	1 week
2025-04-29 23:28:53 +03:00
Eugene Grosbein 93b4a54456 netgraph: prevent panic with INVARIANTS-enabled kernel
This change makes NG_ABI_VERSION depend on INVARIANTS
in addition to NETGRAPH_DEBUG.

PR:		257876
MFC-after:	2 weeks
2025-02-25 14:22:53 +07:00
Andreas Kempe 4ae0fa8a2f ng_hci: add support for Bluetooth Secure Simple Pairing
Add additional messages that allow for secure simple pairing.

PR:		265066
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation (review and commit)
2025-01-27 13:27:28 +00:00
Gleb Smirnoff 63f2849023 ng_ksocket: fix build without INET6
Fixes:	9234a50752
2025-01-13 13:27:32 -08:00
Seyed Pouria Mousavizadeh Tehrani 9234a50752 ng_ksocket: add IPv6 support for address parsing and unparsing
Differential Revision:	https://reviews.freebsd.org/D48204
2025-01-10 12:00:58 -08:00
Damjan Jovanovic f132be9bac netgraph: Enable support for EIM NAT
Enable support for endpoint-independent mapping ("full cone NAT") via
Libalias's UDP NAT.

Reviewed by:    igoro, thj
Differential Revision:  https://reviews.freebsd.org/D46689
2024-12-06 09:31:58 +00:00
Richard Scheffenegger 0fc7bdc978 tcp: extend the use of the th_flags accessor function
Formally, there are 12 bits for TCP header flags.
Use the accessor functions in more (kernel) places.

No functional change.

Reviewed By: cc, #transport, cy, glebius, #iflib, kbowling
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D47063
2024-11-29 09:48:23 +01:00
Ed Maste ae4f39464c ng_parse: disallow negative length for malloc
This is an interim robustness improvement; further improvements as
described in the PR and/or Phabricator review are still needed.

PR:		267334
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37229
2024-11-21 15:53:04 -05:00
Mark Johnston 46f38a6ded netgraph: Exit the net epoch to handle control messages
In general, in the direct dispatch case netgraph only enters the net
epoch to send data messages, but this was inconsistent with the netgraph
thread, which also entered the net epoch to send fn and fn2 messages to
nodes.  Some handlers, e.g., ng_bridge_newhook(), may sleep, and so
cannot be called in epoch context; the netgraph tests occasionally panic
due to this problem.

Make ngthread() consistent with the direct dispatch path.

Discussed with:	afedorov (in D44615)
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
2024-11-21 18:55:35 +00:00
Vladimir Kondratyev 24ae172a50 ng_ubt(4): do not attach Realtek 87XX/88XX adaptors in bootloader mode.
Attempt to initialize FreeBSD bluetooth stack while such a device is in
bootloader mode locks the adapter hardly so it requires power on/off
cycle to restore.

This change blocks ng_ubt attachment unless operational firmware is
loaded thus preventing the lock up.

Sponsored by:	Future Crew LLC
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D46738
2024-11-07 02:28:11 +03:00
Vladimir Kondratyev 0b23c50ae8 ng_ubt_intel: Ignore unexpected HCI events
If Intel firmware is already in operational mode at boot that takes
place at warm boot, BT adaptor can generate extra HCI events which
interferes with firmware mode detection logic. Ignore them.

Sponsored by:	Future Crew LLC
MFC after:	1 month
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D46736
2024-11-07 02:27:20 +03:00
Vladimir Kondratyev 19a577ea5c ng_ubt_intel: Allow to attach to 9260 bluetooth adaptors
with operational mode firmware.

Sponsored by:	Future Crew LLC
MFC after:	1 month
Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D46734
2024-11-07 02:25:56 +03:00
Gordon Bergling 9046ecff40 bluetooth(3): Fix two typos in source code comments
- s/conficts/conflicts/

MFC after:	3 days
2024-09-20 20:00:04 +02:00
Eugene Grosbein becd0079c0 ng_ipfw(4): add missing change after previous commit
The function ng_ipfw_input() used to enjoy implicit
32->16 bits truncation of its second argument.
Make it explicit to recover from the breakage.

PR:		281082
Reported by:	Ruben van Staveren <ruben@verweg.com>
Tested by:	Ruben van Staveren <ruben@verweg.com>
MFC after:	3 days
Fixes:		20e1f207cc
2024-09-13 02:09:28 +07:00
Kevin Lo 8b21c469db ng_ubt: Add blacklist entries for MediaTek MT7925
This controller requires firmware patch downloading to operate,
block ng_ubt attachment unless operational firmware is loaded.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D46302
2024-08-16 10:03:19 +08:00
Ryan Libby f8a46de2dd bluetooth socket sysinit: correct memset initialization
gcc -Wmemset-elt-size diagnosed this.  The code was only initializing
the first 1/sizeof(long) bytes.  On 64-bit systems, this would mean only
events up to 0x20 were initialized.

This effectively reverses the security policy for some events with
higher ids, now permitting them on unprivileged sockets.  Two that are
defined are NG_HCI_EVENT_LE (0x3e) and NG_HCI_EVENT_BT_LOGO (0xfe).

PR:		280039
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D45707
2024-07-01 08:22:31 -07:00
Zhenlei Huang aa3860851b net: Remove unneeded NULL check for the allocated ifnet
Change 4787572d05 made if_alloc_domain() never fail, then also do the
wrappers if_alloc(), if_alloc_dev(), and if_gethandle().

No functional change intended.

Reviewed by:	kp, imp, glebius, stevek
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D45740
2024-06-28 18:16:29 +08:00
Dmitry Lukhtionov 9b8db66402 netgraph: provide separate malloc type for nodes that are missing it
The kernel option NG_SEPARATE_MALLOC helps to debug memory leaks in
netgraph(4).  Several nodes were missing the support.
2024-05-31 09:19:54 -07:00
Martin Vahlensieck d44c78074d ng_pipe: Do not panic when memory allocations fail
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

Reviewed by:	markj
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1181
2024-04-24 08:44:50 -04:00
Martin Vahlensieck a3ecf8c786 ng_pipe: Replace deprecated random() with prng32_bounded()
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

MFC after:	2 weeks
Reviewed by:	markj
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1181
2024-04-24 08:44:50 -04:00
Martin Vahlensieck bb2ab7a374 ng_pipe: Remove node when all hooks are disconnected
This is the behavior described in the man page.

Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

Discussed with:	glebius
Reviewed by:	markj
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1181
2024-04-24 08:44:50 -04:00
Martin Vahlensieck 8512311fb5 ng_pipe: Fix whitespace
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

Reviewed by:	markj
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1181
2024-04-24 08:40:51 -04:00
Mark Johnston 7f7b4926a7 ng_hci: Add sockaddr validation to sendto()
ng_btsocket_hci_raw_send() wasn't verifying that the destination address
specified by sendto() is large enough to fill a struct sockaddr_hci.
Thus, when copying the socket address into an mbuf,
ng_btsocket_hci_raw_send() may read past the end of the input sockaddr
while copying.

In practice this is effectively harmless since
ng_btsocket_hci_raw_output() only uses the address to identify a
netgraph node.

Reported by:	Oliver Sieber <oliver@secfault-security.com>
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2024-04-22 11:48:00 -04:00
Seth Hoffert 2cb0fce24d bpf: Make BPF interop consistent with if_loop
The pseudo_AF_HDRCMPLT check is already being done in if_loop and
just needed to be ported over to if_ic, if_wg, if_disc, if_gif,
if_gre, if_me, if_tuntap and ng_iface.  This is needed in order to
allow these interfaces to work properly with e.g., tcpreplay.

PR:		256587
Reviewed by:	markj
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/876
2024-04-19 14:48:37 -04:00
Zhenlei Huang f6f67f58c1 ng_socket: Treat EEXIST from kern_kldload() as success
EEXIST is possible in a race condition.

Inspired by:	ffc72591b1 (Don't worry if a module is already loaded ...)
Reviewed by:	glebius
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D44633
2024-04-09 18:04:47 +08:00
David Marker 86a6393a7d ng_bridge: allow to automatically assign numbers to new hooks
This will allow a userland machinery that orchestrates a bridge (e.g. a
jail or vm manager) to not double the number allocation logic.  See bug
278130 for longer description and examples.

Reviewed by:		glebius, afedorov
Differential Revision:	https://reviews.freebsd.org/D44615
PR:			278130
2024-04-08 10:48:22 -07:00
Gleb Smirnoff 1a3d1be496 ng_ksocket: use new macros to lock socket buffers 2024-03-22 22:44:16 -07:00
Gleb Smirnoff f79a8585bb sockets: garbage collect SS_ISCONFIRMING
Fixes:	8df32b19de
2024-01-30 10:38:33 -08:00