This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Netis Cloud Probe is a network packet capture and forwarding system. Captures packets on one device and forwards them (via GRE, VXLAN, ZMQ, or file) to another for analysis. Core packet capture engine in C (cpworker), management tools in Go (cpdaemon, cpctl, dockerpid).
Uses Mage (Go-based build tool) as the primary build system. cpworker uses CMake internally.
All commands run from the build/ directory:
cd build
# Build all components for Linux
go run mage.go build:linux
# Build individual components
go run mage.go cpworker:linux
go run mage.go cpdaemon:linux
go run mage.go cpctl:linux
go run mage.go dockerpid:linux
# Other platforms: build:linuxARM64, build:darwin, build:darwinARM64, build:windows
# Clean
go run mage.go cleanCLOUD_PROBE_VERSION- Required for final package creationCPWORKER_LIBRARY_ROOT- Root path for C library dependencies (libpcap, libzmq)CPWORKER_CMAKE_TOOLCHAIN_FILE- Optional, for cross-compilationCPWORKER_CMAKE_BUILD_TYPE- Optional, e.g. Release/Debug
ENABLE_DPDK(OFF) - Enable DPDK high-performance packet I/OENABLE_UNIT_TESTS(ON) - Build with Unity test frameworkENABLE_LINK_STATIC_LIBPCAP(OFF) - Static link libpcapENABLE_NO_PIE(OFF) - For QEMU debugging
Unit tests (C, Unity framework):
cd build && go run mage.go cpworker:linux
cd build/tmp/cpworker-linux-amd64 && make testUnit test sources are in cpworker/tests/unit/. Each test file links all cpworker sources (except main.c). Add new tests by adding to the unity_tests list in cpworker/tests/unit/CMakeLists.txt.
Integration tests (Go):
cd cpworker/tests/integration
./build_cpworker.sh
./run_test.shIntegration tests use Go's testing framework with helpers in helpers/ for running cpworker, capturing output, and comparing pcap files. Test data in testdata/.
cpworker uses clang-format (cpworker/.clang-format): Allman braces, IndentWidth=4, ColumnLimit=120.
- cpworker (C) - Core packet capture engine. Entry:
cpworker/src/main.c. Config-driven via JSON. - cpdaemon (Go) - Management daemon that supervises cpworker processes, integrates with CPM (Cloud Probe Manager). Uses Cobra CLI, Viper config, Wire DI.
- cpctl (Go) - CLI control utility for cpworker/cpdaemon.
- cpgolib (Go) - Shared library: cpworker client, slogx logging utilities.
- dockerpid (Go,
cptools/dockerpid/) - Docker container PID utility.
Modular pipeline design: Capturer -> Task -> Output(s)
- Capturer: Packet source abstraction (libpcap, pcap_file, dpdk_pdump). Network namespace support via
netns_linux.c. - Task (
task.c, ~1600 lines): Central orchestration. Each task has one capturer and multiple outputs. Handles rate limiting, statistics, and the config reload lifecycle. - Output modules:
output_gre.c,output_vxlan.c,output_zmq.c,output_file.c,output_rotating_file.c,output_null.c. All implement a common init/write/close interface. - Request Pattern (
req_pattern.c): Detects traffic direction (request vs response) via auto-detection or custom BPF. - Control Plane (
unix-manager.c): Unix socket for runtime commands from cpdaemon/cpctl. - Config (
config.c,cjson_utils.c): JSON parsing. Examples incpworker/examples/,template.jsonshows all fields.
cpworker supports live config reload without restarting:
- Trigger: SIGHUP signal or
reload_configcommand via unix socket - Mechanism: Dedicated reload thread communicates with main thread via mailbox protocol (message types: START, REUSED, REUSED_ACK, EXCHANGE, DESTROY, DONE)
- Task identity: Tasks use
fingerprintfield to match across reloads, allowing reuse of unchanged tasks - Ring buffer (
ring_buffer.c): SPSC queue with mempool for pipeline execution model
SIGHUP- Triggers config reload (task_manager_reload_signal())SIGINT/SIGTERM- Graceful shutdownSIGPIPE- Ignored
Top-level fields: log_level, cpu_affinity, control (unix socket), execution_model (e.g. "rtc"), pipeline (buffer_size_mb)
Task-level: fingerprint, req_pattern, capturer, outputs[]
-
Modifying cpworker (C code):
- Edit sources in
cpworker/src/ - Build-verify cycle:
cd build && go run mage.go clean && go run mage.go cpworker:linux - Test:
cd build/tmp/cpworker-linux-amd64 && make test
- Edit sources in
-
Modifying Go components:
- Edit sources in respective directories
- Rebuild:
cd build && go run mage.go <component>:linux - Go modules use local
replacedirectives for cpgolib
-
Adding new output type:
- Create
cpworker/src/output_<name>.cand.h - Implement output interface (init, write, close)
- Register in
config.coutput type parsing - CMakeLists.txt auto-discovers sources via glob
- Create
- Main development branch:
0.9.x - PRs should target
0.9.xunless specified otherwise
- Primary: Linux (CentOS 7.9, Ubuntu 22.04)
- Also: macOS (Intel/ARM64), Windows
- Toolchain compatibility: GCC 4.8.5, glibc 2.17