Commit Graph
54 Commits
Author SHA1 Message Date
Ryan Huber 130ef730b4 tun: Size staged slots from the workers and listen.batch
The TX and RX slot counts were fixed at eight and six. TX now uses one slot
per worker plus the one being read and the one being sent, at least eight.
RX keeps up to 384 recvmmsg entries in flight in four to six slots, so a
larger listen.batch takes fewer slots and RX memory never exceeds today's.
tun.staged.tx_slots and rx_slots override either, down to two. The defaults
at listen.batch 64 with up to six workers are unchanged: eight TX slots of
about 1.1 MiB and six RX slots of 4 MiB with GRO.
2026-10-16 21:23:10 +00:00
Ryan Huber ffb2835f70 tio: Count superpacket segments on Packet
Move the staged transmit segment count onto tio.Packet, next to
IsSuperpacket and SegmentSuperpacket, which it predicts.
2026-10-16 21:22:49 +00:00
Ryan Huber eb073d6c23 tun: Keep small idle batches on the reader
With staging enabled, a reader whose pipeline is empty handles a batch below
256 TX segments or RX packets itself, without a worker handoff or buffer swap.
The threshold is the measured crossover, not another configuration knob.
Inline work only starts once that reader's ordered work has completed, so
ownership and order hold across switches.

With several readers, transmit still takes shared tunnel credit and the same
reservations as staged batches, releasing it after the synchronous flush; a
sole reader with an empty pipeline has nothing to overtake and uses the
original inline path. Small batches a reader sends itself run on the reader's
CPU, so they can use a different XPS TX ring than its sender.

Metrics: flow.tx.inline and flow.rx.inline count reads handled on the reader
(TX inline also counts oversized reads).

With receive IRQ CPUs kept free of Nebula threads, this improved one TCP
stream over 100 GbE from 16.7 to 21.1 Gbit/s; that measurement does not isolate
the threshold. Tests cover the switch in both directions, ordering behind an
in-flight batch, a paused reader against repeated small sends on another,
RecvError handling on the listener, and send affinity across mode switches.
2026-10-16 21:22:30 +00:00
Ryan Huber e4f659a207 tun: Share replay-window reservation credit across readers
Charge staged reservations to each tunnel instead of dividing a static share
of the window by routines. Several readers sending on one tunnel then share
its credit: the limit is half the peer replay window, assumed from
ReplayWindow, which must be a power of two of at least 8192 (checked at
compile time). The other half allows finite unreserved traffic (inline and
control sends, relay forwarding through SendVia) and network reordering;
unlimited bypass traffic or delay can still exceed it.

An outstanding-count cap alone would let a fast reader repeatedly send and
reacquire credit, overtaking a paused reader without bound. So once readers
overlap, spent credit is only recycled when every reservation has drained. A
sole ordered reader gets each completion refunded, since its later batches
cannot overtake its earlier ones. A reader that fails to acquire ends sole
ownership, so a busy owner cannot keep a larger waiter blocked forever. This
restores progress, not FIFO fairness. All transitions are a single CAS.

Waiting readers flush their own oldest batch before retrying and never hold a
partial acquisition: a failed multi-tunnel (relay) acquisition rolls back.
Credit is released only after the flush or an explicit drop. A read that alone
exceeds a tunnel's credit, such as a tiny-MSS superpacket, is sent segment by
segment, synchronously. Acquisition is per read, so pressure on one tunnel
also delays the other tunnels in the same read.

The combined staged transmit, receive and shared credit measured 15 to 25
Gbit/s over one tunnel with eight TCP streams between two 100 GbE hosts.

Tests model overtaking, ordered reuse, a blocked reader behind a busy owner,
and relay rollback with both window sizes, and run eight competing readers
plus unreserved control traffic on one tunnel, checking every packet is
accepted by the receiver's replay window in wire order.
2026-10-16 21:22:11 +00:00
Ryan Huber db8f9cd2e9 udp: Add ordered staged receive processing
With tun.staged.workers set, each Linux UDP listener classifies a recvmmsg
batch, hands its data packets to that many decrypt workers, and an ordered
writer commits the batch in arrival order: replay window, roaming, firewall,
control packets and tun writes go through the same helpers inline receive
uses. Six batches per routine bound memory and backpressure. Conns that cannot
hand off their buffers stay inline.

