scanner

package
v1.0.460 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 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 scanner is the DPI content scanner: a set of pre-compiled regex signatures applied to HTTP response bodies flowing through SSL-Inspect tunnels, with a per-host bypass list and atomic persistence. It is extracted from the flat package main per ADR-0002; its only Culvert dependencies are the obs / fileutil / hostutil seams.

Patterns are standard Go regex strings. Matching is byte-level. Each match is bounded by a timeout to prevent ReDoS from pathological patterns or input.

Index

Constants

View Source
const PanicReason = "dpi-match-panic"

PanicReason is the pattern string reported when a match panicked and the guard contained it. Like SaturatedReason it reaches only the DPI_BLOCKED log line and the inspection record, never the client-visible block page.

View Source
const SaturatedReason = "dpi-engine-saturated"

SaturatedReason is the pattern string reported when the gate refuses a scan. It reaches the DPI_BLOCKED log line and the inspection record; the client-visible block page is a fixed string that names no pattern, so this does not disclose the node's posture to the client that triggered it.

Variables

This section is empty.

Functions

func AbandonedWorkers added in v1.0.403

func AbandonedWorkers() int64

AbandonedWorkers counts scans whose worker outlived its parent — the uninterruptible-match population the cap is sized against.

func Inflight added in v1.0.403

func Inflight() int64

Inflight is the number of scan workers alive right now, INCLUDING workers whose scan has already failed closed and walked away. Counting the abandoned ones is the point: they are the goroutines and the retained bodies the cap exists to bound.

func MatchPanics added in v1.0.403

func MatchPanics() int64

MatchPanics counts matches that panicked and were contained by the worker's guard. Distinct from a timeout: a timeout means the match did not finish, a panic means it crashed. Both fail closed, but they point at different causes.

func MatchRegexWithTimeout

func MatchRegexWithTimeout(re *regexp.Regexp, data []byte, timeout time.Duration) bool

MatchRegexWithTimeout runs re.Match(data) with a deadline. Returns false if the match does not complete in time (ReDoS prevention); on timeout it fails closed (treats a timeout as a suspicious match).

func MaxInflight added in v1.0.403

func MaxInflight() int

MaxInflight is the current cap.

func SaturationBlocks added in v1.0.403

func SaturationBlocks() int64

SaturationBlocks counts scans refused because no slot came free within the wait budget. Each one is a fail-closed block of content that was never inspected, so a non-zero and rising value is an availability signal, not just a capacity one.

func SetMaxInflight added in v1.0.403

func SetMaxInflight(n int)

SetMaxInflight republishes the gate with room for n concurrent scan workers. n < 1 is clamped to 1. Exported as the seam a future operator setting (or a test) can drive; production uses defaultMaxInflight.

Types

type ContentScanner

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

ContentScanner holds pre-compiled DPI regex patterns and applies them to HTTP response bodies.

func New

func New(maxBytes int64) *ContentScanner

New returns a ContentScanner with the given per-response buffer cap and an empty bypass-host set.

func (*ContentScanner) Add

func (s *ContentScanner) Add(pattern string) error

Add compiles and appends a single pattern. Copy-on-write: the existing set is never appended to in place, so a Scan worker already walking it is unaffected.

func (*ContentScanner) BypassHosts

func (s *ContentScanner) BypassHosts() []string

BypassHosts returns a sorted copy of the current DPI bypass host list. Tier 3.4.

func (*ContentScanner) Enabled

func (s *ContentScanner) Enabled() bool

Enabled returns true when at least one pattern is loaded.

func (*ContentScanner) IsBypassHost

func (s *ContentScanner) IsBypassHost(host string) bool

IsBypassHost reports whether the given host is on the DPI bypass list. Hot path: called once per inspected tunnel response. Tier 3.4.

func (*ContentScanner) List

func (s *ContentScanner) List() []string

List returns a snapshot of all raw pattern strings.

func (*ContentScanner) Load

func (s *ContentScanner) Load(path string) error

Load reads a JSON array of regex strings (legacy format) or a dpiContentFile envelope ({patterns, bypass_hosts}) from path. If the file does not exist, Load succeeds (empty scanner — no patterns active).

func (*ContentScanner) MaxBytes

func (s *ContentScanner) MaxBytes() int64

MaxBytes returns the per-response buffering cap.

func (*ContentScanner) Path

func (s *ContentScanner) Path() string

Path returns the configured persistence file path ("" when unset).

func (*ContentScanner) Remove

func (s *ContentScanner) Remove(pattern string) bool

Remove deletes the first occurrence of pattern from the list. Returns true if a pattern was removed. Copy-on-write, for the same reason as Add: the pre-snapshot version shifted the shared backing array in place, which an abandoned (timed-out) Scan worker still reading that array would have raced.

func (*ContentScanner) Save

func (s *ContentScanner) Save() error

Save persists the current pattern list and bypass host list to the configured file path. Uses an atomic write (tmp + rename) so a crash never leaves a partial file. No-op if no path is configured. Writes the envelope format when bypass hosts are present, otherwise the legacy array format so existing tooling keeps working. Tier 3.4.

Returns the write error (2E-A durability truth): the admin handlers must not report a durable configuration change that never reached disk. Callers on bulk/best-effort paths may keep ignoring it (statement call).

Snapshot and publication run as ONE serialized critical section (saveMu — see the field comment): every writer of the shared envelope (interactive handlers, config-version rollback, CP→DP snapshot apply, inspection-rules seed, config import) funnels through Save, so serializing here is the single writer domain the envelope needs — no caller-side protocol.

func (*ContentScanner) Scan

func (s *ContentScanner) Scan(data []byte) (string, bool)

Scan checks data against all compiled patterns. Returns the first matching raw pattern string and true, or ("", false). Each regex match is bounded by dpiRegexTimeout to prevent ReDoS hangs.

func (*ContentScanner) Set

func (s *ContentScanner) Set(patterns []string) error

Set atomically replaces the full pattern list. Returns an error if any pattern fails to compile; on error the existing patterns are unchanged.

func (*ContentScanner) SetBypassHosts

func (s *ContentScanner) SetBypassHosts(hosts []string)

SetBypassHosts atomically replaces the DPI bypass host list. Hosts are lower-cased and trimmed. Tier 3.4.

func (*ContentScanner) SetPath

func (s *ContentScanner) SetPath(path string)

SetPath sets the persistence file path without loading from it. Used by the test suite (and any caller wanting Save to target a specific file) in place of reaching into the unexported field after the ADR-0002 extraction.

func (*ContentScanner) SetWriteFileForTest added in v1.0.218

func (s *ContentScanner) SetWriteFileForTest(fn func(path string, data []byte) error)

SetWriteFileForTest installs a durable-publication seam (nil restores the default fileutil.AtomicWrite). Test-only: lets a test pause Save at the exact write boundary so writer interleavings are deterministic, never sleep-based.

Jump to

Keyboard shortcuts

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