mirror of https://github.com/v2ray/v2ray-core
Add padding to abstract unix domain socket in fallbacks (#277)
* fix fall back to abstract unix domain socket in vless and trojan * Update trojan.go * Update vless.go * Update trojan.go * Update vless.go Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com>pull/2757/head
parent
f0403a67a1
commit
425b4b497d
|
@ -2,7 +2,9 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto" // nolint: staticcheck
|
"github.com/golang/protobuf/proto" // nolint: staticcheck
|
||||||
|
|
||||||
|
@ -147,6 +149,11 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
|
||||||
switch fb.Dest[0] {
|
switch fb.Dest[0] {
|
||||||
case '@', '/':
|
case '@', '/':
|
||||||
fb.Type = "unix"
|
fb.Type = "unix"
|
||||||
|
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && runtime.GOOS == "linux" {
|
||||||
|
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work in front of haproxy
|
||||||
|
copy(fullAddr, fb.Dest[1:])
|
||||||
|
fb.Dest = string(fullAddr)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
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
|
||||||
|
|
|
@ -2,7 +2,9 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
@ -102,6 +104,11 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
||||||
switch fb.Dest[0] {
|
switch fb.Dest[0] {
|
||||||
case '@', '/':
|
case '@', '/':
|
||||||
fb.Type = "unix"
|
fb.Type = "unix"
|
||||||
|
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && runtime.GOOS == "linux" {
|
||||||
|
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work in front of haproxy
|
||||||
|
copy(fullAddr, fb.Dest[1:])
|
||||||
|
fb.Dest = string(fullAddr)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue