Commit graph

1518 commits

Author SHA1 Message Date
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
Takanori Watanabe 263a104f43 Allow some Bluetooth LE related HCI request to non-root user.
PR:	247588
Reported by:	Greg V (greg@unrelenting.technology)
Reviewed by:	emax
Differential Revision:	https://reviews.freebsd.org/D25516
2020-07-01 04:00:54 +00:00
Takanori Watanabe ccb9fc3218 Update event masks constant to Bluetooth core spec V5.2
and add LE Events.

PR: 247257
Submitted by:	Marc Veldman
2020-06-15 14:58:40 +00:00
Takanori Watanabe 7a33c92b43 Add LE events:
READ_REMOTE_FEATURES_COMPL
LONG_TERM_KEY_REQUEST
REMOTE_CONN_PARAM_REQUEST
DATA_LENGTH_CHANGE
READ_LOCAL_P256_PK_COMPL
GEN_DHKEY_COMPL
ENH_CONN_COMPL

PR: 247050
Submitted by:	Marc Veldman marc at bumblingdork.com
2020-06-10 04:54:02 +00:00
Hans Petter Selasky 4ac6682cab Fix check for wMaxPacketSize in USB bluetooth driver,
in case device is not FULL speed.

MFC after:	3 days
Sponsored by:	Mellanox Technologies
2020-05-28 08:41:18 +00:00
Takanori Watanabe 022f27959e Fix Typo in ng_hci_le_connection_complete_ep struct.
PR:	246538
Submitted by:	Marc Veldman
2020-05-19 13:58:52 +00:00
Takanori Watanabe 75afc548cb Add space for RSSI in data member.
RSSI is put just after actual data.

Submitted by: Marc Veldman
PR: 245920
2020-05-09 14:15:44 +00:00
Takanori Watanabe 1f5d883dd7 Add le_read_buffer_size command and manpage.
It supports both v1 and v2 command.

PR:245964
Submitted by:	Marc Veldman <marc@bumblingdork.com>
2020-04-28 16:00:34 +00:00
Aleksandr Fedorov cade08387c ng_eiface: fix kernel panic due to the racecondition in ng_eiface shutdown.
PR:		244247
Reported by:	Vladislav V. Prodan <admin@support.od.ua>
Reviewed by:	vmaffione, lutz_donnerhacke.de
Approved by:	vmaffione (mentor)
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D24557
2020-04-27 10:00:46 +00:00
Hans Petter Selasky 21eefd310a Substitute le_read_supported_status with le_read_supported_states.
Refer to bluetooth core v5.2 specifications Vol4. Part E. 7.8.27.

PR:		245763
Submitted by:	Marc Veldman <marc@bumblingdork.com>
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-04-20 13:44:14 +00:00
Hans Petter Selasky 3bc36313e4 Bring HCI error messages up-to-date.
See Bluetooth v5.6 core specification Vol.1 Part F: Controller error codes.

Submitted by:	Marc Veldman <marc@bumblingdork.com>
PR:		245737
MFC after:	1 week
Sponsored by:	Mellanox Technologies
2020-04-19 10:24:15 +00:00
Kyle Evans 23d5326823 tty: convert tty_lock_assert to tty_assert_locked to hide lock type
A later change, currently being iterated on in D24459, will in-fact change
the lock type to an sx so that TTY drivers can sleep on it if they need to.
Committing this ahead of time to make the review in question a little more
palatable.

tty_lock_assert() is unfortunately still needed for now in two places to
make sure that the tty lock has not been recursed upon, for those scenarios
where it's supplied by the TTY driver and possibly a mutex that is allowed
to recurse.

Suggested by:	markj
2020-04-17 18:34:49 +00:00
Gleb Smirnoff 2ffded5e53 Don't initialize m->m_data to m->m_pktdat, this is already done by the
mbuf allocator.  That was the last remnant of such code in the kernel.
2020-04-17 05:59:38 +00:00
Takanori Watanabe 3cba89e6f8 Fix mbuf handling in le advertize packet processing.
Submitted by: Marc Veldman <marc at bumblingdork.com>
2020-04-02 09:15:31 +00:00
Gleb Smirnoff def4e701e5 Fix spelling of "dropped".
Submitted by:	Lutz Donnerhacke
Differential Revision:	https://reviews.freebsd.org/D23954
2020-03-04 22:32:40 +00:00
Pawel Biernacki 7029da5c36 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2020-02-26 14:26:36 +00:00
Gleb Smirnoff 039eb22c0a Rework second part of r357558. Unroll the macro and allocate memory in
sleepable manner before entering the epoch for the send.
2020-02-21 04:18:15 +00:00
Gleb Smirnoff be3d57e69b Revert one half of previous change r357558. Don't enter the epoch on
sends to control socket.  Control socket messages can run constructors
of nodes and other stuff that is allowed to M_WAITOK.

PR:		244241
2020-02-21 04:10:41 +00:00
Eugene Grosbein 49f384cb47 ng_nat: avoid panic if attached directly to ng_ether and got short packet
From the beginning, ng_nat safely assumed cleansed traffic
because of limited ways it could be attached to NETGRAPH:
ng_ipfw or ng_ppp only.

Now as it may be attached with ng_ether too, the assumption proven wrong.
Add needed check to the ng_nat. Thanks for markj for debugging this.

PR:		243096
Submitted by:	Lutz Donnerhacke <lutz@donnerhacke.de>
Reported by:	Robert James Hernandez <rob@sarcasticadmin.com>
Reviewed by:	markj and others
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D23091
2020-02-12 00:31:00 +00:00
Gleb Smirnoff f71291a65e I doubt anybody in the world uses ng_device, but its write method should
also enter the network epoch when sending data from user level to netgraph.
2020-02-05 03:07:20 +00:00
Gleb Smirnoff 940508a5be Enter the network epoch when ng_socket sends data or control from user
land to the netgraph and potentially further down the network stack.
2020-02-05 03:06:29 +00:00
Gleb Smirnoff 4c02c20c32 netgraph(4) callouts need to be executed in the network epoch. 2020-02-05 02:53:40 +00:00
Mark Johnston 66351f5126 ng_nat: Pass IPv6 packets through.
ng_nat implements NAT for IPv4 traffic only.  When connected to an
ng_ether node it erroneously handled IPv6 packets as well.

This change is not sufficient: ng_nat does not do any validation of IP
packets in this mode, even though they have not yet passed through
ip_input().

PR:		243096
Reported by:	Robert James Hernandez <rob@sarcasticadmin.com>
Reviewed by:	julian
Differential Revision:	https://reviews.freebsd.org/D23080
2020-01-23 16:45:48 +00:00
Kirill Ponomarev bc6e80ddc1 Generate MAC address from the FreeBSD OUI range.
Submitted by:	aleksandr.fedorov_vstack_com
Approved by:	kevans
Differential Revision:	https://reviews.freebsd.org/D23168
2020-01-16 20:12:15 +00:00
Gleb Smirnoff 35e67a79fb Netgraph queue processing thread must process all its items
in the network epoch.

Reported by:	Michael Zhilin <mizhka@ >
2020-01-15 03:35:57 +00:00
Bjoern A. Zeeb aeaef7d597 netgraph/ng_bridge: Reestablish old ABI
In order to be able to merge r353026 bring back support for the old
cookie API for a transition period in 12.x releases (and possibly 13)
before the old API can be removed again entirely.

Suggested by:	julian
Submitted by:	Lutz Donnerhacke (lutz donnerhacke.de)
PR:		240787
Reviewed by:	julian
MFC after:	2 weeks
X-MFC with:	r353026
Differential Revision:	https://reviews.freebsd.org/D21961
2020-01-05 19:14:16 +00:00
John Baldwin 4b28d96e5d Remove the deprecated timeout(9) interface.
All in-tree consumers have been converted to callout(9).

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D22602
2019-12-13 21:03:12 +00:00
John Baldwin 5773ac113c Use callout_func_t instead of the deprecated timeout_t.
Reviewed by:	kib, imp
Differential Revision:	https://reviews.freebsd.org/D22752
2019-12-10 22:06:53 +00:00
Gleb Smirnoff abc4b11cea Fix regression from r353026. Pointer was increased instead of value
pointed to.

PR:		241646
Submitted by:	Aleksandr Fedorov <aleksandr.fedorov itglobal.com>
2019-11-02 03:09:17 +00:00
Gleb Smirnoff ebded7d547 Don't use if_maddr_rlock() in ng_eiface(4), use epoch(9) directly instead. 2019-10-10 23:49:19 +00:00
Gleb Smirnoff 57985d11b4 Don't use if_maddr_rlock() in ng_ether(4), use epoch(9) directly instead. 2019-10-10 23:47:14 +00:00
Gleb Smirnoff b8a6e03fac Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.

However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.

Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.

On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().

This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.

Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.

This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.

