fix: multi issues - TUN read loop, SDWAN routing for TenantID=0, WS keepalive 10s
This commit is contained in:
@@ -95,7 +95,7 @@ func (c *Client) connectAndRun() error {
|
||||
c.publicIP = natResult.PublicIP
|
||||
c.publicPort = natResult.Port1
|
||||
c.localPort = natResult.LocalPort
|
||||
log.Printf("[client] NAT type=%s, publicIP=%s, publicPort=%d, localPort=%d", c.natType, c.publicIP, c.publicPort, c.localPort)
|
||||
log.Printf("[client] SENDING_LOGIN_TOKEN=%d NAT type=%s, publicIP=%s, publicPort=%d, localPort=%d", c.natType, c.publicIP, c.publicPort, c.localPort)
|
||||
|
||||
// 2. WSS Connect
|
||||
scheme := "ws"
|
||||
@@ -642,28 +642,34 @@ func (c *Client) tunReadLoop() {
|
||||
if c.IsStopping() {
|
||||
return
|
||||
}
|
||||
// Log only real errors, not EOF or timeout
|
||||
if err.Error() != "EOF" && err.Error() != "resource temporarily unavailable" {
|
||||
log.Printf("[client] tun read error: %v", err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
log.Printf("[client] tun read error: %v", err)
|
||||
continue
|
||||
}
|
||||
// Skip empty packets or non-IPv4
|
||||
if n == 0 || n < 20 {
|
||||
log.Printf("[client] tun read error: %v", err)
|
||||
continue
|
||||
}
|
||||
pkt := buf[:n]
|
||||
version := pkt[0] >> 4
|
||||
if version != 4 {
|
||||
log.Printf("[client] tun read error: %v", err)
|
||||
continue // skip non-IPv4
|
||||
}
|
||||
dstIP := net.IP(pkt[16:20]).String()
|
||||
c.sdwanMu.RLock()
|
||||
self := c.sdwanIP
|
||||
c.sdwanMu.RUnlock()
|
||||
if dstIP == self {
|
||||
log.Printf("[client] tun read error: %v", err)
|
||||
continue // skip packets to self
|
||||
}
|
||||
// send raw binary to avoid JSON base64 overhead
|
||||
log.Printf("[client] tun: read pkt len=%d dst=%s", n, dstIP)
|
||||
frame := protocol.EncodeRaw(protocol.MsgTunnel, protocol.SubTunnelSDWANRaw, pkt)
|
||||
_ = c.conn.WriteRaw(frame)
|
||||
if err := c.conn.WriteRaw(frame); err != nil {
|
||||
log.Printf("[client] tun write failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user