nft collector provides insight into Netfilter rules and actions by tracking packet flow through nftables.
Overview
Thenft collector helps debug firewall behavior by reporting which nftables rules are evaluated and what actions are taken on packets. This is invaluable for understanding why packets are allowed, dropped, or transformed by your firewall.
What Data is Retrieved
Thenft collector retrieves:
- Table information: Table name and handle
- Chain information: Chain name and handle
- Rule handle: Specific rule that matched
- Verdict: Action taken (accept, drop, jump, etc.)
- Policy indication: Whether the verdict comes from chain policy
Probe Installation
The
nft collector automatically installs a kprobe on the __nft_trace_packet kernel function.Prerequisites
Kernel Configuration
Must be enabled (
y) or available as a module (m).If built as a module, the nf_tables module must be loaded.NFTables Trace Rule
For the collector to work, a special nftrace rule must be added. This can be done manually or automatically.Manual Setup
Create a table that enables tracing:Automatic Setup
Use the--allow-system-changes flag:
- Creates the
Retis_Tabletable - Adds the
Retis_Chainchain - Installs the nftrace rule
- Removes the table when Retis stops
Without
--allow-system-changes or a manual trace rule, nft events won’t be reported. Retis will warn you if the rule is missing.Command-Line Options
--nft-verdicts
Comma-separated list of verdicts whose events will be collected.Supported values:
accept: Accept verdictsdrop: Drop verdictscontinue: Continue to next rulebreak: Break out of current chainjump: Jump to another chaingoto: Goto another chainreturn: Return from chainstolen: Packet was stolen (rarely visible with filters)queue: Queue to userspacerepeat: Repeat rule evaluationall: All verdicts
-f.Event Sections Produced
Thenft collector produces the nft event section.
See nft event documentation for detailed format.
Event Format
Usage Examples
Basic Firewall Tracing
Trace all accept and drop verdicts:Trace All Verdicts
See every firewall decision:Filter Specific Traffic
Trace only SSH traffic:With Full Context
Include packet and conntrack information:Track Through Stack
Follow packets through firewall and stack:Save for Analysis
Example Output
Basic Output
- First packet hit the PREROUTING chain’s accept policy
- Second packet matched rule 169 in the INPUT chain and was accepted
With Packet Information
Drop Example
Linking Events to Rules
To match events to actual firewall rules, dump your ruleset with handles:Example Mapping
Given this event:ct state { established, related } accept rule.
Integration with Other Collectors
skb
Essential for seeing what packets are affected:ct (Conntrack)
See conntrack state alongside firewall decisions:skb-tracking
Follow packets through multiple rules:skb-drop
See both firewall drops and kernel drops:dev
Include interface information:ns
Debug namespace-aware firewalls:Use Cases
Debug Blocked Traffic
Verify Firewall Rules
Performance Analysis
NAT Troubleshooting
Policy Validation
Understanding Verdicts
accept
Packet is accepted and continues processing.drop
Packet is silently dropped (no ICMP error sent).jump vs goto
- jump: Saves position and returns after target chain completes
- goto: Doesn’t save position, no automatic return
continue vs return
- continue: Move to next rule in same chain
- return: Exit current chain and return to caller
queue
Packet is queued to userspace for processing.stolen
Packet was consumed by a rule (rare).Technical Details
Kernel Types
Thenft collector activates when these types appear in probe arguments:
struct nft_traceinfo *
Automatic Probe
The collector automatically installs:Parameter Offsets
The collector uses BTF to find parameter offsets:struct nft_chain *: Chain informationstruct nft_rule_dp *: Rule informationstruct nft_verdict *: Verdict informationenum nft_trace_types: Trace type
Source Code References
- Collector:
retis/src/collect/collector/nft/nft.rs - eBPF hook:
retis/src/collect/collector/nft/bpf/nft_hook.bpf.c - Event factory:
retis/src/collect/collector/nft/bpf.rs
Best Practices
- Use
--allow-system-changes: Easiest way to enable tracing - Combine with skb: See what packets are affected
- Filter traffic: Reduce noise for specific investigations
- Dump ruleset with handles: Use
nft -a list ruleset - Understand verdict flow: Know how jump/goto/return work
- Check all verdicts initially: Use
--nft-verdicts allthen narrow down
Performance Considerations
- Trace overhead: nftrace has kernel overhead
- Single probe: Only one kprobe installed
- Verdict filtering: Reduces events in userspace
- Efficient extraction: Uses BTF for parameter offsets
- Production use: Consider performance impact of tracing
Troubleshooting
No NFT Events
If you’re not seeing nft events:-
Verify nftrace rule exists:
-
Use
--allow-system-changes: -
Check if nf_tables module is loaded:
Module Not Loaded
Can’t Find Rules
If rule handles in events don’t match your ruleset:- Dump ruleset with handles:
nft -a list ruleset - Ensure you’re looking at the right table family (inet, ip, ip6)
- Rules might have been modified since collection
Binary Not Available
If--allow-system-changes fails:
See Also
- ct collector - Connection tracking information
- skb collector - Packet data
- nft event format - Event format details
- Filtering - Filter traced packets