Reviewed by:	gallatin, hselasky, cy, adrian, kristof
Differential Revision:	https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
Gleb Smirnoff 0b951c55a1 Fix build failure from r353026. Somehow module build allowed this.
Pointy hat to:	glebius
2019-10-03 04:41:57 +00:00
Gleb Smirnoff 30b7addf5a Protect access to seq->xwin[] with the seq mutex.
MFC after:	5 weeks
2019-10-03 02:34:51 +00:00
Gleb Smirnoff 631cabba47 - Remove the compile time limit for number of links a ng_bridge node
can handle.  Instead using an array on node private data, use per-hook
  private data.
- Use NG_NODE_FOREACH_HOOK() to traverse through hooks instead of array.

PR:		240787
Submitted by:	Lutz Donnerhacke <lutz donnerhacke.de>
Differential Revision:	  https://reviews.freebsd.org/D21803
2019-10-03 02:32:55 +00:00
Maksim Yevmenkin 444e5d09b5 avoid holding PCB mutex during copyin/copyout()
Reported by:	imp, mms dot vanbreukelingen at gmail dot com
Reviewed by:	imp
2019-08-30 16:35:31 +00:00
Xin LI 34ff55b662 Convert ng_deflate to use new zlib.
This removes the last consumer of the modified zlib originally
bundled with Paul's PPP implementation, which will be removed
in a follow up commit.

PR:			229763
Differential Revision:	https://reviews.freebsd.org/D21186
2019-08-23 07:24:36 +00:00
Xin LI 443127c517 Use MTX_NEW instead of bzero().
Submitted by:	cem
2019-08-21 08:15:30 +00:00
Xin LI ee318606ce Fix a panic in ubt_do_hci_request.
The 'mtx' is on stack and can contain garbages that would cause mtx_init
(and in turn lock_init) to think that the mutex was already initialized.
2019-08-21 07:45:39 +00:00
Vladimir Kondratyev 3544d43bb1 ng_ubt(4): do not attach Intel Wireless 8260/8265 in bootloader mode.
Add helper function for synchronous execution of HCI commands at probe
stage and use this function to check firmware state of Intel Wireless
8260/8265 bluetooth devices found in many post 2016 year laptops.

Attempt to initialize FreeBSD bluetooth stack while such a device is in
bootloader mode locks the adapter hardly so it requires power on/off
cycle to restore.

This change blocks ng_ubt attachment unless operational firmware is
loaded thus preventing the lock up.

PR:			237083
Reviewed by:		hps, emax
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D21071
2019-08-18 22:11:42 +00:00
Gleb Smirnoff cef9f220cd Remove 'dir' argument in ng_ipfw_input, since ip_fw_args now has this info.
While here make 'tee' boolean.
2019-03-14 22:30:05 +00:00
Gleb Smirnoff 7d3df83cfa Remove remnants of byte order manipulation, back when FreeBSD stack
stored packets in host byte order.
2019-02-09 03:00:00 +00:00
Gleb Smirnoff 938864b71b Allow some nesting of ng_iface(4) interfaces and add a configuration knob.
PR:		235500
MFC after:	1 week
2019-02-08 06:19:28 +00:00
Maxim Sobolev b7841ae650 Allow ng_nat to be attached to a ethernet interface directly via ng_ether(4)
or the likes. Add new control message types: setdlt and getdlt to switch
from default DLT_RAW (no encapsulation) to DLT_EN10MB (ethernet).

Approved by:	glebius
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D18535
2018-12-17 16:00:35 +00:00
Eugene Grosbein f8edc37316 ng_source(4): correction after the change r340617
tv_usec has "long" type for all architecture in FreeBSD
and follows __LP64__. However, this is not true for tv_sec
that has "time_t" type.

Since r320347 that changed time_t from 32 to 64 bit integer
for 32 bit version of powerpc architecture, we have only single
i386 architecture having 32 bit time_t type.

Submitted by:	jhb
MFC after:	1 week.
2018-11-27 04:05:38 +00:00
Eugene Grosbein d642b94209 Unbreak ng_source(4) for 64-bit platforms including amd64. 2018-11-19 07:27:50 +00:00
Eugene Grosbein a594f9453b Make ng_pptpgre(8) netgraph node be able to restore order for packets
reordered in transit instead of dropping them altogether.
It uses sequence numbers of PPtPGRE packets.

A set of new sysctl(8) added to control this ability or disable it:

