Skip to content

Commit 236e84c

Browse files
authored
feat: add logging for forwarded TCP connections
part of #7963 log TCP connections as they are forwarded by gVisor
1 parent 791144d commit 236e84c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tailnet/conn.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ func (c *Conn) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.U
943943
return c.netStack.DialContextUDP(ctx, ipp)
944944
}
945945

946-
func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) {
946+
func (c *Conn) forwardTCP(src, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) {
947+
logger := c.logger.Named("tcp").With(slog.F("src", src.String()), slog.F("dst", dst.String()))
947948
c.mutex.Lock()
948949
ln, ok := c.listeners[listenKey{"tcp", "", fmt.Sprint(dst.Port())}]
949950
c.mutex.Unlock()
@@ -961,10 +962,14 @@ func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts [
961962
defer t.Stop()
962963
select {
963964
case ln.conn <- conn:
965+
logger.Info(context.Background(), "accepted connection")
964966
return
965967
case <-ln.closed:
968+
logger.Info(context.Background(), "listener closed; closing connection")
966969
case <-c.closed:
970+
logger.Info(context.Background(), "tailnet closed; closing connection")
967971
case <-t.C:
972+
logger.Info(context.Background(), "listener timed out accepting; closing connection")
968973
}
969974
_ = conn.Close()
970975
}, opts, true

0 commit comments

Comments
 (0)