Windows fix: iterate over IPv4/IPv6 interfaces separately

If we get back an IPv6 address as the first gateway then we won't have
the expected IPv4 gateway that the route poker needs to operate.

This iterates through them separately so that we treat the IPv4 and IPv6
sides of an address as separate interfaces which should allow the route
poker to find the one it wants (and just skip the IPv6 one).
pull/2008/head
Jason Rhinelander 2 years ago
parent e398b5bff8
commit 6f31d5108b
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -171,23 +171,27 @@ namespace llarp::net
AllNetworkInterfaces() const override
{
std::vector<InterfaceInfo> all;
iter_adapters([&all](auto* a) {
auto& cur = all.emplace_back();
cur.index = a->IfIndex;
cur.name = a->AdapterName;
for (auto* addr = a->FirstUnicastAddress; addr; addr = addr->Next)
{
SockAddr saddr{*addr->Address.lpSockaddr};
cur.addrs.emplace_back(
saddr.asIPv6(),
ipaddr_netmask_bits(addr->OnLinkPrefixLength, addr->Address.lpSockaddr->sa_family));
}
if (auto* addr = a->FirstGatewayAddress)
{
SockAddr gw{*addr->Address.lpSockaddr};
cur.gateway = gw.getIP();
}
});
for (int af : {AF_INET, AF_INET6})
iter_adapters(
[&all](auto* a) {
auto& cur = all.emplace_back();
cur.index = a->IfIndex;
cur.name = a->AdapterName;
for (auto* addr = a->FirstUnicastAddress; addr; addr = addr->Next)
{
SockAddr saddr{*addr->Address.lpSockaddr};
cur.addrs.emplace_back(
saddr.asIPv6(),
ipaddr_netmask_bits(
addr->OnLinkPrefixLength, addr->Address.lpSockaddr->sa_family));
}
if (auto* addr = a->FirstGatewayAddress)
{
SockAddr gw{*addr->Address.lpSockaddr};
cur.gateway = gw.getIP();
}
},
af);
return all;
}
};

Loading…
Cancel
Save