Merge bitcoin/bitcoin#29984: net: Replace ifname check with IFF_LOOPBACK in Discover

a68fed111be393ddbbcd7451f78bc63601253ee0 net: Fix misleading comment for Discover (laanwj)
7766dd280d9a4a7ffdfcec58224d0985cfd4169b net: Replace ifname check with IFF_LOOPBACK in Discover (laanwj)

Pull request description:

  Checking the interface name is kind of brittle. In the age of network namespaces and containers, there is no reason a loopback interface can't be called differently.

  Check for the `IFF_LOOPBACK` flag to detect loopback interface instead.

  Also remove a misleading comment in Discover's doc comment.

ACKs for top commit:
  sipa:
    utACK a68fed111be393ddbbcd7451f78bc63601253ee0
  willcl-ark:
    utACK a68fed111be393ddbbcd7451f78bc63601253ee0
  theuni:
    utACK a68fed111be393ddbbcd7451f78bc63601253ee0. Satoshi-era brittleness :)

Tree-SHA512: e2d7fc541f40f6a6af08286e7bcb0873ff55debdcd8b38b03f274897b673a6fb51d84d6c7241a02a9567ddf2645f50231d91bb1f55307ba7c6e68196c29b0edf
This commit is contained in:
merge-script 2024-05-07 10:28:58 +08:00 committed by pasta
parent daa6eeed5f
commit f1907ea997
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38
2 changed files with 2 additions and 4 deletions

View File

@ -4090,8 +4090,7 @@ void Discover()
{ {
if (ifa->ifa_addr == nullptr) continue; if (ifa->ifa_addr == nullptr) continue;
if ((ifa->ifa_flags & IFF_UP) == 0) continue; if ((ifa->ifa_flags & IFF_UP) == 0) continue;
if (strcmp(ifa->ifa_name, "lo") == 0) continue; if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) continue;
if (strcmp(ifa->ifa_name, "lo0") == 0) continue;
if (ifa->ifa_addr->sa_family == AF_INET) if (ifa->ifa_addr->sa_family == AF_INET)
{ {
struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr); struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);

View File

@ -169,8 +169,7 @@ struct CSerializedNetMsg {
/** /**
* Look up IP addresses from all interfaces on the machine and add them to the * Look up IP addresses from all interfaces on the machine and add them to the
* list of local addresses to self-advertise. * list of local addresses to self-advertise.
* The loopback interface is skipped and only the first address from each * The loopback interface is skipped.
* interface is used.
*/ */
void Discover(); void Discover();