The listener's classification is speculative. Before touching replay state the
writer resolves each data packet through its own batch-local hostmap cache,
exactly where inline receive would, so data after a close in the same batch is
still delivered while data after a removal or replacement between batches is
dropped, with the same RecvError reply inline receive sends. Known replays are
marked by a precheck and skip decryption, but keep their place so that reply
stays identical when an earlier RecvError deleted their tunnel.

New API: udp.StdConn.ListenOutHandoff, and the same on TesterConn for e2e,
runs the receive loop while handing each batch's buffers to the caller in
exchange for replacements. It is found through an unexported interface in
nebula, so udp.Conn and its other implementations are unchanged.

Metrics: flow.rx.batches, and flow.stage.{rx_read,rx_decrypt,rx_write}.q<N>.busy_ns.

Tests cover both ciphers, ordering, duplicate and corrupted packets from other
addresses, window jumps, control packets mid-batch, RecvError then replay,
tunnel replacement, firewall parity, fallback, real UDP sockets, partial
batches at close, and a handshake and traffic through e2e that checks pipeline
use on Linux and the inline fallback elsewhere. No isolated receive throughput
claim is made.
2026-10-16 21:21:50 +00:00
Ryan Huber f3f98e1690 tun: Add opt-in staged transmit processing
Set tun.staged.workers to a positive count on Linux, with tun.use_offloads
enabled, to move encryption off each tun reader. The reader filters and
reserves counters for a whole read, hands the batch to that many encrypt
workers, and an ordered sender flushes the batches in read order. Eight slots
per routine bound the batches in flight; a full pipeline blocks the reader.
Zero workers, the default, keeps today's inline path, as do tun queues that
cannot hand off their read buffer and builds whose AES-GCM needs nonce-ordered
encryption (BoringCrypto, FIPS).

IMPORTANT: staged senders need peers with the 8192-entry replay window of
master. Released v1.11.x peers use 1024 and will drop reordered batches. The
window is not negotiated.

Readers keep today's pinning. The sender is only pinned with an explicit
tun.cpu_affinity: sender i uses entry i+1, unless that is its reader's CPU,
so a one-entry list leaves the sender unpinned rather than sharing it: two
busy transmit threads on one CPU serialise (eight TCP streams over 100 GbE
fell from 25.9 to 22.8 Gbit/s). Without a list the sender is not pinned. Placing it by queue index on a
hybrid CPU put it on an efficiency core, and one TCP stream over 100 GbE
reached 18.6-19.6 Gbit/s pinned against 20.2-20.6 unpinned.

New API, each needed across a package boundary:
- tio.Offload.SwapRxBuf hands the buffer of the last Read to the reader and
  reads into the one given. It is a method on the concrete queue, found through
  an unexported interface in nebula, so tio.Queue and its other
  implementations are unchanged.
- batch.SendBatch.Reset drops queued packets without sending, for a sender
  whose sockets are already closed; Flush now uses it.

Metrics, registered only for active pipelines: flow.tx.batches counts reads
handed to the sender, flow.stage.{tx_read,tx_encrypt,tx_send}.q<N>.busy_ns the
elapsed busy time of each stage, to find the limiting one.

