Commit Graph

1480 Commits

Author SHA1 Message Date
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
Gleb Smirnoff
607beb88af bluetooth: don't assign NULL in C99 sparse initializer 2022-05-09 10:42:48 -07:00
Eugene Grosbein
28903f396a ng_pppoe: introduce new sysctl net.graph.pppoe.lcp_pcp
This fixes incomplete commit 2e547442ab

New sysctl allows to mark transmitted PPPoE LCP Control
ethernet frames with needed 3-bit Priority Code Point (PCP) value.
Confirming driver like if_vlan(4) uses the value to fill
IEEE 802.1p class of service field.

This is similar to Cisco IOS "control-packets vlan cos priority"
command.

It helps to avoid premature disconnection of user sessions
due to control frame drops (LCP Echo etc.)
if network infrastructure has a botteleck at a switch
or the xdsl DSLAM.

See also:
https://sourceforge.net/p/mpd/discussion/44692/thread/c7abe70e3a/

Tested by:      Klaus Fokuhl at SourceForge
MFC after:      2 weeks
2022-05-02 21:57:12 +07:00
John Baldwin
2fdf3ed1e3 ng_netflow: Move various variables under INET || INET6. 2022-04-13 16:08:21 -07:00
John Baldwin
6d5f002ed1 netgraph: Remove the rethook parameter from NG_NODE_FOREACH_HOOK.
This parameter was set to the hook that terminated the iteration
early.  However, none of the remaining callers used this argument and
it was always set to an otherwise-unused variable.
2022-04-12 14:58:59 -07:00
John Baldwin
fa351643f5 netgraph: Remove unused variable. 2022-04-12 14:58:59 -07:00
Gordon Bergling
ecbdfbfd18 netgraph(3): Remove a double word in a source code comment
- s/it it/it/

MFC after:	3 days
2022-04-09 14:41:40 +02:00
Gordon Bergling
77a44875e5 netgraph(4): Fix a typo in a source code comment
- s/peform/perform/

MFC after:	3 days
2022-04-09 11:40:14 +02:00
John Baldwin
f44692ce0c ng_tag: Move totlen fully under #ifdef NG_TAG_DEBUG. 2022-04-07 17:01:27 -07:00
John Baldwin
8373c80503 ng_ppp: Remove unused variable. 2022-04-07 17:01:27 -07:00
John Baldwin
ad490a5aeb ng_netflow: Remove unused variable. 2022-04-07 17:01:27 -07:00
John Baldwin
a11819ca1f ng_lmi: Move all of highest_dlci under #if 0. 2022-04-07 17:01:27 -07:00
John Baldwin
497c2cf4f8 ng_ksocket: Remove unused variable. 2022-04-07 17:01:27 -07:00
John Baldwin
9f566782e0 ng_bt: Remove an unused variable.
Leave a comment describing the field in the packet it represented.
2022-04-07 17:01:26 -07:00
Gordon Bergling
f64919bbd9 ng_btsocket(4): Fix a typo in an error message
- s/mulitplexor/multiplexor/

MFC after:	5 days
2022-04-06 18:27:29 +02:00
Gordon Bergling
7fc0ffda35 ng_pppoe(4): Fix a typo in a source code comment
- s/asychronous/asynchronous/

MFC after:	3 days
2022-04-02 13:54:36 +02:00
Gordon Bergling
79438267b3 netgraph(3): Fix a typo in a source code comment
- s/failes/fails/

MFC after:	3 days
2022-03-28 19:31:50 +02:00
Gordon Bergling
1dc2c71ed8 netgraph(4): Fix a typo in a source code comment
- s/shapshot/snapshot/

MFC after:	3 days
2022-03-27 20:08:44 +02:00
Aleksandr Fedorov
b27e6e91d0 ng pppoe(4): Add the required NET_EPOCH section to the hook
disconnection function.

Disconnecting hooks are called outside of NET_EPOCH, but
ng_pppoe_disconnect() calls NG_SEND_DATA_ONLY() which should be called
in NET_EPOCH.

PR:	257067
Reported by:	niels=freebsd@bakker.net
Reviewed by:	vmaffione (mentor), glebius, donner
Approved by:	vmaffione (mentor), glebius, donner
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D34185
2022-02-09 22:00:50 +03:00
Gleb Smirnoff
644ca0846d domains: make domain_init() initialize only global state
Now that each module handles its global and VNET initialization
itself, there is no VNET related stuff left to do in domain_init().

Differential revision:	https://reviews.freebsd.org/D33541
2022-01-03 10:15:22 -08:00
Gleb Smirnoff
89128ff3e4 protocols: init with standard SYSINIT(9) or VNET_SYSINIT
The historical BSD network stack loop that rolls over domains and
over protocols has no advantages over more modern SYSINIT(9).
While doing the sweep, split global and per-VNET initializers.

Getting rid of pr_init allows to achieve several things:
o Get rid of ifdef's that protect against double foo_init() when
  both INET and INET6 are compiled in.
o Isolate initializers statically to the module they init.
o Makes code easier to understand and maintain.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D33537
2022-01-03 10:15:21 -08:00
Alexander Motin
2f1a46d12b netgraph: Remove CTLFLAG_NEEDGIANT from sysctl.
MFC after:	2 weeks
2021-12-26 19:42:53 -05:00
Mateusz Guzik
fe30e08ac7 ng_pppoe: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-15 12:32:40 +00:00
Hans Petter Selasky
8fa952937b ng_ubt(4): Add missing module dependency for _net_bluetooth sysctl node.
Differential Revision:  https://reviews.freebsd.org/D33282
PR:		238235
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-12-08 10:18:32 +01:00
Hans Petter Selasky
03f0393477 ng_ubt(4): Make net.bluetooth.usb_isoc_enable writable.
Differential Revision:	https://reviews.freebsd.org/D33282
PR:		238235
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-12-07 11:50:51 +01:00
Hans Petter Selasky
67cbbf1959 ng_ubt(4): Introduce net.bluetooth.usb_isoc_enable loader tunable to disable
isochronous transfers.

If users want to disable isochronous transfers, which cause high
frequency periodic interrupts from the USB host controller, then
net.bluetooth.usb_isoc_enable can be set to zero, either as a
sysctl(8) or as a loader.conf(5) tunable.

Differential Revision:	https://reviews.freebsd.org/D33282
Submitted by:	naito.yuichiro@gmail.com
PR:		238235
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2021-12-07 11:39:49 +01:00
Mark Johnston
b25ba58adc ng_ubt: Avoid attaching to several newer Intel controllers
Like other Intel controllers, these require firmware to be loaded, and
generic ng_ubt attach causes them to lock up until a power cycle.
However, their firmware interface for querying version info and loading
operational firmware is different from that implemented by ng_ubt_intel
and iwmbtfw, so they are not usable yet.  Just disable attach for now to
avoid stalls during USB device enumeration.

PR:		260161
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-12-05 10:51:46 -05:00
Gleb Smirnoff
ae04d30451 ng_l2tp: use callout_reset() instead of ng_callout()
The previous commit to this node falsely stated that locked callouts
are compatible with netgraph ng_callout KPI.  They are not.  An item
can be queued instead of being applied to the node, which results in
a mutex leak to the callout thread and later unlocked call into function
that expects to be called locked.

Potentially netgraph can be taught to handle locked callouts, but that
would bring a lot of complexity in it.  Instead lets question necessity
of ng_callout() instead of callout_reset().  It protects against node
going away while callout is scheduled.  But a node that drains all
callouts in the shutdown method (ng_l2tp does) is already protected.

Fixes:	89042ff776
2021-12-03 08:57:23 -08:00
Mitchell Horne
0d2224733e Implement GET_STACK_USAGE on remaining archs
This definition enables callers to estimate remaining space on the
kstack, and take action on it. Notably, it enables optimizations in the
GEOM and netgraph subsystems to directly dispatch work items when there
is sufficient stack space, rather than queuing them for a worker thread.

Implement it for riscv, arm, and mips. Remove the #ifdefs, so it will
not go unimplemented elsewhere.

PR:		259157
Reviewed by:	mav, kib, markj (previous version)
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32580
2021-11-30 11:15:56 -04:00
Gleb Smirnoff
319e9fc642 ng_bridge: count item allocation failures as memory failures
Submitted by:	Dmitry Luhtionov <dmitryluhtionov gmail.com>
2021-11-23 10:05:36 -08:00
Ian Lepore
44aae623ab Add ETHER_ALIGN support to ng_device(4).
This adds a new ng_device command, NGM_DEVICE_ETHERALIGN, which has no
associated args.  After the command arrives, the device begins adjusting all
packets sent out its hook to have ETHER_ALIGN bytes of padding at the
beginning of the packet.  The ETHER_ALIGN padding is added only when
running on an architecture that requires strict alignment of IP headers
(based on the __NO_STRICT_ALIGNMENT macro, which is only #define'd on
x86 as of this writing).

This also adds ascii <-> binary command translation to ng_device, both for
the existing NGM_DEVICE_GET_DEVNAME and the new ETHERALIGN command.

This also gives a name to every ng_device node when it is constructed, using
the cdev device name (ngd0, ngd1, etc).  This makes it easier to address
command msgs to the device using ngctl(8).

