mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-30 21:26:33 -05:00
fix(conf): add Windows support for Unix Domain Socket
This commit is contained in:
parent
1f1ff246dd
commit
527a12d24e
@ -2,8 +2,10 @@ package v4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@ -141,16 +143,14 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
|
|||||||
if fb.Type == "" && fb.Dest != "" {
|
if fb.Type == "" && fb.Dest != "" {
|
||||||
if fb.Dest == "serve-ws-none" {
|
if fb.Dest == "serve-ws-none" {
|
||||||
fb.Type = "serve"
|
fb.Type = "serve"
|
||||||
} else {
|
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
|
||||||
switch fb.Dest[0] {
|
|
||||||
case '@', '/':
|
|
||||||
fb.Type = "unix"
|
fb.Type = "unix"
|
||||||
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
if strings.HasPrefix(fb.Dest, "@@") && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
||||||
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
||||||
copy(fullAddr, fb.Dest[1:])
|
copy(fullAddr, fb.Dest[1:])
|
||||||
fb.Dest = string(fullAddr)
|
fb.Dest = string(fullAddr)
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
||||||
fb.Dest = "127.0.0.1:" + fb.Dest
|
fb.Dest = "127.0.0.1:" + fb.Dest
|
||||||
}
|
}
|
||||||
@ -159,7 +159,6 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if fb.Type == "" {
|
if fb.Type == "" {
|
||||||
return nil, newError(`Trojan fallbacks: please fill in a valid value for every "dest"`)
|
return nil, newError(`Trojan fallbacks: please fill in a valid value for every "dest"`)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package v4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
@ -121,7 +122,7 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) {
|
|||||||
} else {
|
} else {
|
||||||
// Listen on specific IP or Unix Domain Socket
|
// Listen on specific IP or Unix Domain Socket
|
||||||
receiverSettings.Listen = c.ListenOn.Build()
|
receiverSettings.Listen = c.ListenOn.Build()
|
||||||
listenDS := c.ListenOn.Family().IsDomain() && (c.ListenOn.Domain()[0] == '/' || c.ListenOn.Domain()[0] == '@')
|
listenDS := c.ListenOn.Family().IsDomain() && (filepath.IsAbs(c.ListenOn.Domain()) || c.ListenOn.Domain()[0] == '@')
|
||||||
listenIP := c.ListenOn.Family().IsIP() || (c.ListenOn.Family().IsDomain() && c.ListenOn.Domain() == "localhost")
|
listenIP := c.ListenOn.Family().IsIP() || (c.ListenOn.Family().IsDomain() && c.ListenOn.Domain() == "localhost")
|
||||||
switch {
|
switch {
|
||||||
case listenIP:
|
case listenIP:
|
||||||
|
@ -2,8 +2,10 @@ package v4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@ -90,16 +92,14 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
|||||||
if fb.Type == "" && fb.Dest != "" {
|
if fb.Type == "" && fb.Dest != "" {
|
||||||
if fb.Dest == "serve-ws-none" {
|
if fb.Dest == "serve-ws-none" {
|
||||||
fb.Type = "serve"
|
fb.Type = "serve"
|
||||||
} else {
|
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
|
||||||
switch fb.Dest[0] {
|
|
||||||
case '@', '/':
|
|
||||||
fb.Type = "unix"
|
fb.Type = "unix"
|
||||||
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
if strings.HasPrefix(fb.Dest, "@@") && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
||||||
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
||||||
copy(fullAddr, fb.Dest[1:])
|
copy(fullAddr, fb.Dest[1:])
|
||||||
fb.Dest = string(fullAddr)
|
fb.Dest = string(fullAddr)
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
||||||
fb.Dest = "127.0.0.1:" + fb.Dest
|
fb.Dest = "127.0.0.1:" + fb.Dest
|
||||||
}
|
}
|
||||||
@ -108,7 +108,6 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if fb.Type == "" {
|
if fb.Type == "" {
|
||||||
return nil, newError(`VLESS fallbacks: please fill in a valid value for every "dest"`)
|
return nil, newError(`VLESS fallbacks: please fill in a valid value for every "dest"`)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package v5cfg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ func (c InboundConfig) BuildV5(ctx context.Context) (proto.Message, error) {
|
|||||||
} else {
|
} else {
|
||||||
// Listen on specific IP or Unix Domain Socket
|
// Listen on specific IP or Unix Domain Socket
|
||||||
receiverSettings.Listen = c.ListenOn.Build()
|
receiverSettings.Listen = c.ListenOn.Build()
|
||||||
listenDS := c.ListenOn.Family().IsDomain() && (c.ListenOn.Domain()[0] == '/' || c.ListenOn.Domain()[0] == '@')
|
listenDS := c.ListenOn.Family().IsDomain() && (filepath.IsAbs(c.ListenOn.Domain()) || c.ListenOn.Domain()[0] == '@')
|
||||||
listenIP := c.ListenOn.Family().IsIP() || (c.ListenOn.Family().IsDomain() && c.ListenOn.Domain() == "localhost")
|
listenIP := c.ListenOn.Family().IsIP() || (c.ListenOn.Family().IsDomain() && c.ListenOn.Domain() == "localhost")
|
||||||
switch {
|
switch {
|
||||||
case listenIP:
|
case listenIP:
|
||||||
|
Loading…
Reference in New Issue
Block a user