You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pcap host_spec is effectively widened by interface netmask, causing DNS xact direction misclassification #758
Summary
When using pcap input with a specific host_spec (e.g., VIP /32), pktvisord still adds the capture interface’s full subnet as host IPs. This causes packet direction to be misclassified (toHost/fromHost), which in turn flips DNS xact_in/xact_out metrics. In my case, server-mode DNS traffic is reported as client-mode (xact_in=0, xact_out>0).
Objective
I want DNS server traffic (VIP 192.168.50.2/32) to be classified correctly as “server/in” when the host is the DNS server. host_spec should not be broadened by the interface netmask unless explicitly configured.
version: "1.0"visor:
taps:
default_pcap:
input_type: pcapconfig:
iface: ens3host_spec: 192.168.50.2/32policies:
dns_policy:
kind: collectioninput:
tap: default_pcapinput_type: pcapconfig:
bpf: "udp and ((dst host 192.168.50.2 and dst port 53) or (src host 192.168.50.2 and src port 53))"handlers:
modules:
dns:
type: dnsmetric_groups:
enable: [dns_transaction, histograms, quantiles, counters, cardinality, top_ports, top_qnames]
Observed Behavior
dns_xact_in_total stays 0
dns_xact_out_quantiles_us has data
Captured packets show requests to 192.168.50.2 and responses from 192.168.50.2
Expected Behavior
With host_spec limited to 192.168.50.2/32, the traffic should be classified as server-side, so dns_xact_in_total should increase.
Analysis
In PcapInputStream, parse_host_spec() is called, but for libpcap the code also calls _get_hosts_from_libpcap_iface(), which adds the interface IP + netmask (e.g., 192.168.50.0/24). As a result, any LAN destination like 192.168.50.22 matches toHost, and DNS xacts get counted as client-side.
Relevant code:
PcapInputStream.cpp:
direction check: ~401-412
_get_hosts_from_libpcap_iface() invoked in libpcap path ~176-190
Workaround
Setting pcap_source: af_packet avoids adding interface host ranges, and the metrics classify correctly.
Suggestion
If host_spec is explicitly provided, consider skipping _get_hosts_from_libpcap_iface() (or provide a config flag to disable auto host detection).
Hi @zanyoo, thanks for the detailed report and the spot-on analysis. The fix is merged to develop (#790): on a libpcap input with an explicit host_spec, pktvisord no longer widens it with the capture interface's subnet, so your VIP /32 stays authoritative and the DNS response is classified server-side (dns_xact_in increments). With no host_spec set, the previous auto-detect behavior is unchanged.
You can try it from the develop image, which is rebuilt on each merge to develop (allow a few minutes for CI after the merge):
docker pull netboxlabs/pktvisor:latest-develop
Run it with your existing config (the same host_spec: 192.168.50.2/32 on ens3). There is also a static musl build at netboxlabs/pktvisor:develop-alpine.
One behavior note from the change: for live capture, -H / host_spec is now authoritative (it replaces interface auto-detection instead of appending to it). On a dual-stack interface, list every address family you care about in host_spec, since setting only one family disables auto-detection for both.
Give it a try and let us know if dns_xact_in_total now increments for your server-side DNS traffic.
Activity
fix(pcap): early-return before getifaddrs when host_spec set; guard i…
fix(pcap): recompute host set on each parse_host_spec to avoid stale …
fix(pcap): pass computed host_set_provided to helper for defense-in-d…
fix(pcap): don't widen explicit host_spec with the interface subnet (…
leoparente commentedon Jun 26, 2026
Hi @zanyoo, thanks for the detailed report and the spot-on analysis. The fix is merged to
develop(#790): on a libpcap input with an explicithost_spec, pktvisord no longer widens it with the capture interface's subnet, so your VIP/32stays authoritative and the DNS response is classified server-side (dns_xact_inincrements). With nohost_specset, the previous auto-detect behavior is unchanged.You can try it from the develop image, which is rebuilt on each merge to
develop(allow a few minutes for CI after the merge):Run it with your existing config (the same
host_spec: 192.168.50.2/32onens3). There is also a static musl build atnetboxlabs/pktvisor:develop-alpine.One behavior note from the change: for live capture,
-H/host_specis now authoritative (it replaces interface auto-detection instead of appending to it). On a dual-stack interface, list every address family you care about inhost_spec, since setting only one family disables auto-detection for both.Give it a try and let us know if
dns_xact_in_totalnow increments for your server-side DNS traffic.