NetServer: set B_UNCONFIGURED_ADDRESS_FAMILIES flag for IPv6 link local mask

In NetServer::_ConfigureIPv6LinkLocal, it was observed that the
IPv6 link local addresses being added by the function had invalid
masks applied, which upon investigation turned out to be
uninitialised memory.

It turns out that this call:

  BNetworkAddress localLinkMask("ffff:ffff:ffff:ffff::");

...internally relies on getaddrinfo(), which only works if the OS
already has an IPv6 address. Since this is the first IPv6 address,
this will always fail. Since the error code is not checked, this
results in uninitialised memory being used as the IPv6 mask.

There are a variety of possible ways to solve this problem, but
the one presented here passes the B_UNCONFIGURED_ADDRESS_FAMILIES
flag which tells the resolver to always resolve IPv6 addresses.

Change-Id: Ic1fbbd7cffdc6ec87cf160b9d7b02f077d2cf659
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3548
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Jeremy Visser 2020-12-24 19:19:22 +11:00 committed by Adrien Destugues
parent 96ceef6eb2
commit 8fe17af9a7

View File

@ -888,8 +888,16 @@ NetServer::_ConfigureIPv6LinkLocal(const char* name)
addressRaw.s6_addr[15] = mac[5];
BNetworkAddress localLinkAddress(addressRaw, 0);
BNetworkAddress localLinkMask("ffff:ffff:ffff:ffff::"); // 64
BNetworkAddress localLinkBroadcast("fe80::ffff:ffff:ffff:ffff");
BNetworkAddress localLinkMask(
AF_INET6,
"ffff:ffff:ffff:ffff::", // 64
(uint16)0,
B_UNCONFIGURED_ADDRESS_FAMILIES);
BNetworkAddress localLinkBroadcast(
AF_INET6,
"fe80::ffff:ffff:ffff:ffff",
(uint16)0,
B_UNCONFIGURED_ADDRESS_FAMILIES);
if (interface.FindAddress(localLinkAddress) >= 0) {
// uhoh... already has a local link address