From 236e84c4d6ba94a123a40d7c857e3dac1ccc6830 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Mon, 9 Oct 2023 19:41:26 +0400 Subject: [PATCH] feat: add logging for forwarded TCP connections part of #7963 log TCP connections as they are forwarded by gVisor --- tailnet/conn.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tailnet/conn.go b/tailnet/conn.go index 8808fab775..358241108d 100644 --- a/tailnet/conn.go +++ b/tailnet/conn.go @@ -943,7 +943,8 @@ func (c *Conn) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.U return c.netStack.DialContextUDP(ctx, ipp) } -func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) { +func (c *Conn) forwardTCP(src, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) { + logger := c.logger.Named("tcp").With(slog.F("src", src.String()), slog.F("dst", dst.String())) c.mutex.Lock() ln, ok := c.listeners[listenKey{"tcp", "", fmt.Sprint(dst.Port())}] c.mutex.Unlock() @@ -961,10 +962,14 @@ func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts [ defer t.Stop() select { case ln.conn <- conn: + logger.Info(context.Background(), "accepted connection") return case <-ln.closed: + logger.Info(context.Background(), "listener closed; closing connection") case <-c.closed: + logger.Info(context.Background(), "tailnet closed; closing connection") case <-t.C: + logger.Info(context.Background(), "listener timed out accepting; closing connection") } _ = conn.Close() }, opts, true