Skip to content

Commit

Permalink
iphlpapi: Partially fill Ipv4 / Ipv6 metric in GetAdaptersAddresses().
Browse files Browse the repository at this point in the history
CW-Bug-Id: #23640
  • Loading branch information
Paul Gofman committed Feb 24, 2024
1 parent 322b88e commit 11a9ad1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions dlls/iphlpapi/iphlpapi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ static DWORD gateway_and_prefix_addresses_alloc( IP_ADAPTER_ADDRESSES *aa, ULONG
{
struct nsi_ipv4_forward_key *key4;
struct nsi_ipv6_forward_key *key6;
struct nsi_ip_forward_rw *rw;
IP_ADAPTER_GATEWAY_ADDRESS *gw, **gw_next;
IP_ADAPTER_PREFIX *prefix, **prefix_next;
DWORD err, count, i, prefix_len, key_size = (family == AF_INET) ? sizeof(*key4) : sizeof(*key6);
Expand All @@ -1002,11 +1003,14 @@ static DWORD gateway_and_prefix_addresses_alloc( IP_ADAPTER_ADDRESSES *aa, ULONG
void *key;

err = NsiAllocateAndGetTable( 1, ip_module_id( family ), NSI_IP_FORWARD_TABLE, &key, key_size,
NULL, 0, NULL, 0, NULL, 0, &count, 0 );
(void **)&rw, sizeof(*rw), NULL, 0, NULL, 0, &count, 0 );
if (err) return err;

while (aa)
{
if (family == AF_INET) aa->Ipv4Metric = ~0u;
else aa->Ipv6Metric = ~0u;

for (gw_next = &aa->FirstGatewayAddress; *gw_next; gw_next = &(*gw_next)->Next)
;
for (prefix_next = &aa->FirstPrefix; *prefix_next; prefix_next = &(*prefix_next)->Next)
Expand All @@ -1019,6 +1023,12 @@ static DWORD gateway_and_prefix_addresses_alloc( IP_ADAPTER_ADDRESSES *aa, ULONG
luid = (family == AF_INET) ? &key4->luid : &key6->luid;
if (luid->Value != aa->Luid.Value) continue;

if (rw[i].metric)
{
if (family == AF_INET) aa->Ipv4Metric = min( aa->Ipv4Metric, rw[i].metric );
else aa->Ipv6Metric = min( aa->Ipv6Metric, rw[i].metric );
}

if (flags & GAA_FLAG_INCLUDE_GATEWAYS)
{
memset( &sockaddr, 0, sizeof(sockaddr) );
Expand Down Expand Up @@ -1103,7 +1113,7 @@ static DWORD gateway_and_prefix_addresses_alloc( IP_ADAPTER_ADDRESSES *aa, ULONG
}

err:
NsiFreeTable( key, NULL, NULL, NULL );
NsiFreeTable( key, rw, NULL, NULL );
return err;
}

Expand Down Expand Up @@ -1269,11 +1279,8 @@ static DWORD adapters_addresses_alloc( ULONG family, ULONG flags, IP_ADAPTER_ADD
if (err) goto err;
}

if (flags & (GAA_FLAG_INCLUDE_GATEWAYS | GAA_FLAG_INCLUDE_PREFIX))
{
err = call_families( gateway_and_prefix_addresses_alloc, aa, family, flags );
if (err) goto err;
}
err = call_families( gateway_and_prefix_addresses_alloc, aa, family, flags );
if (err) goto err;

err = dns_info_alloc( aa, family, flags );
if (err) goto err;
Expand Down

0 comments on commit 11a9ad1

Please sign in to comment.