-
Notifications
You must be signed in to change notification settings - Fork 152
fix: gracefully handle stale interface binding with fallback to default route #1400
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8a06337
fix(build_apple.sh): set minimum deployment targets for iOS and macOS…
xiguagua e99de6e
fix(api): return delay values in milliseconds for get_proxy_delay res…
xiguagua 7545cd8
chore
xiguagua 414fa1b
chore(statistics_manager): comment out memory field and its usage in …
xiguagua 27458ea
feat(clash-ffi): add tracing dependencies and initialize logging for …
xiguagua fbd74a6
Update Apple build script for simulator support
xiguagua b3f3f31
Merge branch 'master' into iOS
xiguagua dd5bc4d
fix: unblock Apple builds
xiguagua 25989da
chore: add apple build mode flag
xiguagua 9047fac
Merge branch 'master' into iOS
xiguagua 5fe25d8
fix: auto-create log file if it does not exist
xiguagua 85a79b6
fix: remove conflicting init_logging that blocked file log layer regi…
xiguagua 1f8a426
Merge branch 'master' into iOS
xiguagua 93cd35b
fix: use child_token() instead of clone() for reload API server cance…
xiguagua eb5f848
Merge branch 'master' into apple
xiguagua 8a9b365
Merge branch 'master' into apple
xiguagua f7cb640
fix: gracefully handle stale interface binding with fallback to defau…
xiguagua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Extract duplicate error handling logic.
The IPv4 and IPv6 branches have identical error handling code for
AddrNotAvailable. Consider extracting this into a helper closure to eliminate duplication.♻️ Proposed refactor to eliminate duplication
pub(crate) fn bind_socket_on_interface( socket: &socket2::Socket, iface: &OutboundInterface, family: socket2::Domain, ) -> io::Result<()> { let index = iface.index; if index == 0 { warn!( "OutboundInterface index is 0, skipping binding to interface {}", iface.name ); return Ok(()); } + let handle_stale = |e: io::Error| { + if e.kind() == io::ErrorKind::AddrNotAvailable { + warn!( + "stale interface index {index} for '{}', \ + falling back to default route: {e}", + iface.name + ); + Ok(()) + } else { + Err(e) + } + }; match family { socket2::Domain::IPV4 => { socket .bind_device_by_index_v4(std::num::NonZeroU32::new(index)) - .or_else(|e| { - if e.kind() == io::ErrorKind::AddrNotAvailable { - warn!( - "stale interface index {index} for '{}', \ - falling back to default route: {e}", - iface.name - ); - Ok(()) - } else { - Err(e) - } - }) + .or_else(handle_stale) } socket2::Domain::IPV6 => { socket .bind_device_by_index_v6(std::num::NonZeroU32::new(index)) - .or_else(|e| { - if e.kind() == io::ErrorKind::AddrNotAvailable { - warn!( - "stale interface index {index} for '{}', \ - falling back to default route: {e}", - iface.name - ); - Ok(()) - } else { - Err(e) - } - }) + .or_else(handle_stale) } _ => Err(io::Error::new( io::ErrorKind::InvalidInput, "unsupported socket family", )), } }🤖 Prompt for AI Agents