eycorsican / go-tun2socks

A tun2socks implementation written in Go.
MIT License
1.29k stars 429 forks source link

无法在arm64 openwrt 运行 #138

Closed f4nff closed 3 years ago

f4nff commented 3 years ago

CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build main.go

编译了一个,但是只能在 Linux NanoPi-R2S 5.4.50 #2 SMP PREEMPT Wed Jul 8 15:28:03 CST 2020 aarch64 aarch64 aarch64 GNU/Linux 下运行, 但是无法在openwrt下运行。

求解, tun2socks-aarch64.zip

f4nff commented 3 years ago
root@OpenWrt:~/tun# ldd tun2socks
        /lib/ld-linux-aarch64.so.1 (0xffffb677f000)
        libpthread.so.0 => /lib/ld-linux-aarch64.so.1 (0xffffb677f000)
        libc.so.6 => /lib/ld-linux-aarch64.so.1 (0xffffb677f000)
        ld-linux-aarch64.so.1 => /lib/ld-linux-aarch64.so.1 (0xffffb6750000)
Error relocating tun2socks: __printf_chk: symbol not found
Error relocating tun2socks: __vfprintf_chk: symbol not found
Error relocating tun2socks: __fprintf_chk: symbol not found
imgk commented 3 years ago

你应该下载对应的OpenWrt SDK,CC和CXX指定为OpenWrt SDK的gcc和g++,这样这可以运行了

f4nff commented 3 years ago

系统是 https://downloads.openwrt.org/snapshots/targets/rockchip/armv8/ 这里下载的, 貌似sdk也在这里, 是编译的时候下载sdk,还是在openwrt系统下载安装sdk 具体能指教下吗?

f4nff commented 3 years ago

给编译一下呀,

imgk commented 3 years ago

如果你运行OpenWrt的设备空间大,可以直接通过opkg安装golang及gcc,不过开启cgo编译时可能会报一个错误,你可以自己google一下解决。

如果运行OpenWrt的空间不够大,那就在一个Linux上使用SDK,下载解压,staging目录下可以找到gcc,具体过程可以google。

f4nff commented 3 years ago
export PATH=/home/openwrt-sdk-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64/staging_dir/toolchain-aarch64_generic_gcc-8.4.0_musl/bin:$PATH
export STAGING_DIR=/home/openwrt-sdk-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64/staging_dir/
env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-openwrt-linux-musl-gcc CXX=aarch64-openwrt-linux-g++ go build -a -ldflags="-w -s"  ./main.go

编译成功,用不了

f4nff commented 3 years ago

CGO_ENABLED=1 CC=aarch64-openwrt-linux-musl-gcc CXX=aarch64-openwrt-linux-g++ GOOS=linux GOARCH=arm64 go build -o server -ldflags '-s -w --extldflags "-static -fpic"' main.go

编译成功,但是用不了。

root@OpenWrt:~/tun# ldd server
ldd: server: Not a valid dynamic program
root@OpenWrt:~/tun# ./server
2020/08/11 02:58:21 failed to open tun device: no such file or directory
root@OpenWrt:~/tun# ./server -h
Usage of ./server:
  -blockOutsideDns
        Prevent DNS leaks by blocking plaintext DNS queries going out through non-TUN interface (may require admin privileges) (Windows only)
  -loglevel string
        Logging level. (debug, info, warn, error, none) (default "info")
  -proxyType string
        Proxy handler type (default "socks")
  -tunAddr string
        TUN interface address (default "10.255.0.2")
  -tunDns string
        DNS resolvers for TUN interface (only need on Windows) (default "8.8.8.8,8.8.4.4")
  -tunGw string
        TUN interface gateway (default "10.255.0.1")
  -tunMask string
        TUN interface netmask, it should be a prefixlen (a number) for IPv6 address (default "255.255.255.0")
  -tunName string
        TUN interface name (default "tun1")
  -tunPersist
        Persist TUN interface after the program exits or the last open file descriptor is closed (Linux only)
  -version
        Print version