Reviewed by:	donner, ray, adrian
Differential Revision:	https://reviews.freebsd.org/D32905
MFC after:   1 week
2021-11-14 13:37:41 +01:00
Gordon Bergling
40a57b00f9 ng_pptpgre(4): Fix a typo in a source code comment
- s/mimimum/minimum/

MFC after:	3 days
2021-11-03 17:15:59 +01:00
Gleb Smirnoff
6aae3517ed Retire synchronous PPP kernel driver sppp(4).
The last two drivers that required sppp are cp(4) and ce(4).

These devices are still produced and can be purchased
at Cronyx <http://cronyx.ru/hardware/wan.html>.

Since Roman Kurakin <rik@FreeBSD.org> has quit them, they no
longer support FreeBSD officially.  Later they have dropped
support for Linux drivers to.  As of mid-2020 they don't even
have a developer to maintain their Windows driver.  However,
their support verbally told me that they could provide aid to
a FreeBSD developer with documentaion in case if there appears
a new customer for their devices.

These drivers have a feature to not use sppp(4) and create an
interface, but instead expose the device as netgraph(4) node.
Then, you can attach ng_ppp(4) with help of ports/net/mpd5 on
top of the node and get your synchronous PPP.  Alternatively
you can attach ng_frame_relay(4) or ng_cisco(4) for HDLC.
Actually, last time I used cp(4) back in 2004, using netgraph(4)
instead of sppp(4) was already the right way to do.

Thus, remove the sppp(4) related part of the drivers and enable
by default the negraph(4) part.  Further maintenance of these
drivers in the tree shouldn't be a big deal.

While doing that, remove some cruft and enable cp(4) compilation
on amd64.  The ce(4) for some unknown reason marks its internal
DDK functions with __attribute__ fastcall, which most likely is
safe to remove, but without hardware I'm not going to do that, so
ce(4) remains i386-only.

Reviewed by:		emaste, imp, donner
Differential Revision:	https://reviews.freebsd.org/D32590
See also:		https://reviews.freebsd.org/D23928
2021-10-22 11:41:36 -07:00
Gordon Bergling
0a8159d8ca ng_ppp(4): Fix a typo in a comment
- s/delcared/declared/

MFC after:	3 days
2021-10-14 15:30:32 +02:00
Warner Losh
79a100e28e bluetooth: complete removal of ng_h4
The ng_h4 module was disconnected 13 years ago when the tty later was
locked by Ed. It completely fails to compile, and has a number of false
positives for Giant use. Remove it for lack of interest. Bluetooth has
largely (completely?) moved on from bluetooth over UART transport.

OK'd by:		emax
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31846
2021-09-29 20:00:02 -06:00
Yoshihiro Takahashi
d653b188e8 ng_ether: Create netgraph nodes for bridge interfaces.
Create netgraph nodes for bridge interfaces when the ng_ether module
is loaded.  If a bridge interface is created after loading the ng_ether
module, a netgraph node is created via ether_ifattach().

MFC after:	1 week
2021-09-26 01:24:33 +09:00
Gleb Smirnoff
89042ff776 ng_l2tp: improve callout locking.
Apparently e62e4b8594 wasn't enough to close the race between
a queue being flushed by a packet and callout executing, because
the callouts used without a lock aren't 100% bulletproof. To close
the race use callout_init_mtx() for L2TP timers, and make sure that
all calls to ng_callout()/ng_uncallout() are done under the seq lock.

If used properly, a locked callout can be used transparently with
old netgraph KPI of ng_callout/ng_uncallout which predates locked
callouts.

While here, utilize ng_uncallout_drain() instead of ng_uncallout()
on the node shutdown.

PR:			241133
Reviewed by:		mjg, markj
Differential Revision:	https://reviews.freebsd.org/D31476
2021-09-10 11:27:19 -07:00
Gleb Smirnoff
0a76c63dd4 ng_l2tp: improve seq structure locking.
Cover few cases of access to seq without lock missed in 702f98951d.
There are no known bugs fixed with this change, however. With INVARIANTS
embed ng_l2tp_seq_check() into lock/unlock macros. Slightly reduce number
of locks/unlocks per packet keeping the lock between functions.

Reviewed by:		mjg, markj
Differential Revision:	https://reviews.freebsd.org/D31476
2021-09-10 11:27:13 -07:00
Gleb Smirnoff
b2954f0a8f netgraph: add ng_uncallout_drain().
Move shared code into ng_uncallout_internal(). While here add a comment
mentioning a problem with scheduled+executing callout.

Reviewed by:		mjg, markj
Differential Revision:	https://reviews.freebsd.org/D31476
2021-09-10 11:27:04 -07:00