Skip to content

Commit

Permalink
Lower udp timeout and add teardown messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Dec 31, 2024
1 parent fb1a107 commit 509b4e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions client/firewall/uspfilter/forwarder/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"

"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/waiter"
)
Expand Down Expand Up @@ -45,10 +46,10 @@ func (f *Forwarder) handleTCP(r *tcp.ForwarderRequest) {

f.logger.Trace("forwarder: established TCP connection to %v", id)

go f.proxyTCP(inConn, outConn)
go f.proxyTCP(id, inConn, outConn)
}

func (f *Forwarder) proxyTCP(inConn *gonet.TCPConn, outConn net.Conn) {
func (f *Forwarder) proxyTCP(id stack.TransportEndpointID, inConn *gonet.TCPConn, outConn net.Conn) {
defer func() {
if err := inConn.Close(); err != nil {
f.logger.Error("forwarder: inConn close error: %v", err)
Expand Down Expand Up @@ -82,11 +83,13 @@ func (f *Forwarder) proxyTCP(inConn *gonet.TCPConn, outConn net.Conn) {

select {
case <-ctx.Done():
f.logger.Trace("forwarder: tearing down TCP connection %v due to context done", id)
return
case err := <-errChan:
if err != nil && !isClosedError(err) {
f.logger.Error("proxyTCP: copy error: %v", err)
}
f.logger.Trace("forwarder: tearing down TCP connection %v", id)
return
}
}
4 changes: 3 additions & 1 deletion client/firewall/uspfilter/forwarder/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
udpTimeout = 60 * time.Second
udpTimeout = 30 * time.Second
maxPacketSize = 65535
)

Expand Down Expand Up @@ -213,11 +213,13 @@ func (f *Forwarder) proxyUDP(ctx context.Context, pConn *udpPacketConn, id stack

select {
case <-ctx.Done():
f.logger.Trace("forwarder: tearing down UDP connection %v due to context done", id)
return
case err := <-errChan:
if err != nil && !isClosedError(err) {
f.logger.Error("proxyUDP: copy error: %v", err)
}
f.logger.Trace("forwarder: tearing down UDP connection %v", id)
return
}
}
Expand Down

0 comments on commit 509b4e2

Please sign in to comment.