xtaci / kcptun

A Quantum-Safe Secure Tunnel based on QPP, KCP, FEC, and N:M multiplexing.
MIT License
13.81k stars 2.53k forks source link

Bug: When server has multi IPv6 addresses, only one will work. #911

Open wits-fe opened 1 year ago

wits-fe commented 1 year ago

OS: CentOS 7 There are three IPv6 addresses, for example:

A: 2600::1
B: 2600::2
C: 2600::3

server side command:

server_linux_amd64 -t "127.0.0.1:4321" -l ":5432" -crypt none -mode fast3 -mtu 1280 -sndwnd 2560 -rcvwnd 2560 -ds 2 -ps 2 -nocomp -sockbuf 16777216

On client, it's all ok connect with IPv6 address C, but other two will fail. When client connect with address A, log like this:

2023/03/20 06:48:24 remote address: [2400::11]:57442
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57442
2023/03/20 06:48:24 remote address: [2400::11]:57438
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57438
2023/03/20 06:48:24 stream opened in: [2400::11]:57442(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:57439
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57439
2023/03/20 06:48:24 stream opened in: [2400::11]:57438(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream opened in: [2400::11]:57439(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:57437
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57437
2023/03/20 06:48:24 remote address: [2400::11]:57440
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57440
2023/03/20 06:48:24 stream opened in: [2400::11]:57437(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream opened in: [2400::11]:57440(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:57441
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57441
2023/03/20 06:48:24 stream opened in: [2400::11]:57441(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream opened in: [2400::11]:57438(5) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:57443
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57443
2023/03/20 06:48:24 stream opened in: [2400::11]:57443(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:57444
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:57444
2023/03/20 06:48:24 stream opened in: [2400::11]:57437(5) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream opened in: [2400::11]:57444(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57442(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57438(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57439(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57437(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57438(5) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57440(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57444(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57443(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57437(5) out: 127.0.0.1:4321
2023/03/20 06:48:24 stream closed in: [2400::11]:57441(3) out: 127.0.0.1:4321
2023/03/20 06:48:24 remote address: [2400::11]:50000
2023/03/20 06:48:24 smux version: 1 on connection: [::]:5432 -> [2400::11]:50000
2023/03/20 06:48:24 stream opened in: [2400::11]:50000(3) out: 127.0.0.1:4321
2023/03/20 06:48:25 remote address: [2400::11]:52781
2023/03/20 06:48:25 remote address: [2400::11]:52782
2023/03/20 06:48:25 smux version: 1 on connection: [::]:5432 -> [2400::11]:52782
2023/03/20 06:48:25 smux version: 1 on connection: [::]:5432 -> [2400::11]:52781
2023/03/20 06:48:25 stream opened in: [2400::11]:52782(3) out: 127.0.0.1:4321
2023/03/20 06:48:25 remote address: [2400::11]:52783
2023/03/20 06:48:25 smux version: 1 on connection: [::]:5432 -> [2400::11]:52783
2023/03/20 06:48:25 stream opened in: [2400::11]:52783(3) out: 127.0.0.1:4321
2023/03/20 06:48:25 stream opened in: [2400::11]:52781(3) out: 127.0.0.1:4321
2023/03/20 06:48:25 remote address: [2400::11]:52784
2023/03/20 06:48:25 smux version: 1 on connection: [::]:5432 -> [2400::11]:52784
2023/03/20 06:48:25 stream opened in: [2400::11]:52784(3) out: 127.0.0.1:4321
2023/03/20 06:48:26 remote address: [2400::11]:55246
2023/03/20 06:48:26 smux version: 1 on connection: [::]:5432 -> [2400::11]:55246
2023/03/20 06:48:26 stream opened in: [2400::11]:55246(3) out: 127.0.0.1:4321
2023/03/20 06:48:27 remote address: [2400::11]:64553
2023/03/20 06:48:27 smux version: 1 on connection: [::]:5432 -> [2400::11]:64553
2023/03/20 06:48:27 stream opened in: [2400::11]:64553(3) out: 127.0.0.1:4321
2023/03/20 06:48:28 remote address: [2400::11]:64048
2023/03/20 06:48:28 smux version: 1 on connection: [::]:5432 -> [2400::11]:64048
2023/03/20 06:48:28 stream opened in: [2400::11]:64048(3) out: 127.0.0.1:4321
2023/03/20 06:48:28 stream opened in: [2400::11]:50000(5) out: 127.0.0.1:4321
2023/03/20 06:48:28 stream opened in: [2400::11]:52781(5) out: 127.0.0.1:4321
2023/03/20 06:48:30 stream opened in: [2400::11]:52782(5) out: 127.0.0.1:4321
2023/03/20 06:48:30 stream opened in: [2400::11]:52783(5) out: 127.0.0.1:4321
2023/03/20 06:48:30 stream opened in: [2400::11]:52784(5) out: 127.0.0.1:4321
2023/03/20 06:48:35 stream opened in: [2400::11]:55246(5) out: 127.0.0.1:4321
2023/03/20 06:48:35 stream closed in: [2400::11]:50000(3) out: 127.0.0.1:4321
2023/03/20 06:48:35 stream closed in: [2400::11]:52784(3) out: 127.0.0.1:4321
2023/03/20 06:48:37 stream closed in: [2400::11]:64553(3) out: 127.0.0.1:4321
2023/03/20 06:48:38 stream closed in: [2400::11]:64048(3) out: 127.0.0.1:4321
2023/03/20 06:48:38 stream closed in: [2400::11]:50000(5) out: 127.0.0.1:4321

It didn't work, though.


Now if I use the following: ( listen to one certain IPv6 address )

server_linux_amd64 -t "127.0.0.1:4321" -l "[2600::1]:5333" -crypt none -mode fast3 -mtu 1280 -sndwnd 2560 -rcvwnd 2560 -ds 2 -ps 2 -nocomp -sockbuf 16777216

Then it works.

The problem is that it binds the port on all IPv6 address, but only one works.

Though it can be fixed by running more instances which listen to one IPv6 address, that will consume more memory.

woodlyer commented 1 year ago

https://github.com/apernet/hysteria/issues/592 hysteria has the same problem.