Skip to content

Commit eeb041d

Browse files
dguidoclaude
andcommitted
Add packet capture and rp_filter diagnostics to debug WireGuard handshake
- Disable reverse path filtering on veth interface (can drop packets) - Add tcpdump capture to see if UDP packets are arriving - Show host and namespace routing tables - Add route debugging to error output 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent cfed2d4 commit eeb041d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/e2e/test-vpn-connectivity.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ cleanup() {
7272
ip link del "${VETH_SERVER}" 2>/dev/null || true
7373

7474
# Clean up temp files
75-
rm -f /tmp/algo-test-wg.conf /tmp/algo-ipsec-test-* 2>/dev/null || true
75+
rm -f /tmp/algo-test-wg.conf /tmp/algo-ipsec-test-* /tmp/algo-tcpdump.log 2>/dev/null || true
7676
rm -rf /tmp/algo-ipsec-test 2>/dev/null || true
77+
pkill -f "tcpdump.*port 51820" 2>/dev/null || true
7778

7879
log_info "Cleanup complete"
7980
exit "${exit_code}"
@@ -281,10 +282,30 @@ test_wireguard() {
281282
log_info "Server WireGuard listening:"
282283
ss -ulnp | grep 51820 || log_warn "WireGuard port not found in ss output"
283284

285+
# Debug: Show routing before WireGuard starts
286+
log_info "Host routing table:"
287+
ip route | grep -E "(10.99|10.49|default)" || true
288+
log_info "Namespace routing table:"
289+
ip netns exec "${NAMESPACE}" ip route || true
290+
291+
# Debug: Check reverse path filtering (can drop packets)
292+
log_info "Reverse path filter settings:"
293+
sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf."${VETH_SERVER}".rp_filter 2>/dev/null || true
294+
295+
# Disable reverse path filtering on veth (can cause packet drops)
296+
sysctl -w net.ipv4.conf.all.rp_filter=0 > /dev/null 2>&1 || true
297+
sysctl -w net.ipv4.conf."${VETH_SERVER}".rp_filter=0 > /dev/null 2>&1 || true
298+
299+
# Start packet capture in background for debugging
300+
local tcpdump_log="/tmp/algo-tcpdump.log"
301+
timeout 20 tcpdump -i any -n port 51820 -c 20 > "${tcpdump_log}" 2>&1 &
302+
local tcpdump_pid=$!
303+
284304
# Start WireGuard in the namespace
285305
log_info "Starting WireGuard in namespace..."
286306
if ! ip netns exec "${NAMESPACE}" wg-quick up "${ns_config}" 2>&1; then
287307
log_error "Failed to start WireGuard in namespace"
308+
kill "${tcpdump_pid}" 2>/dev/null || true
288309
return 1
289310
fi
290311

@@ -323,9 +344,20 @@ test_wireguard() {
323344
wg show wg0 2>&1 || true
324345
log_error "Debug - iptables INPUT chain (first 15 rules):"
325346
iptables -L INPUT -n -v --line-numbers 2>&1 | head -20 || true
347+
log_error "Debug - packet capture (tcpdump):"
348+
kill "${tcpdump_pid}" 2>/dev/null || true
349+
sleep 1
350+
cat "${tcpdump_log}" 2>/dev/null || echo "No capture available"
351+
log_error "Debug - host route to 10.99.0.0/24:"
352+
ip route get 10.99.0.2 2>&1 || true
353+
log_error "Debug - namespace route to server:"
354+
ip netns exec "${NAMESPACE}" ip route get 10.99.0.1 2>&1 || true
326355
return 1
327356
fi
328357

358+
# Stop packet capture
359+
kill "${tcpdump_pid}" 2>/dev/null || true
360+
329361
# Show WireGuard status
330362
ip netns exec "${NAMESPACE}" wg show
331363

0 commit comments

Comments
 (0)