Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically fall back to IPv6 if host has no IPv4 addresses #864

Closed
artizirk opened this issue Dec 14, 2023 · 7 comments · Fixed by #928
Closed

Automatically fall back to IPv6 if host has no IPv4 addresses #864

artizirk opened this issue Dec 14, 2023 · 7 comments · Fixed by #928
Labels
enhancement New feature or request
Milestone

Comments

@artizirk
Copy link

Currently if you don't specify -6 argument then trippy fails to resolve addresses for IPv6 only hosts and exits with an error. Default seems to be set IPv4. It would be great if it could use any address family available.

@fujiapple852
Copy link
Owner

Hi there @artizirk !

Thanks for the suggestion.

What would be the expected behaviour if both IPv4 and IPv6 were available? How would the -4 and -6 flags influence that?

Trippy uses trust-dns (unless using the system resolver, which is the default) which is configured with a LookupIpStrategy that supports various modes:

pub enum LookupIpStrategy {
    /// Only query for A (Ipv4) records
    Ipv4Only,
    /// Only query for AAAA (Ipv6) records
    Ipv6Only,
    /// Query for A and AAAA in parallel
    Ipv4AndIpv6,
    /// Query for Ipv6 if that fails, query for Ipv4
    Ipv6thenIpv4,
    /// Query for Ipv4 if that fails, query for Ipv6 (default)
    Ipv4thenIpv6,
}

Today, Trippy uses only the Ipv4Only and Ipv6Only modes but it could be enhanced to use the others. A similar change could probably be made to the system resolver. I don't think Ipv4AndIpv6 would be useful.

Default seems to be set IPv4

Note that you can change the default in the trippy.toml config file.

addr-family = "ipv6"

@fujiapple852 fujiapple852 added enhancement New feature or request and removed triage labels Dec 14, 2023
artizirk added a commit to artizirk/trippy that referenced this issue Dec 15, 2023
This is useful when target host only has a IPv6 address and the user
has not forced particular address family.

Fixes: fujiapple852#864
artizirk added a commit to artizirk/trippy that referenced this issue Dec 15, 2023
This is useful when target host only has a IPv6 address and the user
has not forced particular address family.

Fixes: fujiapple852#864
@artizirk
Copy link
Author

artizirk commented Dec 15, 2023

Hi!

Flags -4 and -6 should still force Ipv4Only and Ipv6Only modes. Default without those arguments should be trust-dns Ipv4thenIpv6 strategy or whatever the system resolver does without a filter.

I have created an PR #872 that implements this.

@fujiapple852
Copy link
Owner

Hi again @artizirk, thanks for the PR!

Thinking about this a bit more, some considerations below.

Defaults and overrides

Default without those arguments should be trust-dns Ipv4thenIpv6 strategy

I was a bit uneasy about this at first, as it seems to express an option of favouring Ipv4 over Ipv6. However...

Trippy currently supports both the addr-family config file entry and the --ipv4 (-4) and --ipv6 (-6) command line flags, all of which are optional. The command line flags (which are mutually exclusive) take precedence over the config file entry and if neither are provided there is a default of Ipv4.

Therefore Trippy is already opinionated as it defaults to Ipv4.

However, users are able to change the default opinion in the config file (addr-family), and so we would need to provide the same capability here, by exposing all modes (Ipv4Only, Ipv6Only, Ipv4thenIpv6 & Ipv6thenIpv4) in the config file for addr-family as well.

Flags -4 and -6 should still force Ipv4Only and Ipv6Only modes.

Yes I think that is right. The --ipv4 (-4) and --ipv6 (-6) can stay as shortcuts for Ipv4Only and Ipv6Only respectively, and continue to override whatever is set in the config file.

System Resolver

The logic for the system resolver should match the logic for the other resolvers (google, cloudflare etc) which use trust-dns, which is an implementation detail users should not be aware of (fyi as great as it is, I'm looking to swap it for an non-async DNS resolver crate if I can). This means we need to find a way to emulate the various modes provided by trust-dns in the system resolver.

The system resolver will (depending on how the system is configured) returns both Ipv4 and Ipv6 results and so Trippy currently filters the results based on the configured mode.

Therefore we would need to make this filtering smarter to respect the various "Fallback" options that trust-dns provides.

Once we have that, it may make sense to only use the Ipv4AndIpv6 mode for trust-dns, and apply the logic after the call in a uniform way that is independent of the resolver used.

Dns Resolve All

Trippy 0.9.0 introduced the dns-resolve-all option where multiple ICMP traces will be started, one for each IP resolved for a given DNS entry. Today this will be all Ipv4 or all Ipv6, never a mixture. It would seems sensible that the same logic would apply, even when users specify the Ipv4thenIpv6 or Ipv6thenIpv4 config.

If we wanted to support mixing (I'm not sure that I do...) then perhaps the dns-resolve-all flag should renamed to dns-resolve-mode and changed from a boolean to an enum where you can select something like First, AllForFamily or All where the latter mixes Ipv4 and Ipv6.

@fujiapple852
Copy link
Owner

@artizirk do you think you can your PR to cover the above? Let me know if anything is unclear, happy to help guide you on chat (i'm fujiapple852 on both Matrix and Discord)

@fujiapple852
Copy link
Owner

fujiapple852 commented Jan 16, 2024

@artizirk this turned out to be harder than I thought, WIP PR in #928.

This PR adds two new values to the addr-family configuration value in the [strategy] section of the config file and adds the --addr-family command line flag:

# The address family.
#
# Allowed values are:
#   ipv4            - Lookup Ipv4 only
#   ipv6            - Lookup Ipv6 only
#   ipv6-then-ipv4  - Lookup Ipv6 with a fallback to Ipv4
#   ipv4-then-ipv6  - Lookup Ipv4 with a fallback to Ipv6 [default]
addr-family = "ipv4-then-ipv6"

This covers all resolvers (system, google etc).

There is one outstanding issue with the logic to validate the MultipathStrategy which needs the Ipv4/Ipv6 mode as input, which is no longer known in advance given the fallback nature of Ipv4thenIpv6 or Ipv6thenIpv4. I need to work on this to find a way to validate this later in the process.

@fujiapple852 fujiapple852 self-assigned this Jan 21, 2024
@fujiapple852 fujiapple852 added this to the 0.10.0 milestone Jan 21, 2024
@fujiapple852
Copy link
Owner

fujiapple852 commented Jan 21, 2024

Regarding:

There is one outstanding issue with the logic to validate the MultipathStrategy which needs the Ipv4/Ipv6 mode as input, which is no longer known in advance given the fallback nature of Ipv4thenIpv6 or Ipv6thenIpv4.

I solved this by adding logic to "downgrade" both Ipv4thenIpv6 and Ipv6thenIpv4 to be Ipv4Only if the user request the MultipathStrategy::Dublin ECMP strategy for which Trippy does not support Ipv6 yet. This is a little bit "magic" but it will at least be shown in the TUI header so users can see the downgraded mode.

@fujiapple852
Copy link
Owner

This feature is now merged in #928 and will be in the 0.10.0 release of Trippy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants