Conversation
|
Thank you for your contribution to NETCAP! Before we can accept your pull request, you need to sign our Contributor License Agreement (CLA). To sign the CLA, please read the Individual CLA and comment below with: If you are contributing on behalf of a company or organization, please contact the maintainers to complete the Entity CLA instead. You can re-trigger this check by commenting I have read and agree to the NETCAP CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
dreadl0ck
marked this pull request as ready for review
September 6, 2026 00:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Decision
Keep the portable, single-pass entropy optimization in production. Do not route production entropy through assembly or the four-bank Go variant. The ARM64 entropy assembly evaluation is complete: the kernel is correct, but it does not justify production adoption on the measured packet workload.
Retain the actual assembly and comparison harness behind
entropyexperimentfor reproducibility. Normal builds select onlyentropy.goand no assembly files. Enabling the tag exposes experimental functions; it does not change the decoder call path.Changes
GoFallback, not assembly.Measurements
Apple M5 Max, darwin/arm64, Go 1.27.0. All entropy implementations below allocate zero bytes per call. The shared machine had substantial concurrent load and timing drift; results are descriptive, not statistically significant throughput guarantees.
Portable Optimization Versus Previous Code
Median ns/op from three 1-second samples, 1,500-byte inputs, from the initial implementation run:
These are entropy microbenchmarks, not whole-capture speedups. File entropy already used a histogram; no file-specific speedup is claimed.
Assembly Versus Stronger Go Baseline
Full entropy including zeroing, counting, merging, and exact logs. Medians from five separate 1-second benchmark passes with
-cpu=1:Assembly has some large-buffer wins, but portable four-bank Go captures much of the improvement and wins on 1 MiB repeated data. Large-buffer microbenchmarks alone do not support changing packet entropy.
Real Captured Payloads
The-Ultimate-PCAP-v20200224.pcapng: 21,933 packets, 53,579 Ethernet/IPv4/TCP/UDP layer payload inputs, and zero inputs >= 16 KiB. Payload replay excludes file reading and packet decoding. Median process CPU per complete replay from three samples of ten replays each:Assembly used about 17% more CPU than the production Go baseline in this replay. Process CPU includes runtime work and remains sensitive to frequency/core placement; it is not an isolated hardware-counter measurement.
Differential Verification on a Real Capture
pcaps/The Ultimate PCAP v20250325.pcapng: 49,380 packets, 15,989,140 bytes, mixed per-packet encapsulation (39,236 Ethernet, 9,298 IEEE 802.3br mPackets, 846 Linux cooked). Full default build including DPI, all decoders enabled,--entropy=true, JSON output, file extraction on, one packet worker and one stream worker.Master (
e33ac5f7) versus this branch, comparing every audit record with the per-run header line excluded:PayloadEntropyincludedFile.json(Entropy, MD5/SHA1/SHA256, analysis flags)The 23 differing files are pipeline nondeterminism, not this change. Running the same master binary twice produces the same differing set, with larger divergence:
Exploit.jsonabsent from one runHTTP,DeviceProfile,HostandTLSRecordwere identical in both comparisons. Master-versus-master also varied by 241PayloadEntropyvalues, more than the 20 seen master-versus-branch. Stream decoder output is not reproducible run to run in this checkout, independent of this PR.Entropy Cost on That Capture's Real Payloads
Replaying the 95,261 real packet-layer payload inputs (25,991,234 bytes, zero inputs >= 16 KiB) from the same capture. Median process CPU per full replay, five samples of ten replays:
On this real traffic the merged implementation is about 5.5x faster than the previous packet helper and 5.3x faster than the previous Protobuf helper, while removing 440 MB of allocation churn. Both the assembly and the four-bank Go variant are slower than the merged portable code here, which is the direct evidence for rejecting assembly.
Capture Pipeline
Built three temporary CLI binaries with
nodpi,nomagika,noyara,entropyexperiment, selecting each entropy implementation unconditionally for the trial. Production source was restored before committing. The CLI-only benchmark builds used an ignored placeholder embedded frontend, never served or committed.Replayed the same PCAP concatenated 16 times with
mergecap -a: 350,928 packets, approximately 113 MB. One worker,GOMAXPROCS=1,GOGC=100, entropy on, null output, no payload/context storage, TCP reassembly off, resolver databases/DNS off, WebUI off. One warm-up per binary, then five rounds with rotated binary order.Wall times were highly noisy under concurrent host load; do not interpret their ratios as reliable speedup estimates. The completed run did not demonstrate an assembly benefit. Null output omits serialization, so this is not an output-throughput benchmark. QUIC/Kerberos UDP decoders still initialize in this checkout despite the packet-only include list.
A separate short HTTP CPU profile of the scalar capture attributed approximately 53% cumulative samples to entropy, including approximately 35% to
math.log2. This supports measuring the complete entropy function rather than its counting loop alone; the sample is too short for precise attribution claims.End-to-end timing of the full DPI-enabled pipeline on the 49,380-packet capture could not resolve a difference. Across five alternating repetitions, median process CPU was 24.11 s for master and 22.54 s for this branch with entropy enabled, but 22.64 s versus 24.44 s with entropy disabled — where the two binaries execute identical code. The sign flips, so these end-to-end numbers are noise on this loaded host and no end-to-end speedup is claimed. Entropy is a small share of a full DPI capture, and packet entropy is off by default.
Reproduce the Committed Experiments
For a CLI trial, temporarily select
BytesGo4(data)orBytesARM64(data)inentropy.Bytes, build withnodpi,nomagika,noyara,entropyexperiment, and restore the production function afterward. Use these capture arguments for each binary and a distinct output directory:GOMAXPROCS=1 GOGC=100 ./net capture --read=ultimate-16x.pcapng \ --include=Ethernet,IPv4,TCP,UDP --null=true --entropy=true \ --compress=false --buf=false --payload=false --context=false \ --reverse-dns=false --local-dns=false --macDB=false --ja4DB=false \ --serviceDB=false --geoDB=false --dpi=false --reassemble-connections=false \ --ip4defrag=false --ignore-unknown=true --log-errors=false \ --workers=1 --pbuf=1000 --quiet=true --time=true --http "" --out=trial-outputValidation and Limits
nodpi.go listconfirms[entropy.go] []: no experimental Go or assembly in normal builds.protoc --gogofaster_out=types/. netcap.proto. CLI builds also need frontend embed assets.--http ""to disable WebUI;--http=is rejected here. Use HTTP pprof for profiling: the existing--cpuprofstartup is incorrectly deferred. Neither unrelated CLI issue is changed by this PR.go test -short -race ./...passes with a built frontend bundle and the gitignored PCAP fixtures present. This evaluation concerns the ARM64 entropy kernel, not all possible checksum/parser/SIMD optimizations.types/bfd.go:96calls the value-receivergetStringon a nil*BFDAuthHeader, so--csvexport segfaults on any BFD packet lacking an auth header; and stream decoder output is not reproducible between identical runs.