scanexcl

package
v1.0.521 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 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 scanexcl holds the admin-managed scan-exclusion store: known-good SHA-256 content hashes and hostnames that bypass all body scanning. It is a self-contained leaf (stdlib + the hostutil seam) extracted from the flat package main per ADR-0002.

It is designed for an extreme read:write ratio — IsHostExcluded runs once per inspected tunnel response and once per scanned plain-HTTP response, IsHashExcluded once per body scan, while writes happen only when an admin edits the lists — so the two maps are published as ONE immutable view behind an atomic pointer and the read path takes no lock at all. See Store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store holds admin-managed exclusions: known-good content hashes and hostnames that bypass all body scanning. The zero value is a valid empty store.

── Why the read path is lock-free ──────────────────────────────────────────

IsHostExcluded is called UNCONDITIONALLY from scanInspectBody (proxy_tunnel.go), ahead of the content-type gate, for every response decrypted on the SSL-inspection path — the primary SWG path — and from scanHTTPResponseBody (proxy_http.go) whenever any body scanner is enabled. IsHashExcluded is called once per body scan (internal/secscan). So all three run at request rate against lists that in steady state never change, and the overwhelmingly common posture is that no exclusion is configured at all: the lists are an admin opt-in for known-good internal mirrors.

Those reads used to take sync.RWMutex.RLock. A reader lock is not cheap in this shape: RLock/RUnlock are two atomic read-modify-writes on ONE process-wide word, so every inspected response wrote the same cache line purely to read a map that never changes — and in the default posture, to read a map that is EMPTY. That is not a constant cost but a throughput ceiling, and it is the fourth instance of the identical shape in this tree (internal/threatfeed, internal/connlimit, the IP filter, and the top-hosts counter in store.go all record the same finding).

Measured on a 4-core Xeon @2.10GHz, go1.27.4, -benchtime=2s, -count=1, both arms in ONE interleaved invocation against the verbatim RWMutex implementation kept as the legacy arm in scanexcl_bench_test.go. All rows are RunParallel over the rotating destination working set, so ns/op is wall time per op across ALL workers: a genuinely parallel read FALLS as cores are added and one that serialises on a shared word rises.

                            │   P=1   │   P=2   │   P=4   │ 1->4 throughput
host, no exclusions, RWMutex │ 41.7 ns │  141 ns │  154 ns │ 0.27x  (cores SUBTRACT)
host, no exclusions, view    │ 3.52 ns │ 1.75 ns │ 0.89 ns │ 4.0x
host, configured miss, RWMtx │ 50.2 ns │  156 ns │  171 ns │ 0.29x
host, configured miss, view  │ 42.1 ns │ 23.0 ns │ 12.6 ns │ 3.3x
hash, no exclusions, RWMutex │ 79.0 ns │ 88.2 ns │ 96.6 ns │ 0.82x
hash, no exclusions, view    │ 2.62 ns │ 1.37 ns │ 0.65 ns │ 4.0x

Serially, the shapes that still do the full lookup: a configured host hit 45.7 -> 40.5 ns and a configured hash hit 93.0 -> 79.9 ns, which is the RLock/RUnlock pair and its deferred unlock coming off the call.

Read the DIRECTION, not the exact percentage — absolute ns/op on a shared 4-vCPU VM is not comparable between invocations, which is why both arms are timed in the same run. What is robust is the sign: the lock made cores subtract throughput and the published view makes them add it, in every posture. Re-measure the whole set in one go; never compare a new arm against a number quoted here.

The empty-posture gate below is what makes the "no exclusions" rows total: a store with nothing configured answers from the length check, so it pays neither the port strip nor the case fold that the lock used to be taken around. A configured store still pays both, and that is the cost the "configured miss" rows report. The gate is held structurally by TestEmptyPosture_AllocationFree, not by a timing threshold.

mu now guards only path and serialises writers. Readers never take it.

func New

func New() *Store

New returns an empty Store ready for use.

func (*Store) IsHashExcluded

func (s *Store) IsHashExcluded(hash string) bool

IsHashExcluded reports whether the SHA-256 hex is on the hash allowlist. Hot path: called once per body scan. Lock-free — see Store.

func (*Store) IsHostExcluded

func (s *Store) IsHostExcluded(host string) bool

IsHostExcluded reports whether the hostname is on the host allowlist. Hot path: called once per inspected tunnel response and once per scanned plain-HTTP response. Lock-free — see Store.

func (*Store) Lists

func (s *Store) Lists() (hashes, hosts []string)

Lists returns copies of the current hash and host lists, sorted for stable admin output.

func (*Store) Load

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

Load reads the JSON file at path into the store. Missing file is not an error.

The normalisation here is deliberately NOT Replace's: Load lower-cases what the file holds and keeps every entry, where Replace also trims surrounding space and drops entries that normalise to empty. That asymmetry predates the published view and is preserved verbatim — the file is written by Save from already-normalised keys, so the two agree on every value Culvert itself persists, and widening Load would silently change what a hand-edited file means.

func (*Store) Replace

func (s *Store) Replace(hashes, hosts []string)

Replace atomically swaps the exclusion lists, normalising to lower case.

func (*Store) Save

func (s *Store) Save() error

Save persists the exclusion lists to the configured file path using an atomic tmp+rename write. No-op if no path configured.

Jump to

Keyboard shortcuts

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