extremecoders-re / go-dispatch-proxy

SOCKS5/Transparent load balancing proxy developed in Go, combines multiple internet connections
MIT License
278 stars 45 forks source link

ubuntu20 BUG~ server_response函数 #15

Open golangboy opened 2 years ago

golangboy commented 2 years ago

cat /proc/version

Linux version 5.11.0-34-generic (buildd@lgw01-amd64-001) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #36~20.04.1-Ubuntu SMP Fri Aug 27 08:06:32 UTC 2021

servers_response_linux.go 里的 server_response 函数 发生问题,即 无法向目标地址建立连接,我调试了一下,问题就是在

    dialer := net.Dialer{
        LocalAddr: local_tcpaddr,
        Control: func(network, address string, c syscall.RawConn) error {
            return c.Control(func(fd uintptr) {
                // NOTE: Run with root or use setcap to allow interface binding
                // sudo setcap cap_net_raw=eip ./go-dispatch-proxy
                if err := syscall.BindToDevice(int(fd), load_balancer.iface); err != nil {
                    log.Println("[WARN] Couldn't bind to interface", load_balancer.iface)
                }
            })
        },
    }

    remote_conn, err := dialer.Dial("tcp4", remote_address)

作者的意图大概是用linux的调用绑定到具体的网卡上 ,但其实只要绑定本地地址到对应网卡上的IP上就达到了绑定socket到具体网卡上的效果了,即把servers_response.go里的server_response全部照搬到servers_response_linux.goserver_response 函数就可以了,能达到一样的效果,我按这样修改了达到了期待的效果。

SirSAC commented 2 years ago

Hi, try https://github.com/SirSAC/DisPro

golangboy commented 2 years ago

Hi, try https://github.com/SirSAC/DisPro

It looks really good.I will try it now.

SirSAC commented 2 years ago

Hi, try https://github.com/SirSAC/DisPro

It looks really good.I will try it now.

its working fine for u?

extremecoders-re commented 2 years ago

@blacknight2018 I think specifying the Source IP of the outgoing packet isn't enough on Linux. Infact the older version of gdp didn't BindToDevice at all. However this doesn't guarantee that the same interface will be used whose IP address is specified as the source IP.

Linux uses the weak system model. Check this: https://unix.stackexchange.com/questions/418765/why-does-linux-network-traffic-only-go-through-eth0

Policy based routing or Binding to the interface is the workaround. GDP does the second.

SirSAC commented 2 years ago

Hello, BindToDevice work too for android but the source of an a site needs to be an IP address instead of link address, anyway my phone is not working and not existing anymore by battery issues because made in china and act like a mini bomb in the pocket.