Commit Graph

1518 Commits

Author SHA1 Message Date
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
Brooks Davis
211c302f10 NgATM: deprecate
Support for ATM NICs was removed prior to FreeBSD 12.  At the time it
was unclear if this code was still useful without it.  Now the time has
come to finish removing support.

Add DREPRECATION NOTICEs to the manpages and gone_in(14, ...) warnings
in the constructors (or module init for ngatmbase).

MFC after:	3 days
Relnotes:	yes

Reviewed by:	manu, emaste
Differential Revision:	https://reviews.freebsd.org/D38877
2023-03-03 16:47:36 +00:00
Konstantin Belousov
2555f175b3 Move kstack_contains() and GET_STACK_USAGE() to MD machine/stack.h
Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
2023-02-02 00:59:26 +02:00
Justin Hibbits
3d0d5b21c9 IfAPI: Explicitly include <net/if_private.h> in netstack
Summary:
In preparation of making if_t completely opaque outside of the netstack,
explicitly include the header.  <net/if_var.h> will stop including the
header in the future.

Sponsored by:	Juniper Networks, Inc.
Reviewed by:	glebius, melifaro
Differential Revision: https://reviews.freebsd.org/D38200
2023-01-31 15:02:16 -05:00
Ed Maste
05c0c99ea3 ng_hci: handle NG_HCI_M_PULLUP failure in le_advertizing_report
PR:		267396
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	takawata
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37228
2022-11-01 14:33:37 -04:00
Kristof Provost
23559c9d0d netgraph/ng_bridge: add missing array terminator
PR:		267457
Reported by:	Robert Morris <rtm@lcs.mit.edu>
MFC after:	1 week
2022-10-31 09:47:01 +01:00
Ed Schouten
af3c78886f Alter the prototype of qsort_r(3) to match POSIX, which adopted the
glibc-based interface.

Unfortunately, the glibc maintainers, despite knowing the existence
of the FreeBSD qsort_r(3) interface in 2004 and refused to add the
same interface to glibc based on grounds of the lack of standardization
and portability concerns, has decided it was a good idea to introduce
their own qsort_r(3) interface in 2007 as a GNU extension with a
slightly different and incompatible interface.

With the adoption of their interface as POSIX standard, let's switch
to the same prototype, there is no need to remain incompatible.

C++ and C applications written for the historical FreeBSD interface
get source level compatibility when building in C++ mode, or when
building with a C compiler with C11 generics support, provided that
the caller passes a fifth parameter of qsort_r() that exactly matches
the historical FreeBSD comparator function pointer type and does not
redefine the historical qsort_r(3) prototype in their source code.

Symbol versioning is used to keep old binaries working.

MFC:			never
Relnotes:		yes
Reviewed by:		cem, imp, hps, pauamma
Differential revision:	https://reviews.freebsd.org/D17083
2022-09-30 15:26:30 -07:00
Aleksandr Fedorov
0e6e2c4ef3 netgraph(4): Don't process NGQF_MESG items in NET_EPOCH context.
Netgraph has two main types of message items:

- NGQF_DATA items are used for data processing. This is a hot path that
should be called from a NET_EPOCH context.

- NGQF_MESG items are used for node configuration. There are many places
in netgraph(4) where processing the NGQF_MESG item can call sections of code
that are forbidden in the NET_EPOCH context.

All item types can be queued and then processed using ngthread().
But ngthread() is unconditionally enter in the NET_EPOCH section for all types.
This causes panic/deadlocks when processing NGQF_MESG elements.

Reported by:	mjg
Reviewed by:	glebius, vmaffione (mentor)
Tested by:	mjg, afedorov
Approved by:	glebius, vmaffione (mentor)
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D36496
2022-09-13 17:20:41 +03:00
Gleb Smirnoff
8624f4347e divert: declare PF_DIVERT domain and stop abusing PF_INET
The divert(4) is not a protocol of IPv4.  It is a socket to
intercept packets from ipfw(4) to userland and re-inject them
back.  It can divert and re-inject IPv4 and IPv6 packets today,
but potentially it is not limited to these two protocols.  The
IPPROTO_DIVERT does not belong to known IP protocols, it
doesn't even fit into u_char.  I guess, the implementation of
divert(4) was done the way it is done basically because it was
easier to do it this way, back when protocols for sockets were
intertwined with IP protocols and domains were statically
compiled in.

Moving divert(4) out of inetsw accomplished two important things:

1) IPDIVERT is getting much closer to be not dependent on INET.
   This will be finalized in following changes.
2) Now divert socket no longer aliases with raw IPv4 socket.
   Domain/proto selection code won't need a hack for SOCK_RAW and
   multiple entries in inetsw implementing different flavors of
   raw socket can merge into one without requirement of raw IPv4
   being the last member of dom_protosw.

Differential revision:	https://reviews.freebsd.org/D36379
2022-08-30 15:09:21 -07:00
Gleb Smirnoff
e7d02be19d protosw: refactor protosw and domain static declaration and load
o Assert that every protosw has pr_attach.  Now this structure is
  only for socket protocols declarations and nothing else.
o Merge struct pr_usrreqs into struct protosw.  This was suggested
  in 1996 by wollman@ (see 7b187005d1), and later reiterated
  in 2006 by rwatson@ (see 6fbb9cf860).
o Make struct domain hold a variable sized array of protosw pointers.
  For most protocols these pointers are initialized statically.
  Those domains that may have loadable protocols have spacers. IPv4
  and IPv6 have 8 spacers each (andre@ dff3237ee5).
o For inetsw and inet6sw leave a comment noting that many protosw
  entries very likely are dead code.
o Refactor pf_proto_[un]register() into protosw_[un]register().
o Isolate pr_*_notsupp() methods into uipc_domain.c

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36232
2022-08-17 11:50:32 -07:00
Gleb Smirnoff
f277746e13 protosw: change prototype for pr_control
For some reason protosw.h is used during world complation and userland
is not aware of caddr_t, a relic from the first version of C.  Broken
buildworld is good reason to get rid of yet another caddr_t in kernel.

Fixes:	886fc1e804
2022-08-12 12:08:18 -07:00
Dimitry Andric
dba7f4aa09 Adjust ng_{name,ID}_rehash() definitions to avoid clang 15 warnings
With clang 15, the following -Werror warnings are produced:

    sys/netgraph/ng_base.c:981:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ng_name_rehash()
                  ^
                   void
    sys/netgraph/ng_base.c:1012:13: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ng_ID_rehash()
                ^
                 void

This is because ng_name_rehash() and ng_ID_rehash() are declared with
(void) argument lists, but defined with empty argument lists. Make the
definitions match the declarations.

MFC after:	3 days
2022-07-25 20:02:31 +02:00
Hans Petter Selasky
9d28e15e7b ng_ubt(4): Probe USB Bluetooth per USB interface and not per USB device.
PR:		264416
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-06-03 10:49:17 +02:00
Gleb Smirnoff
b46667c63e sockbuf: merge two versions of sbcreatecontrol() into one
No functional change.
2022-05-17 10:10:42 -07:00
John Baldwin
d83185d932 ng_ubt: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:03 -07:00
Gleb Smirnoff
7496792841 ng_socket: don't assign NULL in C99 sparse initializer 2022-05-09 10:42:48 -07:00