From b8d9c79f725e76ea3579ff584cc4878b727b04ea Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Sun, 31 May 2026 16:00:14 +0800 Subject: [PATCH] fix: handle empty host in relay AddrFeature ParseFrom for bind addresses When rtcp listener calls Router.Bind with ":8000" (port-only address), the relay AddrFeature.ParseFrom fails because net.SplitHostPort returns an empty host. This leaves AType at default 0, causing AddrFeature.Encode to return ErrBadAddrType. Fix by normalizing port-only addresses to "0.0.0.0:" in both tunnel and relay connectors before ParseFrom. Also fix error check on resp.WriteTo in the tunnel handler's handleBind to prevent silent protocol desync. --- connector/relay/bind.go | 3 +++ connector/tunnel/bind.go | 3 +++ handler/tunnel/bind.go | 7 +++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/connector/relay/bind.go b/connector/relay/bind.go index cc0f994c..1ab8d3a6 100644 --- a/connector/relay/bind.go +++ b/connector/relay/bind.go @@ -102,6 +102,9 @@ func (c *relayConnector) bind(conn net.Conn, cmd relay.CmdType, network, address Network: nid, }) fa := &relay.AddrFeature{} + if h, _, e := net.SplitHostPort(address); e == nil && h == "" { + address = net.JoinHostPort("0.0.0.0", address) + } fa.ParseFrom(address) req.Features = append(req.Features, fa) if _, err := req.WriteTo(conn); err != nil { diff --git a/connector/tunnel/bind.go b/connector/tunnel/bind.go index b9f51643..5991e845 100644 --- a/connector/tunnel/bind.go +++ b/connector/tunnel/bind.go @@ -69,6 +69,9 @@ func (c *tunnelConnector) initTunnel(conn net.Conn, network, address string) (ad req.Features = append(req.Features, af) af = &relay.AddrFeature{} + if h, _, e := net.SplitHostPort(address); e == nil && h == "" { + address = net.JoinHostPort("0.0.0.0", address) + } af.ParseFrom(address) req.Features = append(req.Features, af) // dst address diff --git a/handler/tunnel/bind.go b/handler/tunnel/bind.go index da2e4bbc..77bb47f2 100644 --- a/handler/tunnel/bind.go +++ b/handler/tunnel/bind.go @@ -57,9 +57,12 @@ func (h *tunnelHandler) handleBind(ctx context.Context, conn net.Conn, network, ID: connectorID, }, ) - resp.WriteTo(conn) + if _, err = resp.WriteTo(conn); err != nil { + log.Error(err) + return + } - // Upgrade connection to multiplex session. + // Upgrade connection to multiplex session. session, err := mux.ClientSession(conn, h.md.muxCfg) if err != nil { return