Commit graph

1518 commits

Author SHA1 Message Date
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
Gleb Smirnoff 26cf4b53d9 netgraph: pass return value from callout_stop() unmodified to callers of
ng_uncallout. Most of them do not check it anyway, so very little node
changes are required.

Reviewed by:		mjg, markj
Differential Revision:	https://reviews.freebsd.org/D31476
2021-09-10 11:26:59 -07:00
Mark Johnston bd4a39cc93 socket: Properly interlock when transitioning to a listening socket
Currently, most protocols implement pru_listen with something like the
following:

	SOCK_LOCK(so);
	error = solisten_proto_check(so);
	if (error) {
		SOCK_UNLOCK(so);
		return (error);
	}
	solisten_proto(so);
	SOCK_UNLOCK(so);

solisten_proto_check() fails if the socket is connected or connecting.
However, the socket lock is not used during I/O, so this pattern is
racy.

The change modifies solisten_proto_check() to additionally acquire
socket buffer locks, and the calling thread holds them until
solisten_proto() or solisten_proto_abort() is called.  Now that the
socket buffer locks are preserved across a listen(2), this change allows
socket I/O paths to properly interlock with listen(2).

This fixes a large number of syzbot reports, only one is listed below
and the rest will be dup'ed to it.

Reported by:	syzbot+9fece8a63c0e27273821@syzkaller.appspotmail.com
Reviewed by:	tuexen, gallatin
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31659
2021-09-07 17:11:43 -04:00
Zhenlei Huang 62e1a437f3 routing: Allow using IPv6 next-hops for IPv4 routes (RFC 5549).
Implement kernel support for RFC 5549/8950.

* Relax control plane restrictions and allow specifying IPv6 gateways
 for IPv4 routes. This behavior is controlled by the
 net.route.rib_route_ipv6_nexthop sysctl (on by default).

* Always pass final destination in ro->ro_dst in ip_forward().

* Use ro->ro_dst to exract packet family inside if_output() routines.
 Consistently use RO_GET_FAMILY() macro to handle ro=NULL case.

* Pass extracted family to nd6_resolve() to get the LLE with proper encap.
 It leverages recent lltable changes committed in c541bd368f.

Presence of the functionality can be checked using ipv4_rfc5549_support feature(3).
Example usage:
  route add -net 192.0.0.0/24 -inet6 fe80::5054:ff:fe14:e319%vtnet0

Differential Revision: https://reviews.freebsd.org/D30398
MFC after:	2 weeks
2021-08-22 22:56:08 +00:00
Gordon Bergling 34f620f1d0 Fix a few typos in source code comments
- s/posbile/possible/

MFC after:	5 days
2021-08-14 09:39:17 +02:00
Mark Johnston e0e3ded78a ng_bridge: Use M_NOWAIT when allocating memory in the newhook routine
newhook can be invoked by ngthread, which runs in a network epoch
section and is thus not permitted to perform M_WAITOK allocations.

Reported by:	Jenkins
Reviewed by:	donner, afedorov
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31486
2021-08-13 09:49:43 -04:00
Roy Marples 7045b1603b socket: Implement SO_RERROR
SO_RERROR indicates that receive buffer overflows should be handled as
errors. Historically receive buffer overflows have been ignored and
programs could not tell if they missed messages or messages had been
truncated because of overflows. Since programs historically do not
expect to get receive overflow errors, this behavior is not the
default.

This is really really important for programs that use route(4) to keep
in sync with the system. If we loose a message then we need to reload
the full system state, otherwise the behaviour from that point is
undefined and can lead to chasing bogus bug reports.

Reviewed by:	philip (network), kbowling (transport), gbe (manpages)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26652
2021-07-28 09:35:09 -07:00
Mark Johnston f4bb1869dd Consistently use the SOLISTENING() macro
Some code was using it already, but in many places we were testing
SO_ACCEPTCONN directly.  As a small step towards fixing some bugs
involving synchronization with listen(2), make the kernel consistently
use SOLISTENING().  No functional change intended.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-06-14 17:32:27 -04:00
Lutz Donnerhacke 4c3280e587 netgraph/bridge: malloc without flags
During tests an assert was triggered and pointed to missing flags in
the newlink function of ng_bridge(4).

Reported by:	markj
Reviewed by:	markj
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D30759
2021-06-14 15:41:46 +02:00
Bjoern A. Zeeb a3c2c06bc9 Make LINT NOINET and NOIP kernel builds warning free.
Apply #ifdef INET or #if defined(INET6) || defined(INET) to make
universe NOINET and NOIP LINT kernels warning free as well again.
2021-06-06 14:03:06 +00:00
Lutz Donnerhacke 0345fd891f netgraph/ng_base: Renaming a node to the same name is a noop
Detailed analysis in https://github.com/genneko/freebsd-vimage-jails/issues/2
brought the problem down to a double call of ng_node_name() before and
after a vnet move.  Because the name of the node is already known
(occupied by itself), the second call fails.

PR:		241954
Reported by:	Paul Armstrong
MFC:		1 week
Differential Revision: https://reviews.freebsd.org/D30110
2021-06-04 11:20:19 +02:00
Alexander V. Chernikov 8e55a80e0c [netflow] fix gateway reporting in ng_netflow
Reported by:	Guy Yur <guyyur at gmail.com>
MFC after:	3 days
2021-05-30 10:12:49 +00:00
Takanori Watanabe 14803ec8d1 Fix a use-after-free in an error case.
PR: 255872
Submitted by:  lylgood
Differential Revision:  https://reviews.freebsd.org/D30454
2021-05-26 18:23:33 +09:00
Alexander Motin 4a6830761c Fix packet cbs/ebs conversion.
Each packet is counted as 128 bytes by the code, not 125.  Not sure
what I was thinking about here 14 years ago.  May be just a typo.

Reported by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after:	2 weeks
2021-05-19 11:04:08 -04:00
Markus Stoff 63b6a08ce2 ng_parse: IP address parsing in netgraph eating too many characters
Once the final component of the IP address has been parsed, the offset
on the input must not be advanced, as this would remove an unparsed
character from the input.

Submitted by:	Markus Stoff
Reviewed by:	donner
MFC after:	3 weeks
Differential Revision: https://reviews.freebsd.org/D26489
2021-05-18 22:36:28 +02:00
Lutz Donnerhacke 687e510e5c netgraph/ng_checksum: Fix double free error
m_pullup(9) frees the mbuf(9) chain in the case of an allocation error.
The mbuf chain must not be freed again in this case.

PR:		255874
Submitted by:	<lylgood@foxmail.com>
Approved by:	markj
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D30273
2021-05-16 19:39:51 +02:00
Lutz Donnerhacke a56e5ad690 netgraph/ng_bridge: Handle send errors during loop handling
If sending out a packet fails during the loop over all links, the
allocated memory is leaked and not all links receive a copy.  This
patch fixes those problems, clarifies a premature abort of the loop,
and fixes a minory style(9) bug.

PR:		255430
Submitted by:	Dancho Penev
Tested by:	Dancho Penev
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D30008
2021-05-13 21:49:20 +02:00
Lutz Donnerhacke 4dfe70fdbd netgraph/ng_bridge: Avoid cache thrashing
Hint the compiler, that this update is needed at most once per second.
Only in this case the memory line needs to be written.  This will
reduce the amount of cache trashing during forward of most frames.

Suggested by:	zec
Approved by:	zec
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28601
2021-05-13 21:14:36 +02:00
Lutz Donnerhacke 9674c2e68c netgraph/ng_bridge: become SMP aware
The node ng_bridge underwent a lot of changes in the last few months.
All those steps were necessary to distinguish between structure
modifying and read-only data transport paths.  Now it's done, the node
can perform frame forwarding on multiple cores in parallel.

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28123
2021-05-13 17:53:07 +02:00
Lutz Donnerhacke f6e0c47169 netgraph/ng_bridge: move MACs via control message
Use the new control message to move ethernet addresses from a link to
a new link in ng_bridge(4).  Send this message instead of doing the
work directly requires to move the loop detection into the control
message processing.  This will delay the loop detection by a few
frames.

This decouples the read-only activity from the modification under a
more strict writer lock.

Reviewed by:	manpages (gbe)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28559
2021-05-13 17:27:01 +02:00
Lutz Donnerhacke b1bd44732d netgraph/ng_bridge: learn MACs via control message
Add a new control message to move ethernet addresses to a given link
in ng_bridge(4). Send this message instead of doing the work directly.
This decouples the read-only activity from the modification under a
more strict writer lock.

Decoupling the work is a prerequisite for multithreaded operation.

Approved by:	manpages (bcr), kp (earlier version)
MFC:		3 weeks
Differential Revision:	https://reviews.freebsd.org/D28516
2021-05-04 22:14:59 +02:00
Mark Johnston f161d294b9 Add missing sockaddr length and family validation to various protocols
Several protocol methods take a sockaddr as input.  In some cases the
sockaddr lengths were not being validated, or were validated after some
out-of-bounds accesses could occur.  Add requisite checking to various
protocol entry points, and convert some existing checks to assertions
where appropriate.

Reported by:	syzkaller+KASAN
Reviewed by:	tuexen, melifaro
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29519
2021-05-03 13:35:19 -04:00
Vladimir Kondratyev 788a171c77 ng_ubt: Block attachment of uninitialized Intel Wireless 7265
As this controller requires firmware patch downloading to operate.
"Intel Wireless 7265" support in iwmbtfw(8) is yet to be done.

Tested by:	arrowd et al
PR:		228787
MFC after:	2 weeks
2021-04-15 17:26:32 +03:00
Vladimir Kondratyev d605d72948 ng_ubt: Use DEFINE_CLASS_1 macro for kobj inheritance.
MFC after:	2 weeks
2021-04-15 17:25:50 +03:00
Vladimir Kondratyev 52489f2a55 ng_ubt: Do not clear stall before receiving of HCI command response.
Unconditional execution of "clear feature" request at SETUP stage was
workaround for probe failures on ng_ubt.ko re-kldloading which is
unnecessary now.

Reviewed by:	hselasky
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D29775
2021-04-15 17:25:00 +03:00
Lutz Donnerhacke 3c958f5fdf netgraph/ng_bridge: Add counters for the first link, too
For broadcast, multicast and unknown unicast, the replication loop
sends a copy of the packet to each link, beside the first one. This
special path is handled later, but the counters are not updated.
Factor out the common send and count actions as a function.

Reviewed by:	kp
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D28537
2021-02-10 19:05:37 +01:00
Lutz Donnerhacke 011b7317db netgraph/ng_bridge: Document staleness in multithreaded operation
In the data path of ng_bridge(4), the only value of the host struct,
which needs to be modified, is the staleness, which is reset every
time a frame is received.  It's save to leave the code as it is.

This patch is part of a series to make ng_bridge(4) multithreaded.

Reviewed by:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28546
2021-02-09 20:09:05 +01:00
Lutz Donnerhacke ccf4cd2e78 netgraph/ng_bridge: Merge internal structures
In a earlier version of ng_bridge(4) the exernal visible host entry
structure was a strict subset of the internal one.  So internal view
was a direct annotation of the external structure.  This strict
inheritance was lost many versions ago.  There is no need to
encapsulate a part of the internal represntation as a separate
structure.

This patch is a preparation to make the internal structure read only
in the data path in order to make ng_bridge(4) multithreaded.

Reviewed by:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28545
2021-02-09 19:29:27 +01:00
Alexander V. Chernikov 924d1c9a05 Revert "SO_RERROR indicates that receive buffer overflows should be handled as errors."
Wrong version of the change was pushed inadvertenly.

This reverts commit 4a01b854ca.
2021-02-08 22:32:32 +00:00
Alexander V. Chernikov 4a01b854ca SO_RERROR indicates that receive buffer overflows should be handled as errors.
Historically receive buffer overflows have been ignored and programs
could not tell if they missed messages or messages had been truncated
because of overflows. Since programs historically do not expect to get
receive overflow errors, this behavior is not the default.

This is really really important for programs that use route(4) to keep in sync
with the system. If we loose a message then we need to reload the full system
state, otherwise the behaviour from that point is undefined and can lead
to chasing bogus bug reports.
2021-02-08 21:42:20 +00:00
Lutz Donnerhacke 45d75e3ac3 netgraph/ng_base: Allow larger BINARY2ASCII conversions
Allocate the necessary memory for the conversion dynamically starting
with a value which is sufficient for almost all normal cases.

PR:		187835
Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D23840
2021-02-08 14:31:58 +01:00
Lutz Donnerhacke 6117aa58fa netgraph/ng_bridge: Make simple internal functions read-only
The data path in netgraph is designed to work on an read only state of
the whole netgraph network.  Currently this is achived by convention,
there is no technical enforcment.  In the case of NETGRAPH_DEBUG all
nodes can be annotated for debugging purposes, so the strict
enforcment needs to be lifted for this purpose.

This patch is part of a series to make ng_bridge multithreaded, which
is done by rewrite the data path to operate on const.

Reviewed By:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28141
2021-02-07 20:31:33 +01:00
Lutz Donnerhacke cef689f45b Revert "netgraph/ng_bridge: Make simple internal functions read-only"
Patch mass breaks LINT kernels.

