From 425b4b497db64c9305937fe871f5abbf0d890aaf Mon Sep 17 00:00:00 2001 From: lucifer Date: Thu, 8 Oct 2020 08:35:21 +0800 Subject: [PATCH] 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> --- infra/conf/trojan.go | 7 +++++++ infra/conf/vless.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/infra/conf/trojan.go b/infra/conf/trojan.go index a633ef76..88fd605d 100644 --- a/infra/conf/trojan.go +++ b/infra/conf/trojan.go @@ -2,7 +2,9 @@ package conf import ( "encoding/json" + "runtime" "strconv" + "syscall" "github.com/golang/protobuf/proto" // nolint: staticcheck @@ -147,6 +149,11 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) { switch fb.Dest[0] { case '@', '/': 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: if _, err := strconv.Atoi(fb.Dest); err == nil { fb.Dest = "127.0.0.1:" + fb.Dest diff --git a/infra/conf/vless.go b/infra/conf/vless.go index 15fb6060..4939696e 100644 --- a/infra/conf/vless.go +++ b/infra/conf/vless.go @@ -2,7 +2,9 @@ package conf import ( "encoding/json" + "runtime" "strconv" + "syscall" "github.com/golang/protobuf/proto" @@ -102,6 +104,11 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) { switch fb.Dest[0] { case '@', '/': 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: if _, err := strconv.Atoi(fb.Dest); err == nil { fb.Dest = "127.0.0.1:" + fb.Dest