net.graph.pptpgre.reorder_max (1) defines maximum length of node's
private reorder queue used to keep data waiting for late packets.
Zero value disables reordering. Default value 1 allows the node to restore
the order for two packets swapped in transit. Greater values allow the node
to deliver packets being late after more packets in sequence
at cost of increased kernel memory usage.

net.graph.pptpgre.reorder_timeout (1) defines time value in miliseconds
used to wait for late packets. It may be useful to increase this
if reordering spot is distant.

MFC after:	1 month
2018-11-04 19:10:44 +00:00
Mark Murray 19fa89e938 Remove the Yarrow PRNG algorithm option in accordance with due notice
given in random(4).

This includes updating of the relevant man pages, and no-longer-used
harvesting parameters.

Ensure that the pseudo-unit-test still does something useful, now also
with the "other" algorithm instead of Yarrow.

PR:		230870
Reviewed by:	cem
Approved by:	so(delphij,gtetlow)
Approved by:	re(marius)
Differential Revision:	https://reviews.freebsd.org/D16898
2018-08-26 12:51:46 +00:00
Alexander Motin 8805f3d7be Remove extra M_ZERO from NG_MKRESPONSE() argument.
NG_MKRESPONSE() sets M_ZERO by itself.

Submitted by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after:	1 week
2018-08-20 14:35:54 +00:00
Luiz Otavio O Souza 02fd7b50a0 The interface name must be sanitized before the search to match the existing
netgraph node.

Fixes the search (and use) of VLANs with dot notation.

Obtained from:	pfSense
Sponsored by:	Rubicon Communications, LLC (Netgate)
2018-08-15 13:42:22 +00:00
Gleb Smirnoff 86b4ad7dd5 Use if_tunnel_check_nesting() for ng_iface(4). 2018-08-03 22:55:58 +00:00
Andrew Turner 5f901c92a8 Use the new VNET_DEFINE_STATIC macro when we are defining static VNET
variables.

Reviewed by:	bz
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D16147
2018-07-24 16:35:52 +00:00
John Baldwin 4560b78de2 Catch up two more places to the V_ifnet change to a CK_STAILQ. 2018-05-24 00:06:55 +00:00
Matt Macy d7c5a620e2 ifnet: Replace if_addr_lock rwlock with epoch + mutex
Run on LLNW canaries and tested by pho@

gallatin:
Using a 14-core, 28-HTT single socket E5-2697 v3 with a 40GbE MLX5
based ConnectX 4-LX NIC, I see an almost 12% improvement in received
packet rate, and a larger improvement in bytes delivered all the way
to userspace.

When the host receiving 64 streams of netperf -H $DUT -t UDP_STREAM -- -m 1,
I see, using nstat -I mce0 1 before the patch:

InMpps OMpps  InGbs  OGbs err TCP Est %CPU syscalls csw     irq GBfree
4.98   0.00   4.42   0.00 4235592     33   83.80 4720653 2149771   1235 247.32
4.73   0.00   4.20   0.00 4025260     33   82.99 4724900 2139833   1204 247.32
4.72   0.00   4.20   0.00 4035252     33   82.14 4719162 2132023   1264 247.32
4.71   0.00   4.21   0.00 4073206     33   83.68 4744973 2123317   1347 247.32
4.72   0.00   4.21   0.00 4061118     33   80.82 4713615 2188091   1490 247.32
4.72   0.00   4.21   0.00 4051675     33   85.29 4727399 2109011   1205 247.32
4.73   0.00   4.21   0.00 4039056     33   84.65 4724735 2102603   1053 247.32

After the patch

InMpps OMpps  InGbs  OGbs err TCP Est %CPU syscalls csw     irq GBfree
5.43   0.00   4.20   0.00 3313143     33   84.96 5434214 1900162   2656 245.51
5.43   0.00   4.20   0.00 3308527     33   85.24 5439695 1809382   2521 245.51
5.42   0.00   4.19   0.00 3316778     33   87.54 5416028 1805835   2256 245.51
5.42   0.00   4.19   0.00 3317673     33   90.44 5426044 1763056   2332 245.51
5.42   0.00   4.19   0.00 3314839     33   88.11 5435732 1792218   2499 245.52
5.44   0.00   4.19   0.00 3293228     33   91.84 5426301 1668597   2121 245.52

Similarly, netperf reports 230Mb/s before the patch, and 270Mb/s after the patch

Reviewed by:	gallatin
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D15366
2018-05-18 20:13:34 +00:00
Ed Maste 315fbaeca2 Correct pseudo misspelling in sys/ comments
contrib code and #define in intel_ata.h unchanged.
2018-02-23 18:15:50 +00:00
Eugene Grosbein 8be8c75688 ng_pppoe(8): add support for user-supplied Host-Uniq tag.
A few ISP filter PADI requests based on such tag,
to force the use of their own routers.
The custom Host-Uniq tag is passed in the NGM_PPPOE_CONNECT
control message, so it can be used with FreeBSD ppp(8)
and mpd without any other change.

Add support to send and receive PADM messages,
HURL and MOTM, often used by service providers to provide
ACS information and other configuration settings
to the user CPE.

Submitted by:	ale
Approved by:	mav (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D9270
2018-02-14 21:17:44 +00:00
Pedro F. Giffuni ac2fffa4b7 Revert r327828, r327949, r327953, r328016-r328026, r328041:
Uses of mallocarray(9).

The use of mallocarray(9) has rocketed the required swap to build FreeBSD.
This is likely caused by the allocation size attributes which put extra pressure
on the compiler.

Given that most of these checks are superfluous we have to choose better
where to use mallocarray(9). We still have more uses of mallocarray(9) but
hopefully this is enough to bring swap usage to a reasonable level.

Reported by:	wosch
PR:		225197
2018-01-21 15:42:36 +00:00
Pedro F. Giffuni 3b0a4e40a0 netgraph: make some use of mallocarray(9).
Focus on code where we are doing multiplications within malloc(9). None of
these ire likely to overflow, however the change is still useful as some
static checkers can benefit from the allocation attributes we use for
mallocarray.

This initial sweep only covers malloc(9) calls with M_NOWAIT. No good
reason but I started doing the changes before r327796 and at that time it
was convenient to make sure the sorrounding code could handle NULL values.

X-Differential revision: https://reviews.freebsd.org/D13837
2018-01-15 21:19:21 +00:00
Pedro F. Giffuni fe267a5590 sys: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:23:17 +00:00
Eugene Grosbein ab070eb18b Correction after r323873: #include <sys/lock.h> in addition to <sys/rmlock.h>
PR:		220076
Approved by:	mav (mentor)
MFC after:	3 days
2017-09-28 11:26:37 +00:00
Eugene Grosbein 10633c7e5a Unprotected modification of ng_iface(4) private data leads to kernel panic.
Fix a race with per-node read-mostly lock and refcounting for a hook.

PR:			220076
Tested by:		peixoto.cassiano
Approved by:		avg (mentor), mav (mentor)
MFC after:		1 week
Relnotes:		yes
Differential Revision:	https://reviews.freebsd.org/D12435
2017-09-21 20:16:10 +00:00
Gleb Smirnoff 7737de9515 Check return value from soaccept().
Coverity:	1376209
2017-06-14 16:13:20 +00:00
Gleb Smirnoff 779f106aa1 Listening sockets improvements.
o Separate fields of struct socket that belong to listening from
  fields that belong to normal dataflow, and unionize them.  This
  shrinks the structure a bit.
  - Take out selinfo's from the socket buffers into the socket. The
    first reason is to support braindamaged scenario when a socket is
    added to kevent(2) and then listen(2) is cast on it. The second
    reason is that there is future plan to make socket buffers pluggable,
    so that for a dataflow socket a socket buffer can be changed, and
    in this case we also want to keep same selinfos through the lifetime
    of a socket.
  - Remove struct struct so_accf. Since now listening stuff no longer
    affects struct socket size, just move its fields into listening part
    of the union.
  - Provide sol_upcall field and enforce that so_upcall_set() may be called
    only on a dataflow socket, which has buffers, and for listening sockets
    provide solisten_upcall_set().

o Remove ACCEPT_LOCK() global.
  - Add a mutex to socket, to be used instead of socket buffer lock to lock
    fields of struct socket that don't belong to a socket buffer.
  - Allow to acquire two socket locks, but the first one must belong to a
    listening socket.
  - Make soref()/sorele() to use atomic(9).  This allows in some situations
    to do soref() without owning socket lock.  There is place for improvement
    here, it is possible to make sorele() also to lock optionally.
  - Most protocols aren't touched by this change, except UNIX local sockets.
    See below for more information.

o Reduce copy-and-paste in kernel modules that accept connections from
  listening sockets: provide function solisten_dequeue(), and use it in
  the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
  infiniband, rpc.

o UNIX local sockets.
  - Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
    local sockets.  Most races exist around spawning a new socket, when we
    are connecting to a local listening socket.  To cover them, we need to
    hold locks on both PCBs when spawning a third one.  This means holding
    them across sonewconn().  This creates a LOR between pcb locks and
    unp_list_lock.
  - To fix the new LOR, abandon the global unp_list_lock in favor of global
    unp_link_lock.  Indeed, separating these two locks didn't provide us any
    extra parralelism in the UNIX sockets.
  - Now call into uipc_attach() may happen with unp_link_lock hold if, we
    are accepting, or without unp_link_lock in case if we are just creating
    a socket.
  - Another problem in UNIX sockets is that uipc_close() basicly did nothing
    for a listening socket.  The vnode remained opened for connections.  This
    is fixed by removing vnode in uipc_close().  Maybe the right way would be
    to do it for all sockets (not only listening), simply move the vnode
    teardown from uipc_detach() to uipc_close()?

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D9770
2017-06-08 21:30:34 +00:00
Takanori Watanabe 4aa92fe2f3 Make cached Bluetooth LE host advertise information visible from userland.
Differential Revision:	https://reviews.freebsd.org/D10362
2017-04-27 15:03:24 +00:00
Brooks Davis a7dc31283a Remove the NATM framework including the en(4), fatm(4), hatm(4), and
patm(4) devices.

Maintaining an address family and framework has real costs when we make
infrastructure improvements.  In the case of NATM we support no devices
manufactured in the last 20 years and some will not even work in modern
motherboards (some newer devices that patm(4) could be updated to
support apparently exist, but we do not currently have support).

With this change, support remains for some netgraph modules that don't
require NATM support code. It is unclear if all these should remain,
though ng_atmllc certainly stands alone.

Note well: FreeBSD 11 supports NATM and will continue to do so until at
least September 30, 2021.  Improvements to the code in FreeBSD 11 are
certainly welcome.

Reviewed by:	philip
Approved by:	harti
2017-04-24 21:21:49 +00:00
Pedro F. Giffuni ec5753e0eb mppc - Finish pluging NETGRAPH_MPPC_COMPRESSION.
There were several places where reference to compression were left
unfinished. Furthermore, KASSERTs contained references to MPPC_INVALID
which is not defined in the tree and therefore were sure to break with
INVARIANTS: comment them out.

Reported by:	Eugene Grosbein
PR:		216265
MFC after:	3 days
2017-01-20 00:02:11 +00:00
Julian Elischer 426b3d047a Changes to allow the patching of packets with an offset (and other changes.. see man page)
PR:	206185
Submitted by:	Dmitry Vagin <daemon-hammer@ya.ru>
MFC after:	 1 week
Relnotes:	yes (also ng_checksum node)
2016-12-02 10:47:10 +00:00
Hans Petter Selasky 0e493ed3a5 Fix return value from ng_uncallout().
callout_stop() recently started returning -1 when the callout is already
stopped, which is not handled by the netgraph code. Properly filter
the return value. Netgraph callers only want to know if the callout
was cancelled and not draining or already stopped.

Discussed with:		julian, glebius
MFC after:		2 weeks
2016-12-02 09:29:22 +00:00
Bjoern A. Zeeb 310dc5a403 Writing out the L2TP control packet requires 12 bytes of
contiguous memory but in one path we did not always guarantee this,
thus do a m_pullup() there.

PR:			214385
Submitted by:		Joe Jones (joeknockando googlemail.com)
MFC after:		3 days
2016-11-17 14:03:44 +00:00
Bryan Drewery 28323add09 Fix improper use of "its".
Sponsored by:	Dell EMC Isilon
2016-11-08 23:59:41 +00:00
Sean Bruno 2f632dbb0b Avoid panic from ng_uncallout when unpluggin ethernet cable with active
PPTP VPN connection.

Submitted by:	Michael Zhilin <mizhka@gmail.com>
Reviewed by:	ngie
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D7209
2016-08-08 19:31:01 +00:00
Julian Elischer d7373c820e netgraph module for reconstructing checksums
PR:		206108
Submitted by:	Dmitry Vagin  daemon.hammer@ya.ru
MFC after:	1 month
2016-08-01 12:09:04 +00:00
Julian Elischer bf909fc9a4 slite style changes. There is an incoming patch that rewrites a
lot of this module and I want to get the style and whitespace changes in
a separate commit (or maybe more).

PR: 206185
Submitted by:	Dmitry Vagin
MFC after:	1 month
2016-08-01 11:34:12 +00:00
Bjoern A. Zeeb 89856f7e2d Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.

Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.

Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.

For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.

Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.

For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).

Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.

Approved by:		re (hrs)
Obtained from:		projects/vnet
Reviewed by:		gnn, jhb
Sponsored by:		The FreeBSD Foundation
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
Takanori Watanabe b32073c458 Disconnect LE socket when the HCI connection associated is disconnected. 2016-06-07 16:57:13 +00:00
Jung-uk Kim ccabe8433f Fix style(9). 2016-05-26 19:17:51 +00:00
Jung-uk Kim a42aa5facd Use bit_count(3) instead of four bitcount32() calls.
Reviewed by:	asomers, ngie
Differential Revision:	https://reviews.freebsd.org/D6543
2016-05-26 18:57:26 +00:00
Pedro F. Giffuni 053359b7f4 sys/netgraph: spelling fixes in comments.
No functional change.
2016-04-29 21:25:05 +00:00
Pedro F. Giffuni 55e0987aea sys: extend use of the howmany() macro when available.
We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
2016-04-26 15:38:17 +00:00
Pedro F. Giffuni 323b076e9c sys: use our nitems() macro when param.h is available.
This should cover all the remaining cases in the kernel.

Discussed in:	freebsd-current
2016-04-21 19:40:10 +00:00
Pedro F. Giffuni 8dfea46460 Remove slightly used const values that can be replaced with nitems().
Suggested by:	jhb
2016-04-21 15:38:28 +00:00
Pedro F. Giffuni 155d72c498 sys/net* : for pointers replace 0 with NULL.
Mostly cosmetical, no functional change.

