add debug logging for VPN packet flow diagnosis

Add comprehensive console logging at key data path points:
- [TUN-RX]: per-packet TUN read (size, proto, src/dst IP, slow write detection)
- [TUN-TX]: per-packet TUN write (size, success/error)
- [WS-RX]: per-packet WebSocket read from client (size, proto, src/dst IP)
- [WS-TX]: per-packet WebSocket write to client (size, lockWaitMs, writeMs)
- [ROUTE]: routing decisions (TUN->client, client->tun, client->relay, anti-spoof)
- [CONN]: connection lifecycle (init, ready, stats every 10s, disconnect with final stats)
- [STATS]: global traffic stats every 10s (clients, rx/tx bytes and rates)
- [PING]: WebSocket ping failures
- [WS]: WebSocket upgrade with client IP and auth method
- [TUN]: MTU set confirmation, VPN start/stop environment info
This commit is contained in:
2026-07-08 19:14:48 +08:00
parent 3306fc7ee4
commit 616d30bc08
6 changed files with 167 additions and 22 deletions
+8 -1
View File
@@ -4,6 +4,7 @@ package vpn
import (
"fmt"
"log"
"net"
)
@@ -32,5 +33,11 @@ func (t *TUNInterface) AddSubnetRoute(subnet *net.IPNet) error {
}
func (t *TUNInterface) SetMTU(mtu int) error {
return execCmd("ifconfig", t.Name(), "mtu", fmt.Sprintf("%d", mtu))
err := execCmd("ifconfig", t.Name(), "mtu", fmt.Sprintf("%d", mtu))
if err != nil {
log.Printf("[TUN] set MTU dev=%s mtu=%d ok=false err=%v", t.Name(), mtu, err)
} else {
log.Printf("[TUN] set MTU dev=%s mtu=%d ok=true", t.Name(), mtu)
}
return err
}