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
+9 -4
View File
@@ -99,10 +99,15 @@ func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, a
return err
}
if network == "tcp" {
switch network {
case "tcp", "tcp4", "tcp6", "unix":
return h.bindTCP(ctx, conn, network, address, ro, log)
} else {
case "udp", "udp4", "udp6":
return h.bindUDP(ctx, conn, network, address, ro, log)
default:
resp.Status = relay.StatusBadRequest
resp.WriteTo(conn)
return fmt.Errorf("network %s is unsupported", network)
}
}
@@ -149,7 +154,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
serviceName := fmt.Sprintf("%s-ep-%s", h.options.Service, ln.Addr())
log = log.WithFields(map[string]any{
"service": serviceName,
"listener": "tcp",
"listener": network,
"handler": "ep-tcp",
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
"src": ln.Addr().String(),
@@ -288,4 +293,4 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
"duration": time.Since(t),
}).Debugf("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
return nil
}
}
+11 -2
View File
@@ -236,6 +236,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
var user, pass string
var address string
var addrFeature *relay.AddrFeature
var networkID relay.NetworkID
for _, f := range req.Features {
switch f.Type() {
@@ -245,7 +246,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
}
case relay.FeatureAddr:
if feature, _ := f.(*relay.AddrFeature); feature != nil {
address = net.JoinHostPort(feature.Host, strconv.Itoa(int(feature.Port)))
addrFeature = feature
}
case relay.FeatureNetwork:
if feature, _ := f.(*relay.NetworkFeature); feature != nil {
@@ -275,6 +276,14 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
if (req.Cmd & relay.FUDP) == relay.FUDP {
network = "udp"
}
if addrFeature != nil {
switch network {
case "unix", "serial":
address = addrFeature.Host
default:
address = net.JoinHostPort(addrFeature.Host, strconv.Itoa(int(addrFeature.Port)))
}
}
ro.Network = network
ro.Host = address
log = log.WithFields(map[string]any{"network": network})
@@ -302,4 +311,4 @@ func (h *relayHandler) Close() error {
h.cancel()
}
return nil
}
}