Found with devel/coccinelle.
2016-04-15 17:30:33 +00:00
Pedro F. Giffuni 74b8d63dcc Cleanup unnecessary semicolons from the kernel.
Found with devel/coccinelle.
2016-04-10 23:07:00 +00:00
Justin Hibbits c47476d7e6 Migrate many bus_alloc_resource() calls to bus_alloc_resource_anywhere().
Most calls to bus_alloc_resource() use "anywhere" as the range, with a given
count.  Migrate these to use the new bus_alloc_resource_anywhere() API.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D5370
2016-02-27 03:38:01 +00:00
Gleb Smirnoff 8ec07310fa These files were getting sys/malloc.h and vm/uma.h with header pollution
via sys/mbuf.h
2016-02-01 17:41:21 +00:00
Alexander V. Chernikov 6369f51bc8 Make ng_netflow(9) use new routing KPI.
Netflow module is supposed to store (along with fields like
  gateway address and interface index) matched netmask for each record.
  This (currently) requires returning individual route entries, instead
  of optimized next-hop structure. Given that, use control-plane
  rib_lookup_info() function to avoid accessing rtentries directly.
While rib_lookup_info() might be slower, than fibX_lookup() flavours,
  it is more scalable than rtalloc1_fib(), because rtentry mutex is
  not acquired.
2016-01-14 13:14:12 +00:00
Alexander V. Chernikov ea8d14925c Remove sys/eventhandler.h from net/route.h
Reviewed by:	ae
2016-01-09 09:34:39 +00:00
Gleb Smirnoff 829fae9063 Make it possible for sbappend() to preserve M_NOTREADY on mbufs, just like
sbappendstream() does. Although, M_NOTREADY may appear only on SOCK_STREAM
sockets, due to sendfile(2) supporting only the latter, there is a corner
case of AF_UNIX/SOCK_STREAM socket, that still uses records for the sake
of control data, albeit being stream socket.

Provide private version of m_clrprotoflags(), which understands PRUS_NOTREADY,
similar to m_demote().
2016-01-08 19:03:20 +00:00
Alexander V. Chernikov a72d531f35 Do not use 'struct route_in6' inside hash6_insert().
rin6 was used only as sockaddr_in6 storage. Make rtalloc1_fib()
  use on-stack sin6 and return rtenry directly, instead of doing
  useless work with 'struct route_in6'.
2016-01-07 12:22:29 +00:00
Alexander V. Chernikov e971a31425 Fix route lookup condition: do IPv6 route lookup for source based on
NG_NETFLOW_CONF_NOSRCLOOKUP instead of NG_NETFLOW_CONF_NODSTLOOKUP.
2016-01-04 17:25:32 +00:00
Maksim Yevmenkin 74cc817d85 - grab ng_btsocket_l2cap_sockets_mtx lock in
ng_btsocket_l2cap_process_l2ca_enc_change()
  before calling ng_btsocket_l2cap_pcb_by_cid();

- handle possible NULL value returned from
  ng_btsocket_l2cap_pcb_by_cid();

