QNetworkInterface/Unix: fix DNS eligibility of global addresses

[ChangeLog][QtNetwork][QNetworkInterface] Fixed the reporting the "DNS
eligibility" factor (QNetworkAddressEntry::dnsEligibility) for global IP
addresses. Previously, QNetworkInterface interface erroneously reported
all global addresses as eligible, regardless of whether they had already
been deprecated by the OS or were temporary in the first place.

From the tst_QNetworkInterface::dump output (netmask & broadcast
suppressed for readability, IPv6 prefixes changed to protect the
innocent, but the local part is exactly as found on my system):

   address  0: 192.168.26.33/24  dns-eligible preferred:33546998ms valid:33546998ms
   address  1: 2001:db8::800/128  dns-eligible preferred:264817000ms valid:264817000ms
   address  2: fd00::800/128  dns-eligible preferred:forever valid:forever
   address  3: 2001:db8::2f5b:342c:fc53:b9b2/64  dns-ineligible preferred:12422000ms valid:264817000ms
   address  4: fd00::9351:adff:333d:5c8d/64  dns-ineligible preferred:12421999ms valid:531402999ms
   address  5: fd00::7297:9516:fbb4:17ac/64  dns-ineligible preferred:0ms valid:445585999ms
   address  6: fd00::fdc8:e620:691:3b44/64  dns-eligible preferred:forever valid:forever
   address  7: 2001:db8::ae82:a01:5a8a:e210/64  dns-ineligible preferred:0ms valid:264816999ms
   address  8: 2001:db8::c673:e0a2:8927:2118/64  dns-eligible preferred:264816999ms valid:264816999ms
   address  9: fe80::bd89:b998:4aeb:a5d0%bond0/64  dns-ineligible preferred:forever valid:forever

Prior to this commit, only address 9 was showing as ineligible.

Addresses 1 and 2 come from DHCPv6 and are thus always eligible.
Addresses 3, 4, 5, and 7 are temporary addresses added on account of
RFC 4941 and are therefore ineligible (they have the IFA_F_TEMPORARY
flag set). Note how 5 and 7 have also stopped being preferred. Address 3
is the one I see when I go to ip6.me and address 4 is the one used to
reach the router.

Addresses 6, 8, and 9 are the "permanent" addresses that would normally
be based on the MAC address of the interface, but are actually in
"stable privacy" mode for me (RFC 8064). Address 9 is the link-local
one, which makes it ineligible, leaving the other two stable addresses
eligible.

Addresses 1, 3, 7, and 8 are global, from a DHCPv6-PD delegation from my
ISP, which is why they have finite lifetime. Addresses 2, 4, 5, and 6
are from my local Unique Local Address (ULA) prefix, which is why 2 and
6 are valid forever.

Pick-to: 6.1
Change-Id: If8b43dc9678c4b4ba9c1fffd1668fdcae873c6bd
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Thiago Macieira 2021-03-03 16:58:34 -08:00
parent 7402f4171d
commit 83876c0256

View File

@ -104,14 +104,15 @@ public:
{
// this implements an algorithm that yields the same results as Windows
// produces, for the same input (as far as I can test)
if (isTemporary || isDeprecated)
if (isTemporary || isDeprecated) {
entry->setDnsEligibility(QNetworkAddressEntry::DnsIneligible);
AddressClassification cl = QHostAddressPrivate::classify(entry->ip());
if (cl == LoopbackAddress || cl == LinkLocalAddress)
entry->setDnsEligibility(QNetworkAddressEntry::DnsIneligible);
else
entry->setDnsEligibility(QNetworkAddressEntry::DnsEligible);
} else {
AddressClassification cl = QHostAddressPrivate::classify(entry->ip());
if (cl == LoopbackAddress || cl == LinkLocalAddress)
entry->setDnsEligibility(QNetworkAddressEntry::DnsIneligible);
else
entry->setDnsEligibility(QNetworkAddressEntry::DnsEligible);
}
}
private: