Tunnel inbound: Fix panic when listening on UDS for Xray's internal services (e.g. API) (#6062)

And API supports listening on UNIX domain socket directly

Completes https://github.com/XTLS/Xray-core/pull/5693
This commit is contained in:
Kosta
2026-05-03 00:56:47 +04:00
committed by GitHub
parent 958eb9ea8f
commit e61eeae258
2 changed files with 20 additions and 5 deletions

View File

@@ -4,12 +4,14 @@ import (
"context" "context"
"net" "net"
"sync" "sync"
"strings"
"github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/signal/done" "github.com/xtls/xray-core/common/signal/done"
core "github.com/xtls/xray-core/core" core "github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/outbound" "github.com/xtls/xray-core/features/outbound"
"github.com/xtls/xray-core/transport/internet"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@@ -73,14 +75,27 @@ func (c *Commander) Start() error {
} }
} }
if len(c.listen) > 0 { if len(c.listen) > 0 {
if l, err := net.Listen("tcp", c.listen); err != nil { var addr net.Addr
if strings.HasPrefix(c.listen, "/") || strings.HasPrefix(c.listen, "@") {
addr = &net.UnixAddr{Name: c.listen, Net: "unix"}
} else {
tcpAddr, err := net.ResolveTCPAddr("tcp", c.listen)
if err != nil {
errors.LogErrorInner(context.Background(), err, "API server failed to parse listen address ", c.listen)
return err
}
addr = tcpAddr
}
l, err := internet.ListenSystem(context.Background(), addr, nil)
if err != nil {
errors.LogErrorInner(context.Background(), err, "API server failed to listen on ", c.listen) errors.LogErrorInner(context.Background(), err, "API server failed to listen on ", c.listen)
return err return err
} else {
errors.LogInfo(context.Background(), "API server listening on ", l.Addr())
go listen(l)
} }
errors.LogInfo(context.Background(), "API server listening on ", l.Addr())
go listen(l)
return nil return nil
} }

View File

@@ -95,7 +95,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
} }
} }
} }
if dest.Port == 0 { if dest.Port == 0 && port != "" {
dest.Port = net.Port(common.Must2(strconv.Atoi(port))) dest.Port = net.Port(common.Must2(strconv.Atoi(port)))
} }
if d.portMap != nil && d.portMap[port] != "" { if d.portMap != nil && d.portMap[port] != "" {