Emulator Issues #12507
openDolphin sometimes uses wrong source IP for UDP packets
0%
Description
Game Name?
Probably any game, I tested with Mario Kart Wii
Game ID? (right click the game in the game list, Properties, Info tab)
RMCP01, probably applies to any game.
What's the problem? Describe what went wrong.
I'm running Dolphin on a linux machine with the following network configuration:
4: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 70:85:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 10.0.1.102/16 brd 10.0.255.255 scope global dynamic noprefixroute enp3s0
valid_lft 2283sec preferred_lft 2283sec
inet 10.20.0.1/16 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 2001:470:70bc:0:xxxx:xxxx:xxxx:xxxx/64 scope global dynamic noprefixroute
valid_lft 6756sec preferred_lft 3156sec
inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link noprefixroute
valid_lft forever preferred_lft forever
10.0.1.102 is my "main" local IP in my normal network. 10.20.0.1 is an extra IP I added to my machine manually.
My actual router (at 10.0.1.1) is configured with a static route to send all 10.20.0.0/16 traffic to 10.0.1.102.
My Wii has the IP 10.20.0.39 with gateway 10.20.0.1 which makes my computer act as a router for the Wii.
Mario Kart Wii (and other Wii games, too) has a feature that when it figures out that two clients are behind the same internet connection (= have the same public IP) they tell eachother their local IP address and try to communicate directly, without using the NAT negotiation server.
When that happens in this particular constellation, Dolphin uses the wrong source IP and the Wii then errors out.
The Wii (10.20.0.39) and Dolphin (10.0.1.102 and 10.20.0.1) come to the conclusion that they are on the same internet connection, and MKWii on Dolphin then tells the MKWii on the Wii "hey, we could skip all that server stuff, just contact me directly at 10.0.1.102".
The Wii obliges and sends an UDP packet from its IP (10.20.0.39) to the IP that Dolphin claimed to have (10.0.1.102). Then Dolphin replies to the Wii at 10.20.0.39, but chooses to use 10.20.0.1 as the sender IP (as that IP is in the same network), and not the IP 10.0.1.102 which it previously claimed to be. The Wii then goes "wait a minute, this response comes from the wrong IP" and cancels the connection.
This probably isn't an issue for most people (since I doubt many people have multiple local IPs on their machine AND want to play with a Wii in the same local network) but I wanted to report it anyways to make sure.
To fix it, I'd assume Dolphin would have to pick ONE local IP address from the system's network stack (in this case the first one, 10.0.1.102), and then always use that IP as sender of UDP packets even if the destination address is in the same subnet as one of the other existing IP addresses.
What steps will reproduce the problem?
I'm not sure if there's an easier way to reproduce this issue, but here's how it should work:
- Take a Linux machine and add another IP to its network interface (ip addr add 10.20.0.1/16 dev eth0)
- Add a static route to your router, forwarding the whole 10.20.0.0/16 network to your Linux machine
- Enable forwarding / routing on that Linux machine: echo 1 > /proc/sys/net/ipv4/ip_forward
- Configure a static IP from that new network on your Wii in the network settings (static IP 10.20.0.39, netmask 255.255.0.0, gateway 10.20.0.1)
- Start Mario Kart Wii on your Wii, connect to Wiimmfi and open a friend room
- Start Mario Kart Wii in Dolphin, connect to Wiimmfi, and try to join your Wii's friend room.
Notice that after a bit of matchmaking the two clients do exchange peer-to-peer data over UDP, but the handshaking process fails (and is repeated over and over again) because the Wii notices the wrong IP.
Is the issue present in the latest development version? For future reference, please also write down the version number of the latest development version.
It is, in 5.0-14191
Is the issue present in the latest stable version?
Not sure, can't successfully compile 5.0-stable. Tried a version from half a year ago (5.0-12725) and the issue is present there, too.
What are your PC specifications? (CPU, GPU, Operating System, more)
i9-9900K, RTX 2080Ti, Ubuntu 20.04
Updated by sepalani over 3 years ago
AFAIK, Dolphin shouldn't (can't?) "change" its source IP address. It's based on the following heuristic:
https://github.com/dolphin-emu/dolphin/blob/5513d5f4f732fb1e436765ab87e7d60ba02b1ad6/Source/Core/Core/IOS/Network/IP/Top.cpp#L165
- Use the default network interface on Windows
- Use a UDP socket and connect to
8.8.8.8
to get its local ip
In theory, your Dolphin's local IP should always be 10.0.1.102
.
Unless the system's sendto
function chooses another IP if the socket is unbound, I guess (probably the case, here).
The solutions I can think of would be:
- Bind an unbound socket before sending data
- Allow the user to choose the IP/network interface from the GUI
- Use the Wii Network settings