Fix: TPROXY fakeip (#572)

This commit is contained in:
duama
2020-03-10 20:36:24 +08:00
committed by GitHub
parent 14d5137703
commit b263095533
4 changed files with 23 additions and 17 deletions

View File

@ -35,8 +35,7 @@ func NewRedirUDPProxy(addr string) (*RedirUDPListener, error) {
oob := make([]byte, 1024)
for {
buf := pool.BufPool.Get().([]byte)
n, oobn, _, remoteAddr, err := c.ReadMsgUDP(buf, oob)
n, oobn, _, lAddr, err := c.ReadMsgUDP(buf, oob)
if err != nil {
pool.BufPool.Put(buf[:cap(buf)])
if rl.closed {
@ -45,11 +44,11 @@ func NewRedirUDPProxy(addr string) (*RedirUDPListener, error) {
continue
}
origDst, err := getOrigDst(oob, oobn)
rAddr, err := getOrigDst(oob, oobn)
if err != nil {
continue
}
handleRedirUDP(l, buf[:n], remoteAddr, origDst)
handleRedirUDP(l, buf[:n], lAddr, rAddr)
}
}()
@ -65,13 +64,11 @@ func (l *RedirUDPListener) Address() string {
return l.address
}
func handleRedirUDP(pc net.PacketConn, buf []byte, addr *net.UDPAddr, origDst *net.UDPAddr) {
target := socks5.ParseAddrToSocksAddr(origDst)
func handleRedirUDP(pc net.PacketConn, buf []byte, lAddr *net.UDPAddr, rAddr *net.UDPAddr) {
target := socks5.ParseAddrToSocksAddr(rAddr)
packet := &fakeConn{
PacketConn: pc,
origDst: origDst,
rAddr: addr,
lAddr: lAddr,
buf: buf,
}
tunnel.AddPacket(adapters.NewPacket(target, packet, C.REDIR))