Submitted by:	Hans Petter Selasky; hps at selasky dot org
MFC after:	1 week
2015-12-23 16:32:04 +00:00
Warner Losh f809f280e0 Create a USB_PNP_INFO and use it to export the existing PNP
tables. Some drivers needed some slight re-arrangement of declarations
to accommodate this. Change the USB pnp tables slightly to allow
better compatibility with the system by moving linux driver info from
start of each entry to the end. All other PNP tables in the system
have the per-device flags and such at the end of the elements rather
that at the beginning.

Differential Review: https://reviews.freebsd.org/D3458
2015-12-11 05:28:00 +00:00
Warner Losh f6cea53f9d Create a generic PCCARD_PNP_INFO from the MODULE_PNP_INFO building
block. Use it in all the PNP drivers to export either the current PNP
table. For uart, create a custom table and export it using
MODULE_PNP_INFO since it's the only one that matches on function
number.

Differential Review: https://reviews.freebsd.org/D3461
2015-12-11 05:27:56 +00:00
Alexander V. Chernikov 8ad43f2d0a Move iflladdr_event eventhandler invocation to if_setlladdr.
Suggested by:	glebius
2015-11-14 13:34:03 +00:00
Alexander V. Chernikov b13c5b5db2 Use lladdr_event to propagate gratiotus arp.
Differential Revision:	https://reviews.freebsd.org/D4019
2015-11-09 10:11:14 +00:00
Takanori Watanabe 483ed39512 Fix encryption error handling.
Close l2cap connection on encryption error.
2015-11-07 12:15:02 +00:00
Takanori Watanabe 3a601a2381 Bluetooth LE Security Management channel support.
Add a socket option to block until underlying HCI connection encrypted.

Differential Revision:	https://reviews.freebsd.org/D3981
2015-10-27 03:42:26 +00:00
Alexander Motin 5b363c09dc Add support for PPP-Max-Payload PPPoE tag (RFC4638).
Submitted by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after:	2 weeks
2015-09-11 09:15:27 +00:00
Mark Murray 3aa77530ca * Address review (and add a bit myself).
- Tweek man page.
 - Remove all mention of RANDOM_FORTUNA. If the system owner wants YARROW or DUMMY, they ask for it, otherwise they get FORTUNA.
 - Tidy up headers a bit.
 - Tidy up declarations a bit.
 - Make static in a couple of places where needed.
 - Move Yarrow/Fortuna SYSINIT/SYSUNINIT to randomdev.c, moving us towards a single file where the algorithm context is used.
 - Get rid of random_*_process_buffer() functions. They were only used in one place each, and are better subsumed into those places.
 - Remove *_post_read() functions as they are stubs everywhere.
 - Assert against buffer size illegalities.
 - Clean up some silly code in the randomdev_read() routine.
 - Make the harvesting more consistent.
 - Make some requested argument name changes.
 - Tidy up and clarify a few comments.
 - Make some requested comment changes.
 - Make some requested macro changes.

* NOTE: the thing calling itself a 'unit test' is not yet a proper
  unit test, but it helps me ensure things work. It may be a proper
  unit test at some time in the future, but for now please don't make
  any assumptions or hold any expectations.

Differential Revision:	https://reviews.freebsd.org/D2025
Approved by:	so (/dev/random blanket)
2015-07-12 18:14:38 +00:00
Takanori Watanabe 99043514c6 Fix rfcomm_sppd regression I could reproduced.
To reproduce it, Two machine running FreeBSD and
run
rfcomm_sppd -c 3 -S
rfcomm_sppd -a ${PEER} -c 3
on each side.
2015-07-07 15:56:51 +00:00
Mark Murray d1b06863fb Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
  neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
  random(4) device in the kernel, and the KERN_ARND sysctl will
  return nothing. With RANDOM_DUMMY there will be a random(4) that
  always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
  through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
  suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
  This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
  there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
  behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
  (direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
  weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
  weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
  when the dust settles.
- Use macros for locks.
- Fix comments.

* src/share/man/...
- Update the man pages.

* src/etc/...
- The startup/shutdown work is done in D2924.

* src/UPDATING
- Add UPDATING announcement.

* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.

* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.

* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.

* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
  selection is the way to go.

* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.

* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.

* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
  that instead. All that is needed here is N=0, N++, N==0, and some
  localised trickery is used to manufacture a 128-bit 0ULLL.

* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
  now the test will do a basic check of compressibility. Clairvoyant
  talent is still a good idea.
- This is still a long way off a proper unit test.

* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
  it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])

* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
  it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.

Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00