Commit graph

1440 commits

Author SHA1 Message Date
Eugene Grosbein
5c332527d1 ng_pppoe: introduce new sysctl net.graph.pppoe.lcp_pcp
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

(cherry picked from commit 2e547442ab)
(cherry picked from commit 28903f396a)
2022-05-16 09:31:56 +07:00
John Baldwin
648ce75c3b 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.

(cherry picked from commit 6d5f002ed1)
2022-05-13 13:13:49 -07:00
Gordon Bergling
61124bbbf6 netgraph(3): Remove a double word in a source code comment
- s/it it/it/

(cherry picked from commit ecbdfbfd18)
2022-04-14 08:15:38 +02:00
Gordon Bergling
128cd1a6a7 netgraph(4): Fix a typo in a source code comment
- s/peform/perform/

(cherry picked from commit 77a44875e5)
2022-04-14 08:03:22 +02:00
Gordon Bergling
d9d5b11797 ng_btsocket(4): Fix a typo in an error message
- s/mulitplexor/multiplexor/

(cherry picked from commit f64919bbd9)
2022-04-11 05:39:10 +02:00
Gordon Bergling
a13ef0bfb0 ng_pppoe(4): Fix a typo in a source code comment
- s/asychronous/asynchronous/

(cherry picked from commit 7fc0ffda35)
2022-04-09 08:06:23 +02:00
Gordon Bergling
12464ec2ef netgraph(3): Fix a typo in a source code comment
- s/failes/fails/

(cherry picked from commit 79438267b3)
2022-04-02 15:29:26 +02:00
Gordon Bergling
1dca9345e9 netgraph(4): Fix a typo in a source code comment
- s/shapshot/snapshot/

(cherry picked from commit 1dc2c71ed8)
2022-03-30 18:36:36 +02:00
Aleksandr Fedorov
85cd9f7e98 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

(cherry picked from commit b27e6e91d0)
2022-02-13 15:05:45 +03:00
Ian Lepore
1a86aab86a 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

(cherry picked from commit 44aae623ab)
2022-01-14 14:28:43 +01:00
Alexander Motin
c63fc5265b netgraph: Remove CTLFLAG_NEEDGIANT from sysctl.
MFC after:	2 weeks

(cherry picked from commit 2f1a46d12b)
2022-01-09 19:30:03 -05:00
Hans Petter Selasky
7b976be508 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
Sponsored by:	NVIDIA Networking

(cherry picked from commit 67cbbf1959)
(cherry picked from commit 03f0393477)
(cherry picked from commit 8fa952937b)
2022-01-07 14:23:10 +01:00
Gleb Smirnoff
42301a9db1 ng_l2tp: improve seq structure locking.
PR:			241133
Reviewed by:		mjg, markj
Differential Revision:	https://reviews.freebsd.org/D31476
Author:			glebius

(cherry picked from commit 0a76c63dd4)
(cherry picked from commit 89042ff776)
(cherry picked from commit ae04d30451)
2021-12-20 01:21:38 +07:00
Mark Johnston
d74c589ead 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

(cherry picked from commit b25ba58adc)
2021-12-13 08:26:19 -05:00
Mitchell Horne
1d640e6135 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

(cherry picked from commit 0d2224733e)
2021-12-07 14:13:47 -04:00
Gordon Bergling
beaf14a65b ng_pptpgre(4): Fix a typo in a source code comment
- s/mimimum/minimum/

(cherry picked from commit 40a57b00f9)
2021-11-06 08:50:54 +01:00
Gordon Bergling
9b918d1761 ng_ppp(4): Fix a typo in a comment
- s/delcared/declared/

(cherry picked from commit 0a8159d8ca)
2021-10-17 10:35:19 +02:00
Yoshihiro Takahashi
e089402431 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().

(cherry picked from commit d653b188e8)
2021-10-02 20:51:14 +09:00
Zhenlei Huang
e8df60a69a 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

(cherry picked from commit 62e1a437f3)
2021-09-07 21:25:06 +00:00
Alexander V. Chernikov
36854c4e1e [netflow] fix gateway reporting in ng_netflow
Reported by:	Guy Yur <guyyur at gmail.com>

(cherry picked from commit 8e55a80e0c)
2021-09-07 21:02:57 +00:00
Mark Johnston
8ad5619ec3 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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e0e3ded78a)
2021-08-20 08:42:43 -04:00
Gordon Bergling
a6bc738260 Fix a few typos in source code comments
- s/posbile/possible/

(cherry picked from commit 34f620f1d0)
2021-08-19 09:29:25 +02:00
Roy Marples
f452713408 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

(cherry picked from commit 7045b1603b)
2021-08-10 18:54:00 -07:00
Mark Johnston
46d8116cae 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.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f4bb1869dd)
2021-06-21 09:14:40 -04:00
Lutz Donnerhacke
ad2c95130b 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
Differential Revision: https://reviews.freebsd.org/D30759

(cherry picked from commit 4c3280e587)
2021-06-16 23:55:35 +02:00
Lutz Donnerhacke
37370a6773 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
Differential Revision: https://reviews.freebsd.org/D30110

(cherry picked from commit 0345fd891f)
2021-06-10 11:29:34 +02:00
Takanori Watanabe
26c3e7a1ec Fix a use-after-free in an error case.
PR: 255872
Submitted by:  lylgood
Differential Revision:  https://reviews.freebsd.org/D30454

(cherry picked from commit 14803ec8d1)
2021-06-09 14:20:57 +09:00
Markus Stoff
f18b7f239d 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
Differential Revision: https://reviews.freebsd.org/D26489

(cherry picked from commit 63b6a08ce2)
2021-06-08 12:14:34 +02:00
Alexander Motin
6ee59ffb5b 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

(cherry picked from commit 4a6830761c)
2021-06-01 23:40:05 -04:00
Lutz Donnerhacke
7fd88ba72e 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
Differential Revision:	https://reviews.freebsd.org/D28601

(cherry picked from commit 4dfe70fdbd)
2021-05-27 12:55:52 +02:00
Lutz Donnerhacke
fb5e2f4d61 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.

Differential Revision:	https://reviews.freebsd.org/D28123

(cherry picked from commit 9674c2e68c)
2021-05-27 12:55:44 +02:00
Lutz Donnerhacke
cab6109379 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)
Differential Revision:	https://reviews.freebsd.org/D28559

(cherry picked from commit f6e0c47169)
2021-05-27 12:55:37 +02:00
Lutz Donnerhacke
53ccd92495 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)
Differential Revision:	https://reviews.freebsd.org/D28516

(cherry picked from commit b1bd44732d)
2021-05-27 12:55:29 +02:00
Lutz Donnerhacke
fa670efa25 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
Differential Revision: https://reviews.freebsd.org/D30273

(cherry picked from commit 687e510e5c)
2021-05-23 14:55:20 +02:00
Lutz Donnerhacke
e240dd0d50 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
Differential Revision: https://reviews.freebsd.org/D30008

(cherry picked from commit a56e5ad690)
2021-05-20 07:52:21 +02:00
Mark Johnston
1e066db6cd 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
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29519

(cherry picked from commit f161d294b9)
2021-05-17 13:43:07 -04:00
Lutz Donnerhacke
2b3074de33 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

(cherry picked from commit 45d75e3ac3)
2021-05-09 15:25:05 +02:00
Vladimir Kondratyev
83235903d5 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
2021-04-30 23:14:44 +03:00
Vladimir Kondratyev
3f5ce99dc6 ng_ubt: Use DEFINE_CLASS_1 macro for kobj inheritance. 2021-04-30 23:14:38 +03:00
Vladimir Kondratyev
ad711fa497 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
Differential revision:	https://reviews.freebsd.org/D29775
2021-04-30 23:12:41 +03:00
Lutz Donnerhacke
26be401728 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
Sponsored by:	IKS Service GmbH
Differential Revision: https://reviews.freebsd.org/D22110

(cherry picked from commit d0d2e523ba)
2021-02-26 13:29:39 +01:00
Neel Chauhan
d65b86dd93 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
Differential Revision: https://reviews.freebsd.org/D23461

(cherry picked from commit 5fe433a6e4)
2021-02-25 11:21:03 +01:00
Lutz Donnerhacke
522a0b7d02 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
Relnotes:	yes
Sponsored by:	IKS Service GmbH
Differential Revision: https://reviews.freebsd.org/D22076

(cherry picked from commit cfd6422a52)
2021-02-25 09:04:24 +01:00
Lutz Donnerhacke
dcb4190179 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
Differential Revision: https://reviews.freebsd.org/D28537

(cherry picked from commit 3c958f5fdf)
2021-02-22 09:22:03 +01:00
Lutz Donnerhacke
88e916bff0 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
Differential Revision: https://reviews.freebsd.org/D28546

(cherry picked from commit 011b7317db)
2021-02-22 09:21:55 +01:00
Lutz Donnerhacke
0952f69003 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
Differential Revision: https://reviews.freebsd.org/D28545

(cherry picked from commit ccf4cd2e78)
2021-02-22 09:21:49 +01:00
Lutz Donnerhacke
1e2c1b7622 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
Differential Revision: https://reviews.freebsd.org/D28141

(cherry picked from commit 6117aa58fa)
2021-02-22 09:21:23 +01:00
Lutz Donnerhacke
d7187b4b1c 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
Differential Revision: https://reviews.freebsd.org/D28125

(cherry picked from commit 66c72859f6)
2021-02-22 09:21:13 +01:00
Lutz Donnerhacke
8135f3f2fc 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
Differential Revision: https://reviews.freebsd.org/D28487

(cherry picked from commit c869d905ba)
2021-02-22 09:21:04 +01:00
Lutz Donnerhacke
882cbdeb21 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
Differential Revision: https://reviews.freebsd.org/D23963

(cherry picked from commit f961caf218)
2021-02-22 09:20:37 +01:00