shadowsocks-rust icon indicating copy to clipboard operation
shadowsocks-rust copied to clipboard

Low speed when creating a tun interface

Open purumpurum2568 opened this issue 1 year ago • 1 comments
trafficstars

Good afternoon, I'm using Raspberry PI and using sslocal and ssserver to create a connection. I also need to create a tun interface, but I have problems with speed:

Regular Internet speed: Download 95-100 Mbps Upload 80-95 Mbps Speed ​​when creating a tun interface: Download 50-55 Mbps Upload 80-85 Mbps Speed ​​when creating local socks and connecting to it via 3proxy: Download 75-80 Mbps Upload 80-85 Mbps

I would like to note that I have no problems when my initial connection speed is about 100 Mbps, but when I use another WIFI network or am in another place where the initial speed is 20 Mbps, then visiting sites with such a connection becomes impossible.

I would also like to note that the issue is precisely the interface that is being created, because the speed with a socks connection is normal.

I launch client shadowsocks-rust this way:

sudo sslocal -s *server_ip:server:port* -k *pass* -m chacha20-ietf-poly1305 -U --tun-interface-name tun0 --protocol tun --timeout 50 --tcp-no-delay --tcp-fast-open

sudo ip link set tun0 up

sudo ip addr add 10.1.2.1/32 dev tun0

sudo ethtool -s tun0 autoneg off speed 1000 duplex full

I launch server shadowsocks-rust this way:

sudo ssserver -k *pass* -m chacha20-ietf-poly1305 -U --server-addr 0.0.0.0:*server_port* --timeout 50 --tcp-no-delay --tcp-multipath

Below I will send some system variables and command outputs. I would like to note that I tried different variations of variables and this way I managed to achieve maximum speed on the client side.

/etc/sysctl.conf client

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
fs.file-max = 51200
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.rmem_default = 65536
net.core.wmem_default = 65536
net.core.netdev_max_backlog = 4096
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1

/etc/sysctl.conf server

net.core.default_qdisc = fq
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 4096
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_mem = 25600 51200 102400
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_congestion_control = cubic

It is also indicated on both sides

ulimit -n 51200

Output of some client side commands

sudo ethtool tun0

Settings for tun0:
	Supported ports: [ ]
	Supported link modes:   Not reported
	Supported pause frame use: No
	Supports auto-negotiation: No
	Supported FEC modes: Not reported
	Advertised link modes:  1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: No
	Advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: off
	MDI-X: Unknown
	Current message level: 0x00000000 (0)
			       
	Link detected: yes
ifconfig tun0

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.1.2.1  netmask 255.255.255.255  destination 10.1.2.1
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
ip a

tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq state UNKNOWN group default qlen 500
    link/none 
    inet 10.1.2.1/32 scope global tun0
       valid_lft forever preferred_lft forever

Options I tried to fix the speed issue:

  1. Tried changing server.
  2. I tried changing the settings in /etc/sysctl.conf, mtu settings and others.
  3. I tried changing the parameters with which I launch the shadowsocks-rust client (tcp-no-delay, tcp-fast-open, buffer-size and others).
  4. I also tried to create an interface using tun2socks, but the speed only got worse.
  5. I tried to optimize the interface and remove delays.

purumpurum2568 avatar Dec 13 '23 16:12 purumpurum2568

The tun interface in this project implementation is still experimental (not optimized yet). But in my network environment, speed test in local network could reach 600Mbps.

I am currently no idea what was happening in your environment. You may try to add some more logs in the program, for example, write a log when received packet from interface, inserted into the state machine, sent to remote server, received from remote server, ... which may help.

zonyitoo avatar Dec 17 '23 14:12 zonyitoo