Skip to content

Commit

Permalink
Add padding to abstract unix domain socket in fallbacks (v2ray#277)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lucifer9 and RPRX authored Oct 8, 2020
1 parent f0403a6 commit 425b4b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions infra/conf/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package conf

import (
"encoding/json"
"runtime"
"strconv"
"syscall"

"github.com/golang/protobuf/proto" // nolint: staticcheck

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions infra/conf/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package conf

import (
"encoding/json"
"runtime"
"strconv"
"syscall"

"github.com/golang/protobuf/proto"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 425b4b4

Please sign in to comment.