XDP/AF_XDP Support
NSD includes experimental support for AF_XDP (Address Family XDP) sockets, which provide a fast-path for network packets from the device driver directly to user-space memory. This bypasses the kernel network stack for significant performance improvements.Overview
AF_XDP introduces a fast-path that:- Bypasses the Linux network stack for UDP queries
- Reduces CPU usage for packet processing
- Increases query throughput
- Enables zero-copy packet handling (driver-dependent)
- 2-3x query throughput for high packet rates
- 30-50% CPU reduction for packet processing
- Sub-microsecond latency improvements
XDP in NSD only handles UDP queries. TCP, TLS, and other protocols use the standard network stack.
Requirements
Kernel Requirements
- Linux kernel: 5.3 or newer (5.10+ recommended)
- XDP support: Enabled in kernel configuration
- AF_XDP socket support:
CONFIG_XDP_SOCKETS=y
Driver Requirements
Not all network drivers support AF_XDP. Check compatibility: Fully supported drivers (zero-copy):- Intel: i40e, ice, ixgbe, igb
- Mellanox: mlx5
- Broadcom: bnxt
- Netronome: nfp
- Most drivers support generic XDP with copy mode
- Lower performance but wider compatibility
Build Dependencies
Fromdoc/manual/xdp.rst:14:
Compile NSD with XDP
# Clone NSD repository
git clone https://github.com/NLnetLabs/nsd
cd nsd
# Initialize submodules (contains XDP program)
git submodule update --init
# Generate build files
autoreconf -fi
# Configure with XDP support enabled
./configure --enable-xdp \
--with-configdir=/etc/nsd \
--with-user=nsd
# Verify XDP is enabled
grep "define USE_XDP" config.h
# Should show: #define USE_XDP 1
Configuration
Basic XDP Configuration
- Simple Setup
- Force Copy Mode
- Custom XDP Program
Advanced Configuration
XDP Program Details
Bundled XDP Program
NSD includes two XDP programs:- xdp-dns-redirect_kern.o: Standard version
- xdp-dns-redirect_kern_pinned.o: With map pinning support
xdp-server.c:59, the program redirects UDP traffic to port 53:
- Filters UDP packets to port 53
- Supports IPv4 and IPv6
- Handles Ethernet framing
- Redirects to AF_XDP socket
Custom XDP Program Requirements
If writing your own XDP program, you must define:Loading Your Own XDP Program
# Load XDP program with pinned map
sudo xdp-loader load -p /sys/fs/bpf eth0 \
/usr/share/nsd/xdp-dns-redirect_kern_pinned.o
# Set permissions for NSD
sudo chown nsd /sys/fs/bpf/xsks_map
sudo chmod o+x /sys/fs/bpf
server:
xdp-interface: eth0
# Don't load program
xdp-program-load: no
# Path to program (for map structure)
xdp-program-path: "/usr/share/nsd/xdp-dns-redirect_kern_pinned.o"
# BPF filesystem path
xdp-bpffs-path: "/sys/fs/bpf"
Network Interface Configuration
Queue Configuration
The number of NSD server processes matches the number of combined NIC queues:If
server-count is less than the queue count, excess queues won’t use XDP.
If server-count is greater, excess processes won’t use XDP.IP Address Handling
Fromxdp-server.c:609, NSD automatically detects IP addresses on the XDP interface:
Performance Tuning
CPU Affinity
From the configuration guide, align CPU affinity with NIC queue affinity:Memory Limits
XDP requires locked memory. Fromxdp-server.c:481:
Buffer Sizes
From the source, XDP uses fixed buffer sizes:Batch Processing
Monitoring and Debugging
Check XDP Status
Enable Verbose Logging
- XDP program load/unload
- Socket creation
- Packet processing errors
Performance Metrics
Limitations and Considerations
Current Limitations
From the documentation:Not supported via XDP:
- PROXYv2 protocol
- DNSTAP logging
- Rate limiting (RRL)
- TCP queries
- DNS-over-TLS
Network Protocol Support
XDP code path handles:- ✓ UDP over IPv4
- ✓ UDP over IPv6
- ✓ Ethernet framing
- ✗ VLAN tags (not yet implemented)
- ✗ TCP
- ✗ Other L4 protocols
Zero-Copy vs Copy Mode
Zero-copy mode (driver-dependent):- Highest performance
- Requires driver support
- Default if supported
- Works with all drivers
- Lower performance than zero-copy
- Still faster than standard stack
Troubleshooting
XDP Program Load Fails
XDP Program Load Fails
Symptom: NSD fails to start with XDP errorDiagnosis:Solutions:
- Kernel too old: Upgrade to 5.10+
- Driver doesn’t support: Use
xdp-force-copy: yes - Permissions issue: Check file ownership and modes
Performance Not Improving
Performance Not Improving
Symptom: XDP enabled but no performance gainDiagnosis:Common Causes:
- CPU affinity misconfigured
- Wrong number of server processes
- Driver using generic XDP (slow)
- Copy mode instead of zero-copy
Queries Not Reaching NSD
Queries Not Reaching NSD
Symptom: Queries time out or failDiagnosis:Solutions:
- Verify IP addresses on interface
- Check firewall rules
- Ensure port 53 UDP is open
- Test with non-XDP interface first
Can't Unload XDP Program
Can't Unload XDP Program
Symptom: XDP program remains after NSD stopsCause: NSD loads with
LIBXDP_SKIP_DISPATCHER=1 to allow unloading without CAP_SYS_ADMINManual Unload:Security Considerations
Recommended Security Practices
Migration Strategy
server:
# Enable alongside existing network stack
xdp-interface: eth0
# Keep standard IP bindings as backup
ip-address: 0.0.0.0
# Compare before/after metrics
nsd-control stats > stats-with-xdp.txt
# Monitor CPU usage
top -p $(pidof nsd)
Best Practices
- Match server-count to NIC queues for optimal distribution
- Configure CPU affinity aligned with NIC queue affinity
- Use zero-copy mode when driver supports it
- Monitor performance before and after enabling XDP
- Test thoroughly in non-production first
- Keep fallback ready via standard network stack
Related Topics
- Performance Tuning - General NSD optimization
- Rate Limiting - DoS protection (not available via XDP)
- Server Configuration - Basic server setup