[SERVER-32017] SockAddr incorrect sort order for IPv4 Created: 17/Nov/17  Updated: 30/Oct/23  Resolved: 20/Nov/17

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: None
Fix Version/s: 3.7.1

Type: Improvement Priority: Minor - P4
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

SockAddr::operator<(SockAddr) treats AF_INET SockAddr objects incorrectly and nonportably.
It orders by the uint32_t sin_addr.s_addr, which is in network byte order. On little-endian, this is major-sorting by LSB. On big-endian it would be correct by accident.

AF_INET6 addresses have no integer equivalent are are correctly compared with network-order memcmp, MSB-first.

So currently on LE machines, we have IPv4 sorted LSB-first, and IPv6 sorted MSB-first.
The obviously correct sorting should be MSB-first, so subnet addresses are grouped together, so we should change the sin_addr.s_addr comparison to a memcmp, or a comparison of the ntohl of these addresses.

I'm not aware of any production impact of this, but that's not saying much as I've been here a month.



 Comments   
Comment by Githook User [ 20/Nov/17 ]

Author:

{'name': 'Billy Donahue', 'username': 'BillyDonahue', 'email': 'billy.donahue@mongodb.com'}

Message: SERVER-32017 remove SockAddr operator<
Branch: master
https://github.com/mongodb/mongo/commit/22f10748b1561f55cd053c9a1b3aba00b83adfc9

Comment by Billy Donahue [ 17/Nov/17 ]

Nobody calls this operator< anymore. Neither removing it nor =delete'ing it cause any build failure.

Comment by Billy Donahue [ 17/Nov/17 ]

The operator was introduced at hash ab654fb9eda000661cde7f3273dac59fcd47caf8
Nov 17, 2007 (with incorrect handling of port numbers), tagged with 0.9.1.

https://github.com/mongodb/mongo/commit/ab654fb9eda000661cde7f3273dac59fcd47caf8#diff-fe83e7c8350e2fc00bc2021e76b1ec0aR49

EndPoint `operator<` depends on the order of its member SockAddr.
EndPoint were used as keys in a `std::map`. `extern EndPointToPC pcMap;`

Generated at Thu Feb 08 04:28:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.