rustdesk / rustdesk-server

RustDesk Server Program
https://rustdesk.com/server
GNU Affero General Public License v3.0
6.46k stars 1.36k forks source link

The server sends the UDP packets via the wrong interface. #447

Open TByte007 opened 2 months ago

TByte007 commented 2 months ago

Describe the bug When my brother (or whoever) connects on the outside interface this happens: The packets are coming via home0 which has 10.0.0.1/24 network:

:> tcpdump -ni home0 host 10.0.0.2 and port 21116

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on home0, link-type EN10MB (Ethernet), snapshot length 262144 bytes 23:47:10.303677 IP 10.0.0.2.54467 > 10.0.0.1.21116: UDP, length 15 23:47:14.302891 IP 10.0.0.2.54467 > 10.0.0.1.21116: UDP, length 15

But are going out via aone0 which has the real IP to the ISP.

:> tcpdump -ni aone0 host 10.0.0.2 and port 21116

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on aone0, link-type EN10MB (Ethernet), snapshot length 262144 bytes 23:45:39.300826 IP 10.0.0.1.21116 > 10.0.0.2.50965: UDP, length 4 23:45:42.300950 IP 10.0.0.1.21116 > 10.0.0.2.50965: UDP, length 4

The only way to "fix" it is to restart the demons (hbbs/hbbr) and connect BEFORE my brother. Basically whoever is first only he can connect. I'm guessing it somehow binds/connects the socket including the interface or i have no idea what is going on exactly.

Describe the environment FreeBSD 14.0 router, no dockers or anything. How to Reproduce the bug explained in the description

Expected behavior I should be able to connect from both the inside and the outside interfaces.

sierja commented 3 weeks ago

I have confirmed this problem exists on the Docker based version of HBBS in host network mode as well.

@rustdesk I think the problem is probably caused by the use of FramedSocket in handle_udp when it's listening on an unspecified address (0.0.0.0) then sending a reply as it's then left up to the OS to choose an interface. The workaround for those impacted by this bug is not to use Rustdesk HBBS with multiple interfaces/IPs.

When coding a fix, please consider those that need to have Rustdesk listening on multiple interfaces at the same time (as opposed to tying it to one interface/IP)