Commit graph

1533 commits

Author SHA1 Message Date
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
Gordon Bergling
7037ebe63d netgraph: Fix two typos in source code comments
- s/bascially/basically/
- s/simpliest/simplest/

MFC after:	3 days
2024-01-20 17:22:28 +01:00
Richard Scheffenegger
a8b70cf260 netpfil: Use accessor functions and named constants for all tcphdr flags
Update all remaining references to the struct tcphdr th_x2 field.
This completes the compatibilty of various aspects with AccECN
(TH_AE), after the internal ipfw "re-checksum required" was moved
to use the TH_RES1 flag.

No functional change.

Reviewed By:           tuexen, #transport, glebius
Sponsored by:          NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D43172
2023-12-25 13:18:01 +01:00
Gleb Smirnoff
0fac350c54 sockets: don't malloc/free sockaddr memory on getpeername/getsockname
Just like it was done for accept(2) in cfb1e92912, use same approach
for two simplier syscalls that return socket addresses.  Although,
these two syscalls aren't performance critical, this change generalizes
some code between 3 syscalls trimming code size.

Following example of accept(2), provide VNET-aware and INVARIANT-checking
wrappers sopeeraddr() and sosockaddr() around protosw methods.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D42694
2023-11-30 08:31:10 -08:00
Gleb Smirnoff
cfb1e92912 sockets: don't malloc/free sockaddr memory on accept(2)
Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient.  Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do.  Linux also does that. Update tests accordingly.

Reviewed by:		rscheff, tuexen, zlei, dchagin
Differential Revision:	https://reviews.freebsd.org/D42635
2023-11-30 08:30:55 -08:00
Gleb Smirnoff
d2de66a90d ng_socket: with getsockname() return node ID for unnamed node
Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42691
2023-11-27 20:11:38 -08:00
Gleb Smirnoff
4064a1108b netgraph: increase size of sockaddr_ng to match maximum node name
The ng_socket(4) node already writes more than declared size of the
struct at least in the in ng_getsockaddr().  Make size match size of
a node name.  The value is pasted instead of including ng_message.h
into ng_socket.h.  This is external API and we want to keep it stable
even if NG_NODESIZ is redefined in a kernel build.

Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42690
2023-11-27 20:10:52 -08:00
Warner Losh
fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Gleb Smirnoff
43f7e21668 ng_ksocket: fix accept(2)
- Provide listen upcall and set it on NGM_KSOCKET_LISTEN
- Mask EWOULDBLOCK on NGM_KSOCKET_ACCEPT

Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42637
PR:			272319
PR:			275106
Fixes:			779f106aa1
2023-11-17 09:24:30 -08:00
Gleb Smirnoff
efad7cbfdc ng_ksocket: fix upcall clearing on node shutdown
Note: imho, the proper solution would be to guarantee that upcalls
won't ever be called after soclose(), but this isn't the case, yet.
This change at least makes the node work the way it always worked.

Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42636
PR:			272319
PR:			275106
Fixes:			779f106aa1
2023-11-17 09:23:58 -08:00
Eugene Grosbein
20e1f207cc ng_ipfw: allow use of 32 bits wide cookies
There is no reason in truncating 32 bits cookie value to 16 bits.

Reviewed by:	glebius
MFC after:	2 weeks
2023-11-14 16:36:08 +07:00
Warner Losh
8c0955cbd9 netgraph: Fix obsolete comment
splnet is no more, adjust the comment.

Sponsored by:		Netflix
2023-10-27 14:00:37 -06:00
Marko Zec
03ef737c54 ng_eiface: switch VNETs when injecting mbufs into netgraph
A ng_eiface instance may be on lease to a different vnet while
remaining tied to its parent vnet.  In such circumstances, before
injecting mbufs into netgraph, curvnet must be set to that of the
ng_eiface's netgraph node.  Mark the vnet transition as QUIET,
since otherwise it would be recorded as a curvnet recursion when
ng_eiface's ifnet resides in the same (parent) vnet as its
netgraph node.

PR:		274028
Reported by:	Dancho Penev <dpslavov@hotmail.com>
MFC after:	1 week
2023-09-23 10:56:56 +02:00
Warner Losh
78d146160d sys: Remove $FreeBSD$: one-line bare tag
Remove /^\s*\$FreeBSD\$$\n/
2023-08-16 11:55:17 -06:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh
ecfb43cb41 SPDX: It's spelled 'SPDX-License-Identifier'
Sponsored by:		Netflix
2023-05-12 10:44:04 -06:00
Warner Losh
eebd9d5366 spdx: Simplify BSD-2-Clause AND BSD-2-Clause
After removing the -FreeBSD and -NetBSD, we're left with a nuber of
BSD-2-Clause AND BSD-2-Clause, so tidy that up.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:04 -06:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Brooks Davis
105a4f7b3c ng_atmllc: remove
This standalone module is the last vestage of ATM support in the tree so
send it on its way.

Reviewed by:	manu, emaste
Relnotes:	yes
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38880
2023-03-09 18:04:21 +00:00
Brooks Davis
af0cc0b223 NgATM: Remove netgraph ATM support
Most ATM support was removed prior to FreeBSD 12.  The netgraph support
was kept as it was less intrusive, but it is presumed to be unused.

Reviewed by:	manu
Relnotes:	yes
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38879
2023-03-09 18:04:02 +00:00
Gleb Smirnoff
7fc82fd1f8 ipfw: garbage collect ip_fw_chk_ptr
It is a relict left from the old times when ipfw(4) was hooked
into IP stack directly, without pfil(9).
2023-03-03 10:30:15 -08:00
Brooks Davis
c2285a7b09 ng_atmllc: deprecate
With the deprecation of NgATM, ng_atmllc is the last vestage of ATM
support so deprecate it too.

MFC after:	3 days
Relnotes:	yes

Reviewed by:	manu, emaste
Differential Revision:	https://reviews.freebsd.org/D38878
2023-03-03 16:47:36 +00:00