This reverts commit bb67e52db1.
2021-02-07 17:39:35 +01:00
Lutz Donnerhacke bb67e52db1 netgraph/ng_bridge: Make simple internal functions read-only
The data path in netgraph is designed to work on an read only state of
the whole netgraph network.  Currently this is achived by convetion,
there is no technical enforcment.  This patch is part of a series to
make ng_brigde multithreaded, which is done by rewrite the data path
to const handling.

Reviewed By:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28141
2021-02-07 15:39:57 +01:00
Lutz Donnerhacke ed0a152750 netgraph/ng_bridge: Remove old table ABI
This was announced to happen after the 12 relases.
Remove a depeciated ABI.

The complete removal is for HEAD only. I'll remove the #define in
stable/13 as MFC, so the code will still exist in 13.x, but will not
included by default. Earlier versions will not be affected.

Reviewed by:	kp
MFC after:	5 days
Differential Revision: https://reviews.freebsd.org/D28518
2021-02-07 15:29:07 +01:00
Lutz Donnerhacke 66c72859f6 netgraph/ng_bridge: switch stats to counter framework
This is the first patch of a series of necessary steps
to make ng_bridge(4) multithreaded.

Reviewed by:	melifaro (network), afedorov
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D28125
2021-02-06 18:14:23 +01:00
Lutz Donnerhacke c869d905ba netgraph/ng_bridge: Derive forwarding mode from first attached hook
Handling of unknown MACs on an bridge with incomplete learning
capabilites (aka uplink ports) can be defined in different ways.

The classical approach is to broadcast unicast frames send to an
unknown MAC, because the unknown devices can be everywhere. This mode
is default for ng_bridge(4).

In the case of dedicated uplink ports, which prohibit learning of MAC
addresses in order to save memory and CPU cycles, the broadcast
approach is dangerous. All traffic to the uplink port is broadcasted
to every downlink port, too. In this case, it's better to restrict the
distribution of frames to unknown MAC to the uplink ports only.

In order to keep the chance small and the handling as natural as
possible, the first attached link is used to determine the behaviour
of the bridge: If it is an "uplink" port, then the bridge switch from
classical mode to restricted mode.

Reviewed By:	kp
Approved by:	kp (mentor)
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28487
2021-02-06 15:01:15 +01:00
Lutz Donnerhacke f961caf218 netgraph/ng_bridge: Introduce "uplink" ports without MAC learning
The ng_bridge(4) node is designed to work in moderately small
environments. Connecting such a node to a larger network rapidly fills
the MAC table for no reason. It even become complicated to obtain data
from the gettable message, because the result is too large to
transmit.

This patch introduces, two new functionality bits on the hooks:
  - Allow or disallow MAC address learning for incoming patckets.
  - Allow or disallow sending unknown MACs through this hook.

Uplinks are characterized by denied learing while sending out
unknowns. Normal links are charaterized by allowed learning and
sending out unknowns.

Reviewed by:	kp
Approved by:	kp (mentor)
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D23963
2021-02-06 11:09:26 +01:00
Lutz Donnerhacke ebc61c86b5 netgraph/ng_source: Switch queuing framework
Change the queuing framework from ifq to mbufq.

Reported by:	glebius
Reviewed by:	glebius, kp
Approved by:	kp (mentor)
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D28407
2021-01-29 12:34:53 +01:00
Lutz Donnerhacke d0d2e523ba netgraph/ng_car: Add color marking code
Chained policing should be able to reuse the classification of
traffic.  A new mbuf_tag type is defined to handle gereral QoS
marking.  A new subtype is defined to track the color marking.

Reviewed by:	manpages (bcr), melifaro, kp
Approved by:	kp (mentor)
Sponsored by:	IKS Service GmbH
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D22110
2021-01-27 21:22:51 +01:00
Lutz Donnerhacke cfd6422a52 netgraph/ng_vlan_rotate: IEEE 802.1ad VLAN manipulation netgraph type
This node is part of an A10-NSP (L2-BSA) development.

Carrier networks tend to stack three or more tags for internal
purposes and therefore hiding the service tags deep inside of the
stack. When decomposing such an access network frame, the processing
order is typically reversed: First distinguish by service, than by
other means.

This new netgragh node allows to bring the relevant VLAN in front (to
the out-most position). This way other netgraph nodes (like ng_vlan)
can operate on this specific type.

