-
Notifications
You must be signed in to change notification settings - Fork 51
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
Commits on Jan 31, 2024
-
Parse
ip%scope
in CLI argumentsCurrently, 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.
Configuration menu - View commit details
-
Copy full SHA for 1cb9bf3 - Browse repository at this point
Copy the full SHA 1cb9bf3View commit details
Commits on Feb 1, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 46fe68e - Browse repository at this point
Copy the full SHA 46fe68eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 24c0d7f - Browse repository at this point
Copy the full SHA 24c0d7fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 093e628 - Browse repository at this point
Copy the full SHA 093e628View commit details -
Use
ScopedV6Addr
inhumility 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`.
Configuration menu - View commit details
-
Copy full SHA for aa598f1 - Browse repository at this point
Copy the full SHA aa598f1View commit details -
Configuration menu - View commit details
-
Copy full SHA for f728bf8 - Browse repository at this point
Copy the full SHA f728bf8View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.