root@OpenWrt:~/tun# ./server -tunAddr "10.255.0.2" -tunGw  "10.255.0.1" -tunMask "255.255.255.0" -tu
nName "tun1" -tunDns "8.8.8.8,8.8.4.4" -proxyType "socks" -proxyServer "192.168.6.1:1080"
flag provided but not defined: -proxyServer
Usage of ./server:
  -blockOutsideDns
        Prevent DNS leaks by blocking plaintext DNS queries going out through non-TUN interface (may require admin privileges) (Windows only)
  -loglevel string
        Logging level. (debug, info, warn, error, none) (default "info")
  -proxyType string
        Proxy handler type (default "socks")
  -tunAddr string
        TUN interface address (default "10.255.0.2")
  -tunDns string
        DNS resolvers for TUN interface (only need on Windows) (default "8.8.8.8,8.8.4.4")
  -tunGw string
        TUN interface gateway (default "10.255.0.1")
  -tunMask string
        TUN interface netmask, it should be a prefixlen (a number) for IPv6 address (default "255.255.255.0")
  -tunName string
        TUN interface name (default "tun1")
  -tunPersist
        Persist TUN interface after the program exits or the last open file descriptor is closed (Linux only)
  -version
        Print version
f4nff commented 3 years ago

tun2socks-arm64-openwrt.zip 搞 定。

f4nff commented 3 years ago

请教, `root@OpenWrt:~# route add -net 104.16.0.0/16 gw 10.255.0.1 dev tun1

root@OpenWrt:~# ip route

default via 10.16.0.1 dev pppoe-wan

10.16.0.1 dev pppoe-wan scope link src 10.16.225.6

10.255.0.0/24 dev tun1 scope link src 10.255.0.1

104.16.0.0/16 via 10.255.0.1 dev tun1

192.168.6.0/24 dev br-lan scope link src 192.168.6.1 `

这样设置之后,全局走104.16.0.0/16已经正常走隧道了,也就是tun1/10.255.0.1

我想设置子网 192.168.6.171走隧道,其他不走, 路由表怎么添加?

**### root@OpenWrt:~# route add -net 192.168.6.171 netmask 255.255.255.255 dev tun1

root@OpenWrt:~# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

default 10.16.0.1 0.0.0.0 UG 0 0 0 pppoe-wan

10.16.0.1 * 255.255.255.255 UH 0 0 0 pppoe-wan

10.255.0.0 * 255.255.255.0 U 0 0 0 tun1

192.168.6.0 * 255.255.255.0 U 0 0 0 br-lan

192.168.6.171 * 255.255.255.255 UH 0 0 0 tun1

root@OpenWrt:~# ip route

default via 10.16.0.1 dev pppoe-wan

10.16.0.1 dev pppoe-wan scope link src 10.16.130.161

10.255.0.0/24 dev tun1 scope link src 10.255.0.1

192.168.6.0/24 dev br-lan scope link src 192.168.6.1

192.168.6.171 dev tun1 scope link**

这样设置之后,是不通的、无法上网。

**root@OpenWrt:~# route add -net 192.168.6.171 netmask 255.255.255.255 gw 10.255.0.1 dev tun1

root@OpenWrt:~# route</br>

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

default 10.16.0.1 0.0.0.0 UG 0 0 0 pppoe-wan

10.16.0.1 * 255.255.255.255 UH 0 0 0 pppoe-wan

10.255.0.0 * 255.255.255.0 U 0 0 0 tun1

192.168.6.0 * 255.255.255.0 U 0 0 0 br-lan

192.168.6.171 10.255.0.1 255.255.255.255 UGH 0 0 0 tun1

root@OpenWrt:~# ip route

default via 10.16.0.1 dev pppoe-wan

10.16.0.1 dev pppoe-wan scope link src 10.16.130.161

10.255.0.0/24 dev tun1 scope link src 10.255.0.1

192.168.6.0/24 dev br-lan scope link src 192.168.6.1

192.168.6.171 via 10.255.0.1 dev tun1**

这样设置也是不通的。