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

Add new NetIf variant to NatResolver for IP resolution via network interface #10922

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

garwahl
Copy link
Contributor

@garwahl garwahl commented Sep 15, 2024

Closes #10832

@@ -185,6 +189,7 @@ pub async fn external_addr_with(resolver: NatResolver) -> Option<IpAddr> {
match resolver {
NatResolver::Any | NatResolver::Upnp | NatResolver::PublicIp => resolve_external_ip().await,
NatResolver::ExternalIp(ip) => Some(ip),
NatResolver::NetIf => resolve_net_if_ip(DEFAULT_NET_IF_NAME).ok(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emhane I've decided to return None here if resolution fails given IP resolution here is touted as best effort similarly to how both resolve_external_ip() above behaves in that there is no Err if that fails.

Don't think we should be changing the signature of this method to Result<Option<IpAddr>, NetInterfaceError> since that would leak resolver specific impl detail to consumers. LMKWYT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defo think sig should change. becomes hard to use this tool otherwise if error isn't printed to log. the error could be logged here too, but it's wrong to use thereth::cli target here, and users should be able to read the error without enabling target reth::net. @shekhirin will error log level be written to stdout regardless of target in default node logging setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah think I'd much rather log an error here or lower, than force consumers of external_addr_with to handle a NetInterfaceError even if their NatResolver impl is something unrelated WDYT

Similar reasoning to how resolve_external_ip() discards the error, would be nice to have it log an error instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye, would like it to panic already in cli as well if the error is logged, so if none is returned when the net if ip resolution flag is passed

please open an issue for resolve_external_ip() not logging error

crates/net/nat/src/lib.rs Show resolved Hide resolved
@@ -48,6 +49,9 @@ pub enum NatResolver {
PublicIp,
/// Use the given [`IpAddr`]
ExternalIp(IpAddr),
/// Resolve external IP via the network interface.
#[cfg(not(target_os = "windows"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to not feature gate this variant

Copy link
Member

@emhane emhane Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only works on non-windows

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +197 to +198
error!("Failed to resolve network interface IP: {}", err);
None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emhane Alternatively we could panic!(....) instead here if I'm understanding #10922 (comment) correctly. Have decided to just log an error here but LMKWYT

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just return None if this fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is the behavior that I had originally #10922 (comment)

@mattsse @emhane Do we want to log an error if this fails?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to log an error if this fails?

doesn't hurt but not strictly required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right so does the above current diff SGTY? We log an error and return None on failure. Just checking your comment here #10922 (comment) wasn't referring to something else

crates/net/nat/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +197 to +198
error!("Failed to resolve network interface IP: {}", err);
None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just return None if this fails

@mattsse mattsse added the A-networking Related to networking in general label Sep 19, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's missing is another arm here:

"publicip" | "public-ip" => Self::PublicIp,

crates/net/nat/src/lib.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Related to networking in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate net IF IP resolution into NatResolver
3 participants