Skip to content

Explicit interface list scans adapters even when it has no IPv6 entries #1917

Closed

Description

@bdraco

Problem

When interfaces is an explicit list, normalize_interface_choice always calls ip6_addresses_to_indexes, which calls ifaddr.get_adapters() before looking at the list. The scan runs even when the list holds only IPv4 addresses, where its result is never used.

ifaddr.get_adapters() is blocking, and both the constructor and async_update_interfaces run on the event loop, so this is a blocking call on the loop that could be avoided. It is sub-millisecond on Linux but can be slower with GetAdaptersAddresses on Windows.

An IPv4-only list is the normal case for:

  • macOS and FreeBSD callers, which cannot use dual-stack and pass IPv4 addresses with IPVersion.V4Only.
  • Any caller that has fallen back to IPVersion.V4Only.

Where

Suggested fix

Return early from ip6_addresses_to_indexes when the list has no int entries and no IPv6 strings, so no adapter scan happens.

Related

The list branch silently drops entries that are already resolved ((address, flowinfo, scope_id), index) tuples: ip6_addresses_to_indexes only handles int and str, although its signature accepts the tuple form. A caller that has already scanned the adapters off the loop therefore cannot hand in resolved interfaces to avoid the second scan. Accepting those tuples as-is would let callers skip the on-loop scan for IPv6 too.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions