-
-
Notifications
You must be signed in to change notification settings - Fork 16k
Add methods to TCP and UDP sockets to modify hop limit (refresh of #94678) #138744
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
Open
Mallets
wants to merge
10
commits into
rust-lang:main
Choose a base branch
from
Mallets:set_ipv6_sock_hop_limit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dd43edc
Add methods to TCP and UDP sockets to modify hop limit
Mallets 8827e04
Use IPv6 addresses in hop_limit_v6 docs
Mallets 867327f
Update tracking issue to 139166
Mallets 6362319
Update docs according to PR review
Mallets a258576
Fix unused_variables
Mallets be7a9dd
fix: add cfg guards on unsupported wasi p2 and p3 targets
Mallets d7ee60c
fix: tidy PAL and unsafe blocks CI failure
Mallets b0fa536
fix: tidy CI
Mallets 61fbce5
fix: port tests to new TCP testing framework
Mallets 32b4838
Trigger CI
Mallets 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -498,6 +498,27 @@ impl TcpStream { | |
| Ok(raw as u32) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
| pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { | ||
| unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; | ||
| Ok(raw as u8) | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| pub fn take_error(&self) -> io::Result<Option<io::Error>> { | ||
| self.inner.take_error() | ||
| } | ||
|
|
@@ -626,6 +647,27 @@ impl TcpListener { | |
| Ok(raw as u32) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { | ||
| unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; | ||
| Ok(raw as u8) | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { | ||
| unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } | ||
| } | ||
|
|
@@ -850,6 +892,49 @@ impl UdpSocket { | |
| Ok(raw as u32) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn set_hop_limit_v6(&self, limit: u8) -> io::Result<()> { | ||
| unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn set_hop_limit_v6(&self, _: u8) -> io::Result<()> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| let raw: c_int = unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)? }; | ||
| Ok(raw as u8) | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn hop_limit_v6(&self) -> io::Result<u8> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn set_multicast_hop_limit_v6(&self, limit: u8) -> io::Result<()> { | ||
| unsafe { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn set_multicast_hop_limit_v6(&self, _: u8) -> io::Result<()> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| #[cfg(not(all(target_os = "wasi", any(target_env = "p2", target_env = "p3"))))] | ||
| pub fn multicast_hop_limit_v6(&self) -> io::Result<u8> { | ||
| let raw: c_int = | ||
| unsafe { getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)? }; | ||
| Ok(raw as u8) | ||
| } | ||
|
|
||
| #[cfg(all(target_os = "wasi", any(target_env = "p2", target_env = "p3")))] | ||
| pub fn multicast_hop_limit_v6(&self) -> io::Result<u8> { | ||
| Err(io::Error::new(ErrorKind::Unsupported, "not supported on this platform")) | ||
| } | ||
|
|
||
| pub fn take_error(&self) -> io::Result<Option<io::Error>> { | ||
| self.inner.take_error() | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This should only be indented four spaces; I'm surprised
rustfmtdoesn't fail on this. Likewise on line 638.View changes since the review
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.
Rustfmt actually doesn't format doctests, currently. It is a bit of a weird limitation.