fix: dns tcp hijack not working

This commit is contained in:
gVisor bot 2022-10-05 13:29:10 +08:00
parent 894b37b4f3
commit 7e67fb2f58
2 changed files with 13 additions and 2 deletions

View file

@ -4,6 +4,7 @@ package gvisor
import ( import (
"encoding/binary" "encoding/binary"
"io"
"net" "net"
"net/netip" "net/netip"
"time" "time"
@ -60,7 +61,7 @@ func (gh *gvHandler) HandleTCP(tunConn adapter.TCPConn) {
break break
} }
n, err := tunConn.Read(buf[:length]) n, err := io.ReadFull(tunConn, buf[:length])
if err != nil { if err != nil {
break break
} }
@ -70,6 +71,11 @@ func (gh *gvHandler) HandleTCP(tunConn adapter.TCPConn) {
break break
} }
err = binary.Write(tunConn, binary.BigEndian, uint16(len(msg)))
if err != nil {
break
}
_, _ = tunConn.Write(msg) _, _ = tunConn.Write(msg)
} }
}() }()

View file

@ -113,7 +113,7 @@ func New(device device.Device, dnsHijack []netip.AddrPort, tunAddress netip.Pref
break break
} }
n, err := conn.Read(buf[:length]) n, err := io.ReadFull(conn, buf[:length])
if err != nil { if err != nil {
break break
} }
@ -123,6 +123,11 @@ func New(device device.Device, dnsHijack []netip.AddrPort, tunAddress netip.Pref
break break
} }
err = binary.Write(conn, binary.BigEndian, uint16(len(msg)))
if err != nil {
break
}
_, _ = conn.Write(msg) _, _ = conn.Write(msg)
} }
}() }()