Skip to content

Commit

Permalink
fix tproxy udp
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Jun 13, 2020
1 parent b0b3a78 commit 0b81bd9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tunnel/tproxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,28 @@ func (s *Server) packetDispatchLoop() {
}
s.mapping[src.String()] = conn
s.mappingLock.Unlock()

conn.Input <- buf[:n]
s.packetChan <- conn

go func(conn *dokodemo.PacketConn) {
defer conn.Close()
back, err := tproxy.DialUDP(
"udp",
&net.UDPAddr{
IP: conn.M.IP,
Port: conn.M.Port,
},
conn.Source.(*net.UDPAddr),
)
if err != nil {
log.Error(common.NewError("failed to dial tproxy udp").Base(err))
return
}
defer back.Close()
for {
select {
case payload := <-conn.Output:
_, err := s.udpListener.WriteTo(payload, conn.Source)
_, err := back.Write(payload)
if err != nil {
log.Error(common.NewError("tproxy udp write error").Base(err))
return
Expand Down

0 comments on commit 0b81bd9

Please sign in to comment.