feat(wrapper): add UnwrapConn to remaining TCP conn wrappers

Add UnwrapConn() to the admission, proxyproto, conn limiter, metrics,
and observer/stats TCP connection wrappers, complementing the traffic
limiter's limitConn added in the previous commit.

This makes the unwrapConn() helper in handler/sshd able to peel through
any combination of these wrappers uniformly, keeping the pattern
complete and future-proof for handlers that assert on concrete
connection types.
This commit is contained in:
ginuerzh
2026-06-13 14:43:49 +08:00
parent bc44baba55
commit 49ceda6cc2
5 changed files with 30 additions and 0 deletions
+6
View File
@@ -44,6 +44,12 @@ func WrapConn(admission admission.Admission, c net.Conn) net.Conn {
} }
} }
// UnwrapConn returns the underlying connection, allowing type assertions
// through wrapper layers.
func (c *serverConn) UnwrapConn() net.Conn {
return c.Conn
}
// Read checks the remote address against the admission controller // Read checks the remote address against the admission controller
// before delegating to the underlying connection. If denied, it returns // before delegating to the underlying connection. If denied, it returns
// io.EOF to signal end-of-stream. // io.EOF to signal end-of-stream.
+6
View File
@@ -14,6 +14,12 @@ type serverConn struct {
ctx context.Context ctx context.Context
} }
// UnwrapConn returns the underlying connection, allowing type assertions
// through wrapper layers.
func (c *serverConn) UnwrapConn() net.Conn {
return c.Conn
}
func (c *serverConn) Context() context.Context { func (c *serverConn) Context() context.Context {
return c.ctx return c.ctx
} }
+6
View File
@@ -36,6 +36,12 @@ func WrapConn(limiter limiter.Limiter, c net.Conn) net.Conn {
} }
} }
// UnwrapConn returns the underlying connection, allowing type assertions
// through wrapper layers.
func (c *serverConn) UnwrapConn() net.Conn {
return c.Conn
}
func (c *serverConn) SyscallConn() (rc syscall.RawConn, err error) { func (c *serverConn) SyscallConn() (rc syscall.RawConn, err error) {
if sc, ok := c.Conn.(syscall.Conn); ok { if sc, ok := c.Conn.(syscall.Conn); ok {
rc, err = sc.SyscallConn() rc, err = sc.SyscallConn()
+6
View File
@@ -42,6 +42,12 @@ func WrapConn(service string, c net.Conn) net.Conn {
} }
} }
// UnwrapConn returns the underlying connection, allowing type assertions
// through wrapper layers.
func (c *serverConn) UnwrapConn() net.Conn {
return c.Conn
}
func (c *serverConn) Read(b []byte) (n int, err error) { func (c *serverConn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b) n, err = c.Conn.Read(b)
if counter := xmetrics.GetCounter( if counter := xmetrics.GetCounter(
+6
View File
@@ -45,6 +45,12 @@ func WrapConn(c net.Conn, pStats stats.Stats) net.Conn {
} }
} }
// UnwrapConn returns the underlying connection, allowing type assertions
// through wrapper layers.
func (c *conn) UnwrapConn() net.Conn {
return c.Conn
}
func (c *conn) Read(b []byte) (n int, err error) { func (c *conn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b) n, err = c.Conn.Read(b)
c.stats.Add(stats.KindInputBytes, int64(n)) c.stats.Add(stats.KindInputBytes, int64(n))