connreject

package
v1.106.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: BSD-3-Clause Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package connreject provides a bounded, in-memory, per-direction aggregator of recent connection-rejection events observed by the local node.

A rejection event is any evidence that a connection attempt was blocked or dropped: a peer's TSMP reject message, an outbound TSMP reject we emitted because a peer's inbound connection violated our ACLs, a pendopen timeout where we never saw a reply, etc.

The aggregator is split by Direction:

  • Outgoing: connections initiated by this node that were rejected or otherwise failed, keyed on the peer's address ("who we failed to reach").
  • Incoming: connections from a peer that this node rejected, keyed on the peer's address ("who we blocked").

Repeated observations for the same (direction, proto, peer-address, reason) are aggregated into a single Event, bumping Count and Last. Least-recently-used eviction keeps each direction's buffer bounded.

This package contains only the data types and aggregator implementation; wiring into the rest of the system is done by feature/connreject.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMax

func DefaultMax() int

DefaultMax returns the default maximum number of entries per direction. On mobile platforms the default is smaller to respect tight memory budgets.

Types

type Aggregator

type Aggregator struct {
	// contains filtered or unexported fields
}

Aggregator owns bounded, per-direction LRU buffers for rejection [Event]s and a runtime enable flag. It is safe for concurrent use.

An Aggregator is per-[LocalBackend] (or per-test); there is no package-level state.

func NewAggregator

func NewAggregator(max int) *Aggregator

NewAggregator returns an Aggregator with per-direction LRU buffers sized to max entries each. It starts disabled (calls to Note are silently dropped until SetEnabled(true) is called).

A max of 0 or negative disables recording entirely.

func (*Aggregator) Enabled

func (a *Aggregator) Enabled() bool

Enabled reports whether the aggregator is currently enabled.

func (*Aggregator) Incoming

func (a *Aggregator) Incoming() []Event

Incoming returns a snapshot of the incoming-rejection events in oldest-to-newest order.

func (*Aggregator) Note

func (a *Aggregator) Note(e Event)

Note records a rejection observation. It is a no-op if the aggregator is disabled, if max is non-positive, or if e.Direction is not a routable value (Outgoing or Incoming).

If an existing entry matches the aggregation key (Direction, Proto, peer-address, Reason), its Last, Count, Src, Dst, Source, and MaybeBroken are updated with the new observation, and it is moved to the "most recent" end of its buffer. Otherwise a new entry is appended, evicting the oldest entry if the buffer is over capacity.

func (*Aggregator) Outgoing

func (a *Aggregator) Outgoing() []Event

Outgoing returns a snapshot of the outgoing-rejection events in oldest-to-newest order.

func (*Aggregator) SetEnabled

func (a *Aggregator) SetEnabled(v bool) (prev bool)

SetEnabled sets the runtime enable flag. When false, Note is a silent no-op. SetEnabled returns the previous value.

type DebugRejectsResponse

type DebugRejectsResponse struct {
	// Enabled is whether [nodecap.ConnReject] is currently set
	// on the node. When false, Outgoing and Incoming will be empty
	// regardless of prior activity.
	Enabled bool
	// Outgoing is the list of rejections observed for connections this
	// node initiated.
	Outgoing []Event
	// Incoming is the list of rejections this node has emitted for
	// connections initiated by peers.
	Incoming []Event
}

DebugRejectsResponse is the JSON response body shared by the debug-rejects LocalAPI endpoint, the GET /debug/rejects c2n endpoint, and the client/local.Client.DebugRejects method.

type Direction

type Direction string

Direction describes whether a rejection applied to a connection this node initiated (Outgoing) or a connection a peer initiated toward us (Incoming).

Direction is a string type so it serializes directly to human-readable JSON without requiring MarshalText/UnmarshalText boilerplate.

const (
	DirectionUnknown Direction = ""
	Outgoing         Direction = "outgoing"
	Incoming         Direction = "incoming"
)

Direction values.

type Event

type Event struct {
	// First is when this (key) was first observed. If unset on a Note,
	// the aggregator fills it with the current time.
	First time.Time
	// Last is the most recent observation of this (key). If unset on a
	// Note, the aggregator fills it with the current time.
	Last time.Time
	// Count is the number of observations merged into this Event. If
	// unset on a Note, the aggregator treats it as 1.
	Count uint32
	// Direction indicates whether the event applies to an outgoing or
	// incoming connection attempt.
	Direction Direction
	// Proto is the transport protocol of the rejected flow.
	Proto ipproto.Proto
	// Src is a representative source endpoint from the most recent
	// observation. For Outgoing events this is our side; for Incoming
	// events this is the peer side.
	Src netip.AddrPort
	// Dst is a representative destination endpoint from the most recent
	// observation. For Outgoing events this is the peer side; for
	// Incoming events this is our side.
	Dst netip.AddrPort
	// Reason is the machine-readable reason tag.
	Reason Reason
	// Source describes how we learned about this event.
	Source Source
	// MaybeBroken is true for the non-terminal form of an inbound TSMP
	// reject (see packet.TailscaleRejectedHeader.MaybeBroken). It is
	// informational and only meaningful when Source == SourceTSMPRecv.
	MaybeBroken bool
}

Event is a single aggregated rejection observation.

Events are aggregated by Aggregator on (Direction, Proto, peer-address, Reason). Src and Dst carry the ports observed on the most recent occurrence but do not participate in the aggregation key.

type Reason

type Reason string

Reason is a short, stable, machine-readable tag describing why a connection was rejected. Reason is part of the aggregation key in Aggregator.

These values are part of the wire format exposed over the debug endpoints; do not rename or repurpose them without bumping the capability version.

const (
	ReasonUnknown                      Reason = "unknown"
	ReasonACL                          Reason = "acl"
	ReasonShields                      Reason = "shields"
	ReasonHostIPForwarding             Reason = "host-ip-forwarding"
	ReasonHostFirewall                 Reason = "host-firewall"
	ReasonAppConnectorTransitIPUnknown Reason = "app-connector-transit-ip-unknown"
	ReasonNoPeer                       Reason = "no-peer"
	ReasonPeerUnreachable              Reason = "peer-unreachable"
	ReasonTimeout                      Reason = "timeout"
)

Reason values.

type Source

type Source string

Source describes how this node learned of a rejection.

const (
	SourceUnknown Source = ""
	// SourceTSMPRecv is a TSMP reject message received from a peer.
	SourceTSMPRecv Source = "tsmp_recv"
	// SourceTSMPSent is a TSMP reject message this node emitted to a peer.
	SourceTSMPSent Source = "tsmp_sent"
	// SourcePendOpenTimeout is a pendopen-timer expiry with no response.
	SourcePendOpenTimeout Source = "pendopen_timeout"
)

Source values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL