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

Parse ip%scope in CLI arguments #443

Merged
merged 6 commits into from
Feb 1, 2024
Merged

Parse ip%scope in CLI arguments #443

merged 6 commits into from
Feb 1, 2024

Commits on Jan 31, 2024

  1. Parse ip%scope in CLI arguments

    Currently, the Humility CLI accepts IP addresses as a `String`, and then
    attempts to parse them as an `Ipv6Addr` and scope. This is a bit
    unfortunate, as when argument parsing is performed by `clap`, the CLI
    will emit a somewhat nicer error message when parsing fails (indicating
    which argument the error occurred while parsing, including the invalid
    value, and suggesting the help text). On the other hand, when we accept
    the argument as a `String`, `clap` doesn't add that useful context to
    the error message.
    
    This branch adds a `ScopedV6Addr` newtype, consisting of an `Ipv6Addr`
    and a scope identifier, and adds a `FromStr` implementation for that
    type. Now, we can use `ScopedV6Addr` as the type of the CLI argument,
    and `clap` performs the parsing for us, getting us somewhat nicer error
    messages. Compare the error output from master:
    
    ```console
    $ cargo run -- --ip ::%fakeiface0 probe
        Finished dev [unoptimized + debuginfo] target(s) in 0.13s
         Running `target/debug/humility --ip '::%fakeiface0' probe`
    humility probe failed: Could not find interface for fakeiface0
    
    $ cargo run -- --ip :: probe
        Finished dev [unoptimized + debuginfo] target(s) in 0.13s
         Running `target/debug/humility --ip '::' probe`
    humility probe failed: Missing scope id in IP (e.g. '%en0')
    
    $ cargo run -- --ip barf%eth0 probe
        Finished dev [unoptimized + debuginfo] target(s) in 0.13s
         Running `target/debug/humility --ip 'barf%eth0' probe`
    humility probe failed: invalid Zip archive: Invalid zip header
    ```
    
    with the error output on this branch:
    
    ```console
    $ cargo run -- --ip :: probe
        Finished dev [unoptimized + debuginfo] target(s) in 0.14s
         Running `target/debug/humility --ip '::' probe`
    error: Invalid value "::" for '--ip <IP>': missing scope ID (e.g. "%en0") in IPv6 address
    
    For more information try --help
    
    $ cargo run -- --ip ::%fakeiface0 probe
        Finished dev [unoptimized + debuginfo] target(s) in 8.45s
         Running `target/debug/humility --ip '::%fakeiface0' probe`
    error: Invalid value "::%fakeiface0" for '--ip <IP>': Could not find interface for fakeiface0
    
    For more information try --help
    
    $ cargo run -- --ip barf%eth0 probe
        Finished dev [unoptimized + debuginfo] target(s) in 12.87s
         Running `target/debug/humility --ip 'barf%eth0' probe`
    error: Invalid value "barf%eth0" for '--ip <IP>': "barf" is not a valid IPv6 address
    
    For more information try --help
    ```
    
    Additionally, using the `ScopedIpv6Addr` type allows us to provide a
    `fmt::Display` implementation that combines the IP address and scope ID
    when formatting. This lets us get rid of a little bit of repeated logic
    for formatting an address with the delimiter, which seems kinda nice to
    me.
    hawkw committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    1cb9bf3 View commit details
    Browse the repository at this point in the history

Commits on Feb 1, 2024

  1. add a doc comment

    hawkw committed Feb 1, 2024
    Configuration menu
    Copy the full SHA
    46fe68e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    24c0d7f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    093e628 View commit details
    Browse the repository at this point in the history
  4. Use ScopedV6Addr in humility rpc

    Because `humility rpc` accepts a list of addresses or a `-i <INTERFACE>`
    (with `--listen`), we still need to use `decode_iface` directly when
    called with `-i`.
    hawkw committed Feb 1, 2024
    Configuration menu
    Copy the full SHA
    aa598f1 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f728bf8 View commit details
    Browse the repository at this point in the history