feat(listener/runix): support remote UDS forwarding (#102)

This commit is contained in:
Yuan Tong
2026-06-13 13:39:14 +08:00
committed by GitHub
parent 9f610fd163
commit 8b0806bad4
14 changed files with 247 additions and 34 deletions
+6 -6
View File
@@ -42,13 +42,13 @@ func (h *forwardHandler) dialTarget(ctx context.Context, conn net.Conn, ro *xrec
}
addr := target.Addr
if opts := target.Options(); opts != nil {
switch opts.Network {
case "unix":
if opts.Network != "" {
network = opts.Network
default:
if _, _, err := net.SplitHostPort(addr); err != nil {
addr += ":0"
}
}
}
if network != "unix" {
if _, _, err := net.SplitHostPort(addr); err != nil {
addr += ":0"
}
}
+6 -6
View File
@@ -28,13 +28,13 @@ func (h *forwardHandler) handleRawForwarding(ctx context.Context, conn net.Conn,
}
addr := target.Addr
if opts := target.Options(); opts != nil {
switch opts.Network {
case "unix":
if opts.Network != "" {
network = opts.Network
default:
if _, _, err := net.SplitHostPort(addr); err != nil {
addr += ":0"
}
}
}
if network != "unix" {
if _, _, err := net.SplitHostPort(addr); err != nil {
addr += ":0"
}
}
+4 -3
View File
@@ -1,8 +1,8 @@
// Package remote implements a reverse forwarding handler for connections
// received from remote GOST nodes. It listens for "rtcp" and "rudp" protocols
// received from remote GOST nodes. It listens for "rtcp", "rudp", and "runix" protocols
// and forwards the accepted connections to the configured hop.
//
// The handler is registered under the names "rtcp" and "rudp" via
// The handler is registered under the names "rtcp", "rudp", and "runix" via
// NewHandler in init().
//
// # Connection processing flow
@@ -85,6 +85,7 @@ import (
func init() {
registry.HandlerRegistry().Register("rtcp", NewHandler)
registry.HandlerRegistry().Register("rudp", NewHandler)
registry.HandlerRegistry().Register("runix", NewHandler)
}
type forwardHandler struct {
@@ -98,7 +99,7 @@ type forwardHandler struct {
}
// NewHandler creates a remote forwarding handler with the given options.
// The handler registers for "rtcp" and "rudp" protocols.
// The handler registers for "rtcp", "rudp", and "runix" protocols.
func NewHandler(opts ...handler.Option) handler.Handler {
options := handler.Options{}
for _, opt := range opts {
+1 -1
View File
@@ -22,7 +22,7 @@ func (h *forwardHandler) newRecorderObject(ctx context.Context, conn net.Conn, s
Service: h.options.Service,
RemoteAddr: conn.RemoteAddr().String(),
LocalAddr: conn.LocalAddr().String(),
Network: "tcp",
Network: conn.LocalAddr().Network(),
Time: start,
SID: xctx.SidFromContext(ctx).String(),
}
+13
View File
@@ -82,6 +82,19 @@ func TestNewRecorderObject_UDP(t *testing.T) {
}
}
func TestNewRecorderObject_Unix(t *testing.T) {
h := newInitdHandler()
conn := newStringConn(nil)
conn.local = &net.UnixAddr{Name: "/tmp/local.sock", Net: "unix"}
conn.remote = &net.UnixAddr{Name: "/tmp/remote.sock", Net: "unix"}
ro := h.newRecorderObject(context.Background(), conn, time.Now())
if ro.Network != "unix" {
t.Errorf("expected network unix, got %s", ro.Network)
}
}
// ---------------------------------------------------------------------------
// checkRateLimit
// ---------------------------------------------------------------------------