Tests cover ordering and counters under backpressure with both ciphers (AES
skipped where nonce order is required), read errors with batches in flight,
shutdown, exhaustion, relays, fallback, firewall parity, and the actual reader
and send thread affinity for every placement, with pinning on and off: the
sender is pinned only to an explicit entry other than its reader's CPU.
2026-10-16 21:21:36 +00:00
Ryan Huber 6146f3e4a6 tun: Prepare batch counter reservation for staged encryption
Build on the inside-packet filtering split with shared preparation and encryption helpers for inline and reserved sends. Reserve each batch’s per-tunnel counter range before encryption, including relay counters, without enabling staged processing yet. Test reserved encryption against a real receiver and check segmentation counts.
2026-10-16 21:21:23 +00:00
Ryan Huber 6826c04103 tun: Separate inside-packet filtering from sending 2026-10-16 21:21:03 +00:00
Ryan Huber 8a2de9b1b5 examples: set socket buffers and raise tun tx_queue (#1928)
* examples: set socket buffers and raise tun tx_queue

* examples: use the default tcp max window for socket buffers

* examples: note buffers are linux only, clarify tx_queue default

* tun: default tx_queue to 5000
2026-10-11 00:30:07 -04:00
Ryan Huber e28336c5db probes to the lh are not generally useful as recv_error should catch (#408) 2023-03-29 15:09:36 -05:00
Ryan Huber 3aaaea6309 don't allow a useless handshake with yourself (#402)
* don't allow a useless handshake with yourself

* remove helper
2021-03-15 12:58:23 -07:00
Ryan Huber 73a5ed90b2 Do not allow someone to run a nebula lighthouse with an ephemeral port (#399)
* Do not allow someone to run a nebula lighthouse with an ephemeral port

* derp - we discover the port so we have to check the config setting

* No context needed for this error

* gofmt yourself

* Revert "gofmt yourself"

This reverts commit c01423498e.

* Revert "No context needed for this error"

This reverts commit 6792af6846.

* snip snap snip snap
2021-03-08 12:42:06 -08:00
Ryan Huber 43a3988afc i don't think this is used at all anymore (#323) 2020-10-29 21:43:50 -04:00
Ryan Huber 0d6b55e495 Bring in the new version of kardianos/service and output logfiles on osx (#303)
* this brings in the new version of kardianos/service which properly
outputs logs from launchd services

* add go sum

* is it really this easy?

* Update CHANGELOG.md
2020-09-24 15:34:08 -07:00
Ryan HuberandNate Brown 1297090af3 add configurable punching delay because of race-condition-y conntracks (#210)
* add configurable punching delay because of race-condition-y conntracks

* add changelog

* fix tests

* only do one punch per query

* Coalesce punchy config

* It is not is not set

* Add tests

Co-authored-by: Nate Brown <nbrown.us@gmail.com>
2020-03-27 11:26:39 -07:00
Ryan Huber 41968551f9 clarify that lighthouse IP should be nebula range (#196) 2020-02-28 11:35:55 -08:00
Ryan Huber a91a40212d check that packet isn't bound for my vpn ip (#192) 2020-02-21 16:49:54 -08:00
Ryan Huber 25bf80d8d3 add new invite link without expiration date (#165)
merging because link doesn't work rn and this is not a code change.
2020-01-16 10:09:45 -06:00
Ryan Huber 91f7b9c049 Update README.md
fix readme
2020-01-07 12:40:25 -06:00
Ryan Huber fd8ad5d0d7 Merge pull request #133 from slackhq/interval_zero_check
if interval is 0 don't even update lh (mobile use case)
2019-12-26 15:57:01 -06:00
Ryan Huber df8e45c13b if interval is 0 don't even update lh (mobile use case) 2019-12-26 21:12:31 +00:00
Ryan Huber fe58cedd2e Merge pull request #120 from slackhq/add_slack_link
add invitation link to readme
2019-12-20 08:33:38 -08:00
Ryan Huber 7ee692663d add invitation link to readme 2019-12-20 16:28:17 +00:00
Ryan Huber 2c8b0ec7b1 Merge pull request #105 from slackhq/fix_lighthouse_check
should be break not continue
2019-12-17 09:18:57 -06:00
Ryan Huber 5d0d916fc9 should be break not continue 2019-12-17 14:43:01 +00:00
Ryan Huber a680ac29f5 Merge pull request #98 from slackhq/warn_not_error
make this a warning, even though i believe it is fundamentally an error (in judgement)
2019-12-13 16:03:36 -06:00
Ryan Huber ad7079d370 make this a warning, even though i believe it is fundamentally an error
(in judgement)
2019-12-13 21:55:01 +00:00
Ryan Huber 6a37b26f9a Merge pull request #94 from infinytum/patch-1
Fix for Issue #90
2019-12-13 10:42:59 -06:00
Ryan Huber cec698b1b3 Merge pull request #91 from slackhq/fix_examle
derp- example config is now less silly
2019-12-12 12:59:15 -06:00
Ryan Huber cedf9549a6 derp- example config is now less silly 2019-12-12 18:50:52 +00:00
Ryan Huber 5217f28264 Merge pull request #79 from slackhq/subnet_support
Subnet and routing support.
2019-12-12 12:36:56 -06:00
Ryan Huber 9981510554 new mtu setting and const for default 2019-12-12 18:01:46 +00:00
Ryan Huber f03d895ebf don't steal error 2019-12-12 17:31:22 +00:00
Ryan Huber 9333a8e3b7 subnet support 2019-12-12 16:34:17 +00:00
Ryan Huber 5c99ea26c9 Merge pull request #83 from slackhq/remove_annotations
get rid of the annotation "errors" on github actions
2019-12-11 14:28:42 -06:00
Ryan Huber 1884aec113 get rid of the annotation "errors" on github actions 2019-12-11 20:24:13 +00:00
Ryan Huber ac72d1615a Merge pull request #49 from itorres/patch-1
Fix typo in getting started
2019-12-02 13:13:13 -06:00
Ryan Huber 6039b9f80a Merge pull request #60 from slackhq/yaml_file_rename
rename file to .yml to prevent confusion with example start scripts
2019-12-02 09:37:40 -06:00
Ryan Huber 15e6e0ad30 Merge pull request #3 from slackhq/self_installing_service
make nebula a service that can install itself
2019-12-02 09:37:09 -06:00
Ryan Huber 29c0523714 rename file to .yml to prevent confusion with example start scripts 2019-12-02 15:31:53 +00:00
Ryan Huber 2bff0b266e clean up makefile per wadey comment 2019-12-02 15:26:48 +00:00
Ryan Huber 3fe99aa065 change bin target to use variable for cmd path 2019-11-28 16:20:57 +00:00
Ryan Huber 00d6973e27 remove some boilerplate + better messages 2019-11-28 16:20:57 +00:00
Ryan Huber 8ed69c8eaf make nebula a service that can install itself 2019-11-28 16:20:57 +00:00
Ryan Huber 94441789d5 Merge pull request #41 from slackhq/lighthouse_static_map_error
Add an error (non fatal) when a lighthouse host has no static entry
2019-11-23 18:24:22 -06:00
Ryan Huber 08915315ff add tests and improve error 2019-11-23 23:55:23 +00:00
Ryan Huber 83d2550b2d add an error (non fatal) when a lighthouse host has no static entry 2019-11-23 21:46:45 +00:00
Ryan Huber 72a4e71ebc Merge pull request #35 from slackhq/chachacha
add chachapoly note to example config
2019-11-23 13:36:36 -06:00
Ryan Huber b01e181704 Merge pull request #37 from slackhq/remove_deprecated_hmac
remove old hmac function. superceded by ix_psk0
2019-11-23 13:33:50 -06:00
Ryan Huber 89f0d998cf remove old debug print statements 2019-11-23 17:01:10 +00:00
Ryan Huber 6a460ba38b remove old hmac function. superceded by ix_psk0 2019-11-23 16:50:36 +00:00
Ryan Huber 1dddd370bb Add chachapoly note and HUP note at the top 2019-11-23 15:12:56 +00:00
Ryan Huber ef324bf7e3 Merge pull request #31 from philippgille/patch-1
Fix config comment
2019-11-23 09:04:37 -06:00
Ryan Huber 498e792a46 add hole punching options to example config 2019-11-20 01:24:45 +00:00