fix command line resolution path-based protocols (such as unix socket) address resolution problem

This commit is contained in:
Rehtt
2025-12-12 09:42:34 +08:00
committed by ginuerzh
parent 254699e176
commit b3b5986b63
+37 -3
View File
@@ -376,10 +376,25 @@ func buildServiceConfig(url *url.URL) ([]*config.ServiceConfig, error) {
listener = schemes[1] listener = schemes[1]
} }
addrs := xnet.AddrPortRange(url.Host).Addrs() // For path-based protocols (unix socket, serial), use path as address
isPathBasedProtocol := listener == "unix" || listener == "serial"
var addrs []string
if isPathBasedProtocol {
path := url.EscapedPath()
if url.Host != "" {
addrs = append(addrs, url.Host+strings.TrimPrefix(path, "/"))
} else if path != "" {
addrs = append(addrs, path)
} else {
addrs = append(addrs, url.Host)
}
} else {
addrs = xnet.AddrPortRange(url.Host).Addrs()
if len(addrs) == 0 { if len(addrs) == 0 {
addrs = append(addrs, url.Host) addrs = append(addrs, url.Host)
} }
}
var services []*config.ServiceConfig var services []*config.ServiceConfig
for _, addr := range addrs { for _, addr := range addrs {
@@ -400,7 +415,8 @@ func buildServiceConfig(url *url.URL) ([]*config.ServiceConfig, error) {
var nodes []*config.ForwardNodeConfig var nodes []*config.ForwardNodeConfig
// forward mode // forward mode
if remotes := strings.Trim(url.EscapedPath(), "/"); remotes != "" { // For path-based protocols, path is address not forward target
if remotes := strings.Trim(url.EscapedPath(), "/"); remotes != "" && !isPathBasedProtocol {
i := 0 i := 0
for _, addr := range strings.Split(remotes, ",") { for _, addr := range strings.Split(remotes, ",") {
addrs := xnet.AddrPortRange(addr).Addrs() addrs := xnet.AddrPortRange(addr).Addrs()
@@ -664,8 +680,26 @@ func buildNodeConfig(url *url.URL, m map[string]any) (*config.NodeConfig, error)
nodeMd[k] = v nodeMd[k] = v
} }
// For path-based protocols (unix socket, serial), use path as address
var nodeAddr string
isPathBasedProtocol := dialer == "unix" || dialer == "serial"
if isPathBasedProtocol {
path := url.EscapedPath()
if url.Host != "" {
// Two slashes: host + path = relative path
nodeAddr = url.Host + strings.TrimPrefix(path, "/")
} else if path != "" {
// Three slashes: path is absolute (keep leading slash)
nodeAddr = path
} else {
nodeAddr = url.Host
}
} else {
nodeAddr = url.Host
}
node := &config.NodeConfig{ node := &config.NodeConfig{
Addr: url.Host, Addr: nodeAddr,
Metadata: nodeMd, Metadata: nodeMd,
} }
node.Connector = &config.ConnectorConfig{ node.Connector = &config.ConnectorConfig{