tspuprobe

package
v0.1.80-dev.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 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 tspuprobe finds out whether TCP SYNs to an address die at the national DPI box (the Russian TSPU), seen from the machine it runs on. It is a traceroute with a TTL limit and no privileges: one plain TCP socket per probe, the TTL and IP_RECVERR set, and a router's ICMP Time Exceeded read from the socket while the connection is in SYN_SENT (hop_linux.go).

The method (a re-implementation of the idea described by porutchik/tspu-check and LowderPlay/cheburcheck; no code is shared):

  1. dpi_hop. SYNs to an address that is certainly blocked in the country go out with TTL 1..max_ttl. The DPI box drops them without an ICMP answer, so the highest TTL a router answered is the hop in front of the box.
  2. Control. SYNs to a certainly-open address with TTL dpi_hop+1..dpi_hop+hop_limit must not all die, else the method does not apply to this network (ErrControlFailed; that is no verdict about any target).
  3. Targets, the same way: an established connection or an ICMP answer from behind the box is "open", a RST "refused", silence at every hop "blocked". A blocked answer is checked again, alone and with more patience, because many probes at once trip the ICMP rate limit of routers and look like a blocked address.

Only the addresses of the request are probed. The package is portable; the probe itself is Linux only.

Index

Constants

View Source
const (
	VerdictBlocked = "blocked"
	VerdictOpen    = "open"
	VerdictRefused = "refused"
	// VerdictTimeout: no verdict was reached for that host:port (the deadline ran out, or the name did not resolve).
	VerdictTimeout = "timeout"

	// The caps of one run (agent.proto "COUNTRY PROBE").
	MaxTargets      = 8
	MaxPorts        = 4
	MaxPairs        = 16
	MaxHopLimit     = 8
	MaxMaxTTL       = 32
	DefaultHopLimit = 3
	DefaultMaxTTL   = 30
	TotalDeadline   = 120 * time.Second
	// ControlPort is the port of the control target and of the blocked reference.
	ControlPort = 443
)
View Source
const (
	// ReasonRefOpen: the blocked reference answered with a SYN-ACK, so it passes on this path.
	ReasonRefOpen = "ref_open"
	// ReasonRefRefused: the reference answered with a RST: something resets it, and this method does not see that filter.
	ReasonRefRefused = "ref_refused"
	// ReasonNoHops: no router answered at any TTL, so the route is hidden.
	ReasonNoHops = "no_hops"
	// ReasonNoRef: the request had no blocked reference.
	ReasonNoRef = "no_ref"
)

Why the DPI box could not be placed (NoDPIHopError.Reason; the "reason" param of the agent's no_dpi_hop answer).

Variables

View Source
var (
	ErrBadParams       = errors.New("tspuprobe: bad parameters")
	ErrUnsupportedHost = errors.New("tspuprobe: unsupported destination")
	// ErrUnsupported: this host cannot run the probe (not Linux, or the socket options are refused).
	ErrUnsupported = errors.New("tspuprobe: unsupported on this host")
	// ErrNoDPIHop: the DPI box cannot be placed: no blocked reference, it was silent from the first hop, or it was reachable.
	// The error a run returns is a *NoDPIHopError that says which (errors.Is matches this value).
	ErrNoDPIHop = errors.New("tspuprobe: dpi hop not found")
	// ErrControlFailed: the control target did not get past the DPI box, the method does not apply on this network.
	ErrControlFailed = errors.New("tspuprobe: control failed")
	// ErrDeadline: the total deadline ran out before the DPI hop and the control were settled.
	ErrDeadline = errors.New("tspuprobe: deadline")
)

Functions

func Key

func Key(host string, port uint16) string

Key is the name of a host:port in Result.Verdicts.

func Supported

func Supported() bool

Supported reports whether this host can run the probe: a TCP socket accepts IP_TTL and IP_RECVERR (no privilege, no raw socket, no AF_PACKET; the hardened unit of the node allows AF_INET).

func Validate

func Validate(req Request) error

Validate checks the request before any socket is opened. Hosts that are literals are checked here; a name is checked when it is resolved.

Types

type NoDPIHopError added in v0.1.44

type NoDPIHopError struct{ Reason string }

NoDPIHopError is ErrNoDPIHop with the reason the box could not be placed.

func (*NoDPIHopError) Error added in v0.1.44

func (e *NoDPIHopError) Error() string

func (*NoDPIHopError) Is added in v0.1.44

func (e *NoDPIHopError) Is(target error) bool

type Request

type Request struct {
	Control    string // IPv4 literal, port 443
	BlockedRef string // IPv4 literal, port 443; "" = ErrNoDPIHop
	Targets    []Target
	HopLimit   int
	MaxTTL     int
}

Request is one run. HopLimit and MaxTTL are 0 for their defaults.

type Result

type Result struct {
	DPIHop   int
	Verdicts map[string]string
}

Result is a finished run. Verdicts are keyed by Key(host, port) with the host as the request spelled it.

func Run

func Run(ctx context.Context, req Request) (Result, error)

Run runs the probe with the machine's sockets. It returns ErrUnsupported where the host cannot.

type Target

type Target struct {
	Host  string
	Ports []uint16
}

Target is one host and its TCP ports.

Jump to

Keyboard shortcuts

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