From ae98dc75cf30451d3f29684977ff7324e0fc26e4 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Tue, 19 Jan 2021 14:50:21 +0000 Subject: [PATCH] Set unix.SO_REUSEPORT=1 for TPROXY Inbound FakeUDP Solved some issues. --- proxy/dokodemo/fakeudp_linux.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proxy/dokodemo/fakeudp_linux.go b/proxy/dokodemo/fakeudp_linux.go index c1eae057..7de71dab 100644 --- a/proxy/dokodemo/fakeudp_linux.go +++ b/proxy/dokodemo/fakeudp_linux.go @@ -7,6 +7,8 @@ import ( "net" "os" "syscall" + + "golang.org/x/sys/unix" ) func FakeUDP(addr *net.UDPAddr, mark int) (net.PacketConn, error) { @@ -33,6 +35,11 @@ func FakeUDP(addr *net.UDPAddr, mark int) (net.PacketConn, error) { return nil, &net.OpError{Op: "fake", Err: fmt.Errorf("set socket option: SO_REUSEADDR: %s", err)} } + if err = syscall.SetsockoptInt(fileDescriptor, syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil { + syscall.Close(fileDescriptor) + return nil, &net.OpError{Op: "fake", Err: fmt.Errorf("set socket option: SO_REUSEPORT: %s", err)} + } + if err = syscall.SetsockoptInt(fileDescriptor, syscall.SOL_IP, syscall.IP_TRANSPARENT, 1); err != nil { syscall.Close(fileDescriptor) return nil, &net.OpError{Op: "fake", Err: fmt.Errorf("set socket option: IP_TRANSPARENT: %s", err)}