Reviewed by:	manpages (gbe), brueffer (manpages), kp
Approved by:	kp (mentor)
MFC after:	1 month
Relnotes:	yes
Sponsored by:	IKS Service GmbH
Differential Revision: https://reviews.freebsd.org/D22076
2021-01-26 16:53:24 +01:00
Neel Chauhan 5fe433a6e4 netgraph/ng_nat: Add RFC 6598/Carrier Grade NAT support
This extends upon the RFC 6598 support to libalias/ipfw in r357092.

Reviewed By:	manpages (bcr), donner, adrian, kp
Approved by:	kp (mentor)
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D23461
2021-01-24 20:38:35 +01:00
Lutz Donnerhacke d7dd28bb09 netgraph/ng_source: If queue is full, don't enqueue
Submitted by: nc
Reviewed by: donner, kp
Approved by: kp (mentor)
Differential Revision: https://reviews.freebsd.org/D23477
2021-01-23 18:54:47 +01:00
Lutz Donnerhacke c3e75b6c1a netgraph/ng_one2main: Clarification in comments about copy mode
The original comment suggests an optimization, which was proven wrong.

Reported by:	nc
Reviewed by:	kp, nc
Approved by:	kp (mentor)
Differential Revision:	https://reviews.freebsd.org/D23727
2021-01-18 14:10:34 +01:00
Lutz Donnerhacke 7c7c231c14 netgraph/ng_tag: permit variable length data
ng_tag(4) operate on arbitrary data of mbuf_tags(9).  Those structures
are padded to the next multiple of the alignment by the compiler.
Hence a valid argument has be at most as long as the data received.

PR:		241462
Reviewed by:	kp
Approved by:	kp (mentor)
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D22140
2021-01-18 13:23:22 +01:00
Lutz Donnerhacke 75e7ef74df netgraph/ng_source: Allow ng_source to inject into any netgraph network
PR:		240530
Reviewed by:	kp
Approved by:	kp (mentor)
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D21968
2021-01-17 22:17:01 +01:00
Warner Losh 23e124c78b pccard: Remove bt3c(4) driver
pccard is being removed, so remove bt3c driver since it only has PC
Card attachment. Also remove bt3cfw(8) since it's the firmware for this
driver.

Relnotes: Yes
2021-01-07 20:40:41 -07:00
Alexander V. Chernikov 4e19e0d92a Use light-weight versions of routing lookup functions in ng_netflow.
Use recently-added combination of `fib[46]_lookup_rt()` which
 returns rtentry & raw nexthop with `rt_get_inet[6]_plen()` which
 returns address/prefix length of prefix inside `rt`.

Add `nhop_select_func()` wrapper around inlined `nhop_select()` to
 allow callers external to the routing subsystem select the proper
 nexthop from the multipath group without including internal headers.

New calls does not require reference counting objects and reduce
 the amount of copied/processed rtentry data.

Differential Revision: https://reviews.freebsd.org/D27675
2020-12-26 11:27:38 +00:00
Mark Johnston cd698c5179 netgraph: Fix ng_ether's shutdown handing
When tearing down a VNET, netgraph sends shutdown messages to all of the
nodes before detaching interfaces (SI_SUB_NETGRAPH comes before
SI_SUB_INIT_IF in teardown order).  ng_ether nodes handle this by
destroying themselves without detaching from the parent ifnet.  Then,
when ifnets go away they detach their ng_ether nodes again, triggering a
use-after-free.

Handle this by modifying ng_ether_shutdown() to detach from the ifnet.
If the shutdown was triggered by an ifnet being destroyed, we will clear
priv->ifp in the ng_ether detach callback, so priv->ifp may be NULL.

Also get rid of the printf in vnet_netgraph_uninit().  It can be
triggered trivially by ng_ether since ng_ether_shutdown() persists the
node unless NG_REALLY_DIE is set.

PR:		233622
Reviewed by:	afedorov, kp, Lutz Donnerhacke
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D27662
2020-12-23 00:12:16 -05:00
Aleksandr Fedorov 3326f7e9bb [ng_socket] Don't take the SOCKBUF_LOCK() twice in the RX data path.
This is just a minor optimization, but it's sensitive. This gives an improvement of 30-50 kpps.

Reviewed by:	kp, markj, glebius, lutz_donnerhacke.de
Approved by:	vmaffione (mentor)
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D27382
2020-12-17 18:15:07 +00:00
Kyle Evans 02354beae7 netgraph: macfilter: small fixes
Two issues:
- The DEBUG macro defined is in direct conflict with the DEBUG kernel
  option, which broke the -LINT build[0]
- Building with NG_MACFILTER_DEBUG did not compile on LP64 systems due to
  using %d for sizeof().

Reported by:	Jenkins[0]
2020-12-09 15:28:56 +00:00
Nick Hibma e8db04c389 New Netgraph module ng_macfilter:
Macfilter to route packets through different hooks based on sender MAC address.

Based on ng_macfilter written by Pekka Nikander

Sponsered by Retina b.v.

Reviewed by:	afedorov
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27268
2020-12-08 15:09:42 +00:00
Eugene Grosbein 3ff4b31749 ng_nat: unbreak ABI
The revision r342168 broke ABI of ng_nat needlessly and
the change was merged to stable branches breaking ABI there, too.
Unbreak it.

PR:		250722
MFC after:	1 week
2020-11-10 02:26:44 +00:00
Mark Johnston e62e4b8594 ng_l2tp: Fix callout synchronization in the rexmit timeout handler
A received control packet may cause the transmit queue to be flushed, in
which case ng_l2tp_seq_recv_nr() cancels the transmit timeout handler.
The handler checks to see if it was cancelled before doing anything, but
did so before acquiring the node lock, so a small race window could
cause ng_l2tp_seq_rack_timeout() to attempt to flush an empty queue,
ultimately causing a null pointer dereference.

PR:		241133
Reviewed by:	bz, glebius, Lutz Donnerhacke
MFC after:	3 days
Sponsored by:	Rubicon Communications, LLC (Netgate)
Differential Revision:	https://reviews.freebsd.org/D26548
2020-09-25 18:55:50 +00:00
Kristof Provost 51e805c43c ng_ether: Enter NET_EPOCH where required
We must enter NET_EPOCH before calling ether_output_frame(). Several of the
functions it calls (pfil_run_hooks, if_transmit) expect to be running in the
NET_EPOCH.

While here remove an unneeded EPOCH entry (which wasn't wide enough to cover
BRIDGE_INPUT).

PR:		248958
Reviewed by:	glebius, bz (previous version), melifaro (previous version)
Tested by:	manu
Differential Revision:	https://reviews.freebsd.org/D26226
2020-09-02 11:49:22 +00:00
Mateusz Guzik 662c13053f net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
Mark Johnston 3a3992fb86 ng_ubt: Add a device ID.
PR:		248838
Submitted by:	Andrey Zholos <aaz@q-fu.com>
MFC after:	1 week
2020-08-23 19:30:06 +00:00
Warner Losh e0d14216c1 Tag pccard drivers with gone in 13.
MFC After: 3 days
Reviewed by: emaste, brooks, adrian (on twitter)
Differential Revision: https://reviews.freebsd.org/D26095
2020-08-20 17:19:40 +00:00
Marko Zec eeed0c98a1 Increase BER to PER lookup table size in an attempt to mitigate panics
with LRO and TSO.

Reported by:    rstone
2020-08-18 22:46:46 +00:00
Mark Johnston 370b7cc904 ng_iface(4): Remove unsupported protocols.
Update the ng_iface documentation and hooks to reflect the fact that the
node currently only supports IPv4 and v6 packets.

Reviewed by:	Lutz Donnerhacke
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25862
2020-07-31 14:08:54 +00:00
Mark Johnston 460a9f9d45 ng_iface(4): Set the current VNET before calling netisr_dispatch().
This is normally handled by a netgraph thread, but netgraph messages may
be dispatched directly to a node, in which case no VNET is set before
ng_iface calls into the network stack.  Netgraph could probably handle
this more generally, but for now just be sure to set the current VNET in
ng_iface.

PR:		242406
Tested by:	Michael Muenz <m.muenz@gmail.com>
Reviewed by:	Lutz Donnerhacke
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D25788
2020-07-31 14:08:32 +00:00
Takanori Watanabe b8c46d561e Fix L2CAP ACL packet PB(Packet Boundary) flag for LE PDU.
ACL packet boundary flag should be 0 instead of 2 for LE PDU.
Some HCI will drop LE packet with PB flag is 2, and if sent,
some target may reject the packet.

PR:	248024
Reported by:	Greg V
Reviewed by:	Greg V, emax
Differential Revision:	https://reviews.freebsd.org/D25704
2020-07-17 15:50:03 +00:00
Takanori Watanabe de402d6322 Add support for [read|write] supported data length commands.
Fix ng_hci_le_long_term_key_request_negative_reply_cp struct
while here.

PR:	247809
Submitted by:	Marc Veldman
2020-07-08 06:33:07 +00:00