Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a couple of endianness issues with plNetAddress #1500

Merged
merged 2 commits into from
Oct 13, 2023

Conversation

dgelessus
Copy link
Contributor

This fixes auth server reconnects for servers that send Auth2Cli_ServerAddr messages (i. e. Cyan's server and MOSS). Previously, the received IPv4 address was byte-swapped, making the reconnect always fail.

The srvAddr field is transmitted little-endian and the NetCli receiving
logic converts it to host byte order (also little-endian usually), but
SetHost expects a big-endian value.

This change fixes auth server reconnects for servers that send
Auth2Cli_ServerAddr messages (i. e. Cyan's server and MOSS).
fHost is always stored big-endian in memory, regardless of the host
endianness. It's thus incorrect to read/write it using
ReadLE32/WriteLE32, because then the byte order in the stream changes
depending on the host byte order!

On little-endian systems, fHost has always been read/written big-endian
(because ReadLE32/WriteLE32 don't swap anything on little-endian
systems). To make big-endian systems behave the same way, the field
needs to be read/written as-is with no endianness conversion.
@@ -1861,7 +1861,7 @@ bool RecvMsg<Auth2Cli_ServerAddr>(const uint8_t in[], unsigned, void*)
hsLockGuard(s_critsect);
if (s_active) {
s_active->token = msg.token;
s_active->addr.SetHost(msg.srvAddr);
s_active->addr.SetHost(hsToBE32(msg.srvAddr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we need to byteswap here because the server is (incorrectly) sending the address in LE rather than network order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's "correct" in the sense that it's consistent with the rest of the auth server protocol - IPv4 addresses are treated as integers, so they are transmitted little-endian. It's definitely a weird choice though.

An extra twist is that the NetCli receive machinery also does an implicit endianness conversion before the message gets here. So the IPv4 address is received little-endian, then implicitly converted to host byte order, and finally explicitly converted to big-endian. Fun!

Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks okay to me

@Hoikas Hoikas merged commit 74a5374 into H-uru:master Oct 13, 2023
14 checks passed
@dgelessus dgelessus deleted the plnetaddress_endianness_fixes branch November 29, 2023 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants