ns collector retrieves information about namespaces, currently supporting network namespaces.
Overview
Thens collector helps debug containerized and multi-tenant networking by tracking which network namespace packets and events belong to. This is essential for understanding packet flow in container environments.
What Data is Retrieved
Thens collector retrieves:
- Network namespace inode number: Unique identifier for the network namespace
- Network namespace cookie: Kernel cookie for the namespace (when available)
Probe Installation
The
ns collector does not install any probes. It only retrieves data when namespace information is available in probe arguments.struct net *parametersstruct sk_buff *parameters (reads namespace fromskb->dev)struct net_device *parameters (reads namespace from device)
Command-Line Options
Thens collector has no specific command-line options.
Event Sections Produced
Thens collector produces the netns event section.
See netns event documentation for detailed format.
Event Format
Network Namespace Cookies
Network cookies are a kernel feature that provides:- Stable namespace identifiers
- Survives namespace recreation
- Kernel-managed uniqueness
struct net BTF type for the net_cookie field.
Network cookies are available in recent kernels. If your kernel doesn’t support them, only the inode number will be reported.
Usage Examples
Basic Namespace Tracking
Track network namespaces:Filter by Namespace
Monitor specific namespace:Track Namespace Transitions
See packets crossing namespace boundaries:Container Debugging
Debug container networking:Cross-Namespace Traffic
Track traffic between containers:Example Output
Basic Output
With Cookie
Tracking Across Namespaces
Usingretis sort after collection:
Finding Namespace Information
List Namespaces
Find namespace inode numbers:Container Namespaces
For containers:Root Namespace
The root network namespace typically has inode4026531840 (but this can vary).
Find your system’s root namespace:
Integration with Other Collectors
skb
Essential combination:dev
Interface and namespace:skb-tracking
Track cross-namespace flow:skb-drop
Debug namespace drops:ct (Conntrack)
Namespace-aware conntrack:nft (Netfilter)
Firewall rules per namespace:ovs (OpenVSwitch)
OVS and namespaces:Use Cases
Container Networking Debug
Trace packet in container:Inter-Container Communication
Debug container-to-container traffic:veth Pair Debugging
Trace veth pair operation:Multi-Tenant Isolation
Verify namespace isolation:CNI Plugin Debugging
Debug Kubernetes CNI:Service Mesh Debugging
Understanding Namespace Inodes
Inode Numbers
Namespace inode numbers:- Unique identifier for each namespace
- Assigned when namespace is created
- Can be reused after namespace deletion
- Starts from 4026531840 for initial namespaces
Root vs Container Namespaces
- Root namespace: Where the system starts
- Container namespaces: Created for isolation
- Each container typically gets its own network namespace
Namespace Lifetime
Namespaces exist while:- At least one process is in the namespace, or
- A bind mount exists (e.g., in
/var/run/netns/), or - A process has an open file descriptor to it
Technical Details
Kernel Types
Thens collector activates when these types appear in probe arguments:
struct net *struct sk_buff *(navigates to network namespace)struct net_device *(navigates to network namespace)
Data Extraction
The collector:- Locates
struct netpointer - Reads namespace inode number
- Checks if kernel supports network cookies (BTF inspection)
- Reads cookie if supported
- Formats event section
Cookie Detection
At initialization, the collector:- Uses BTF to inspect
struct net - Looks for
net_cookiemember - Sets flag if found
- This determines if cookies are reported in events
Source Code References
- Collector:
retis/src/collect/collector/ns/ns.rs - eBPF hook:
retis/src/collect/collector/ns/bpf/netns_hook.bpf.c - Event factory: Inline in
ns.rs
Best Practices
- Always combine with dev: Interface names make sense with namespace context
- Use tracking: Enable
skb-trackingfor cross-namespace flows - Filter by namespace: Use
-mto focus on specific namespaces - Identify namespaces first: Use
lsnsor/proc/<pid>/ns/netto find target namespaces - Consider cookies: Use kernel with cookie support for stable identifiers
Performance Considerations
- No probe overhead: Doesn’t install probes
- Minimal extraction: Only reads namespace pointers
- Small data: Adds ~16 bytes per event
- BTF lookup once: Cookie support checked at initialization
- Works with any probe: Activates automatically
Troubleshooting
No Namespace Information
If namespace information is missing:- Verify
nscollector is enabled - Check probes have appropriate arguments
- Verify kernel has namespace support
Can’t Find Namespace
To find a process’s namespace:Namespace Confusion
If namespaces seem mixed up:- Verify inode numbers:
ls -li /proc/*/ns/net - Check namespace relationships
- Ensure correct PID namespace context
- Remember inodes can be reused
Missing Cookies
If cookies aren’t reported:- Check kernel version (cookies are recent feature)
- Verify BTF is available
- Update kernel if needed
- Inode numbers still work without cookies
Filtering by Namespace
By Inode
Root Namespace
Non-Root Namespaces
Container Platform Examples
Docker
Kubernetes
LXC/LXD
See Also
- dev collector - Network device information
- skb collector - Packet data
- netns event format - Event format details
- Filtering - Filter by namespace
