How to create custom Inspector plugins for Snort 3: inspector types, virtual methods, the InspectApi structure, pub/sub with DataBus, and Trace Logger inspectors.
Inspectors are the main workhorse between packet decoding and IPS detection. They correspond to Snort 2’s preprocessors and cover everything from flow tracking and TCP reassembly to application-layer protocol analysis.
The InspectorType enum controls when and how an inspector is invoked:
// framework/inspector.henum InspectorType{ IT_PASSIVE, // config only, or data consumer (eg file_log, binder, ftp_client) IT_PACKET, // processes raw packets only (eg normalize, capture) IT_STREAM, // flow tracking and reassembly (eg ip, tcp, udp) IT_NETWORK, // process packets w/o service (eg arp, bo) IT_SERVICE, // extract and analyze service PDUs (eg dce, http, ssl) IT_CONTROL, // process all packets before detection (eg appid) IT_PROBE, // process all packets after detection (eg perf_monitor, port_scan) IT_PROBE_FIRST, // process all packets before detection (eg packet_capture) IT_MAX};
IT_CONTROL — before detection
Runs on every packet before IPS detection. AppID is always first among control inspectors.
IT_PACKET — raw packets only
Processes packets at the raw layer, before reassembly. Used for normalization and capture.
IT_STREAM — flow tracking & reassembly
Manages flow state, IP defragmentation, and TCP reassembly. Also handles files and TCP payload-only streams directly.
IT_NETWORK — packets without a service
Handles protocols that don’t ride on a recognized service (e.g. ARP spoofing, Back Orifice).
IT_SERVICE — application PDUs
Parses application-layer PDUs: HTTP, FTP, SSL, DCE/RPC, Telnet, etc.
IT_PASSIVE — config or event consumption
For configuration-only plugins, or for consuming inspection events published by other inspectors (binder, ftp_client, file_log).
IT_PROBE — after detection
Runs after all detection, on every packet. Used for performance monitoring and port scanning.
IT_PROBE_FIRST — before detection (all packets)
Similar to IT_CONTROL but specifically for capture-style inspectors like packet_capture that need access to all packets before the detection engine runs.
The wizard inspector uses IT_SERVICE type in the plugin API, even though its logical role is service identification. The IT_WIZARD label described in user documentation is a conceptual role, not a separate enum value.
Trace Loggers print diagnostic trace messages and are implemented as inspector plugins. The pattern requires three classes: a logger, a factory, and an inspector.
Plugins must keep configuration (parse-time) separate from runtime state. Store runtime state in FlowData on the flow, or in thread-local storage. Never store mutable per-packet state in configuration objects.
eval(), clear(), and likes() run on packet threads — they must be thread-safe.
configure(), show(), and tear_down() run on the main thread.
tinit() / tterm() run on each packet thread once at startup/shutdown.