From ac288b4a207da74337e6da9c88b6806c015ab69a Mon Sep 17 00:00:00 2001 From: Fausto Date: Sat, 5 Mar 2022 13:55:27 -0500 Subject: [PATCH 01/12] add setters and getters for ipv6 socket hop limit --- library/std/src/lib.rs | 1 + library/std/src/net/udp.rs | 76 +++++++++++++++++++++++++++++++ library/std/src/sys_common/net.rs | 18 ++++++++ 3 files changed, 95 insertions(+) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 36e6032b5e4e5..a1d18087ceb90 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -277,6 +277,7 @@ #![feature(hashmap_internals)] #![feature(int_error_internals)] #![feature(intra_doc_pointers)] +#![feature(ipv6_hop_limit)] #![feature(lang_items)] #![feature(linkage)] #![feature(log_syntax)] diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 11a696e92c825..ec206b215add6 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -554,6 +554,82 @@ impl UdpSocket { self.0.ttl() } + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: i32) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(socket.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + + /// Sets the value for the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// This value sets the hop limit field for outgoing multicast packets + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_multicast_hlim_v6(88).expect("set_multicast_hlim_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_multicast_hlim_v6(&self, limit: i32) -> io::Result<()> { + self.0.set_multicast_hlim_v6(limit) + } + + /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); + /// socket.set_multicast_hlim_v6(88).expect("set_multicast_hlim_v6 call failed"); + /// assert_eq!(socket.multicast_hlim_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0.multicast_hlim_v6() + } + /// Executes an operation of the `IP_ADD_MEMBERSHIP` type. /// /// This function specifies a new multicast group for this socket to join. diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 3b7cdd55a081c..cde66dccef48a 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -641,6 +641,24 @@ impl UdpSocket { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: i32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u32) + } + + pub fn set_multicast_hlim_v6(&self, limit: i32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; + Ok(raw as u32) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } From 44c2226513a96edae3f496b16489e07ed1aeb3e8 Mon Sep 17 00:00:00 2001 From: Fausto Date: Sat, 5 Mar 2022 15:39:08 -0500 Subject: [PATCH 02/12] add setters for hop limit to tcp listener and stream and update tests --- library/std/src/net/tcp.rs | 156 ++++++++++++++++++++++++++++++ library/std/src/net/tcp/tests.rs | 17 ++++ library/std/src/net/udp.rs | 4 +- library/std/src/net/udp/tests.rs | 12 +++ library/std/src/sys_common/net.rs | 40 +++++++- 5 files changed, 225 insertions(+), 4 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index cc4e4fd4fdc77..e58ac3a747832 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -540,6 +540,86 @@ impl TcpStream { self.0.ttl() } + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(stream.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + + /// Sets the value for the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// This value sets the hop limit field for outgoing multicast packets + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_multicast_hlim_v6(limit) + } + + /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpStream; + /// + /// let stream = TcpStream::connect("127.0.0.1:54321") + /// .expect("Couldn't connect to the server..."); + /// stream.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(stream.multicast_hlim_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0.multicast_hlim_v6() + } + /// Gets the value of the `SO_ERROR` option on this socket. /// /// This will retrieve the stored error in the underlying socket, clearing @@ -914,6 +994,82 @@ impl TcpListener { self.0.ttl() } + /// Sets the value for the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// This value sets the unicast hop limit field that is used in every packet + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); + /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_hop_limit_v6(limit) + } + + /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); + /// listener.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(listener.hop_limit_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn hop_limit_v6(&self) -> io::Result { + self.0.hop_limit_v6() + } + + /// Sets the value for the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// This value sets the hop limit field for outgoing multicast packets + /// sent from this socket. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); + /// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_multicast_hlim_v6(limit) + } + + /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. + /// + /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(ipv6_hop_limit)] + /// use std::net::TcpListener; + /// + /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); + /// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// assert_eq!(listener.multicast_hlim_v6().unwrap(), 88); + /// ``` + #[unstable(feature = "ipv6_hop_limit", issue = "47727")] + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0.multicast_hlim_v6() + } + #[stable(feature = "net2_mutators", since = "1.9.0")] #[rustc_deprecated( since = "1.16.0", diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs index c2061c1351262..8d38e1d16ec17 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -814,6 +814,23 @@ fn ttl() { assert_eq!(ttl, t!(stream.ttl())); } +#[test] +#[cfg_attr(target_env = "sgx", ignore)] +fn hop_limit() { + let hlim: u32 = 100; + + let addr = next_test_ip6(); + let listener = t!(TcpListener::bind(&addr)); + + t!(listener.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(listener.hop_limit_v6())); + + let stream = t!(TcpStream::connect(&addr)); + + t!(stream.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(stream.hop_limit_v6())); +} + #[test] #[cfg_attr(target_env = "sgx", ignore)] fn set_nonblocking() { diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index ec206b215add6..2ff09457af515 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -569,7 +569,7 @@ impl UdpSocket { /// socket.set_hop_limit_v6(88).expect("set_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn set_hop_limit_v6(&self, limit: i32) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { self.0.set_hop_limit_v6(limit) } @@ -607,7 +607,7 @@ impl UdpSocket { /// socket.set_multicast_hlim_v6(88).expect("set_multicast_hlim_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn set_multicast_hlim_v6(&self, limit: i32) -> io::Result<()> { + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { self.0.set_multicast_hlim_v6(limit) } diff --git a/library/std/src/net/udp/tests.rs b/library/std/src/net/udp/tests.rs index a51113dd9e749..1fd66c4976c41 100644 --- a/library/std/src/net/udp/tests.rs +++ b/library/std/src/net/udp/tests.rs @@ -342,6 +342,18 @@ fn ttl() { assert_eq!(ttl, t!(stream.ttl())); } +#[test] +fn hop_limit() { + let hlim = 100; + + let addr = next_test_ip6(); + + let stream = t!(UdpSocket::bind(&addr)); + + t!(stream.set_hop_limit_v6(hlim)); + assert_eq!(hlim, t!(stream.hop_limit_v6())); +} + #[test] fn set_nonblocking() { each_ip(&mut |addr, _| { diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index cde66dccef48a..513f3fbe20b2c 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -337,6 +337,24 @@ impl TcpStream { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u32) + } + + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; + Ok(raw as u32) + } + pub fn take_error(&self) -> io::Result> { self.inner.take_error() } @@ -437,6 +455,24 @@ impl TcpListener { Ok(raw as u32) } + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) + } + + pub fn hop_limit_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS)?; + Ok(raw as u32) + } + + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; + Ok(raw as u32) + } + pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } @@ -641,7 +677,7 @@ impl UdpSocket { Ok(raw as u32) } - pub fn set_hop_limit_v6(&self, limit: i32) -> io::Result<()> { + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_UNICAST_HOPS, limit as c_int) } @@ -650,7 +686,7 @@ impl UdpSocket { Ok(raw as u32) } - pub fn set_multicast_hlim_v6(&self, limit: i32) -> io::Result<()> { + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } From c60ab7bf60851e1942ced51e57015b8eadc5ff75 Mon Sep 17 00:00:00 2001 From: Fausto Date: Sat, 5 Mar 2022 16:09:03 -0500 Subject: [PATCH 03/12] add noop methods for other sys --- library/std/src/sys/hermit/net.rs | 48 +++++++++++++++++++++++++ library/std/src/sys/sgx/net.rs | 50 ++++++++++++++++++++++++++ library/std/src/sys/unix/l4re.rs | 48 +++++++++++++++++++++++++ library/std/src/sys/unsupported/net.rs | 48 +++++++++++++++++++++++++ library/std/src/sys/wasi/net.rs | 48 +++++++++++++++++++++++++ 5 files changed, 242 insertions(+) diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index f65fd8e53bdc9..b34963dc749fb 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -209,6 +209,22 @@ impl TcpStream { .map_err(|_| io::const_io_error!(ErrorKind::Uncategorized, "unable to get TTL")) } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } @@ -266,6 +282,22 @@ impl TcpListener { unsupported() } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { unsupported() } @@ -392,6 +424,22 @@ impl UdpSocket { unsupported() } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index d14990c6877af..f92a5f48952a8 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -11,6 +11,8 @@ use crate::time::Duration; use super::abi::usercalls; const DEFAULT_FAKE_TTL: u32 = 64; +const DEFAULT_FAKE_HLIM: u32 = 64; + #[derive(Debug, Clone)] pub struct Socket { @@ -207,6 +209,22 @@ impl TcpStream { sgx_ineffective(DEFAULT_FAKE_TTL) } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn hop_limit_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + pub fn take_error(&self) -> io::Result> { Ok(None) } @@ -283,6 +301,22 @@ impl TcpListener { sgx_ineffective(DEFAULT_FAKE_TTL) } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn hop_limit_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + sgx_ineffective(DEFAULT_FAKE_HLIM) + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { sgx_ineffective(()) } @@ -421,6 +455,22 @@ impl UdpSocket { self.0 } + pub fn set_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + self.0 + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index d13e1ecbbfed4..665f589344bdd 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -242,6 +242,22 @@ pub mod net { unimpl!(); } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unimpl!() + } + pub fn ttl(&self) -> io::Result { unimpl!(); } @@ -304,6 +320,22 @@ pub mod net { unimpl!(); } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unimpl!() + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { unimpl!(); } @@ -446,6 +478,22 @@ pub mod net { unimpl!(); } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unimpl!() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unimpl!() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unimpl!() + } + pub fn take_error(&self) -> io::Result> { unimpl!(); } diff --git a/library/std/src/sys/unsupported/net.rs b/library/std/src/sys/unsupported/net.rs index dbb6ce22c22de..9e969a00369b3 100644 --- a/library/std/src/sys/unsupported/net.rs +++ b/library/std/src/sys/unsupported/net.rs @@ -100,6 +100,22 @@ impl TcpStream { self.0 } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } @@ -142,6 +158,22 @@ impl TcpListener { self.0 } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0 + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { self.0 } @@ -268,6 +300,22 @@ impl UdpSocket { self.0 } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn hop_limit_v6(&self) -> io::Result { + self.0 + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + self.0 + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + self.0 + } + pub fn take_error(&self) -> io::Result> { self.0 } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index c66e0e4d328ad..c320e0b9eec63 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -152,6 +152,22 @@ impl TcpStream { unsupported() } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } @@ -234,6 +250,22 @@ impl TcpListener { unsupported() } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { unsupported() } @@ -403,6 +435,22 @@ impl UdpSocket { unsupported() } + pub fn set_hop_limit_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn hop_limit_v6(&self) -> io::Result { + unsupported() + } + + pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + unsupported() + } + + pub fn multicast_hlim_v6(&self) -> io::Result { + unsupported() + } + pub fn take_error(&self) -> io::Result> { unsupported() } From 090c1c93ba4c895f6c8bb08b8ffeeaa60cf761dc Mon Sep 17 00:00:00 2001 From: Fausto Date: Sat, 5 Mar 2022 16:15:19 -0500 Subject: [PATCH 04/12] add unicast and multicast hop limit option for windows --- library/std/src/sys/windows/c.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 9b61b2476d5bb..d30dfbc7d7165 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -215,6 +215,8 @@ pub const IPPROTO_TCP: c_int = 6; pub const IPPROTO_IPV6: c_int = 41; pub const TCP_NODELAY: c_int = 0x0001; pub const IP_TTL: c_int = 4; +pub const IPV6_UNICAST_HOPS: c_int = 4; +pub const IPV6_MULTICAST_HOPS: c_int = 10; pub const IPV6_V6ONLY: c_int = 27; pub const SO_ERROR: c_int = 0x1007; pub const SO_BROADCAST: c_int = 0x0020; From 6d0d29e17ceee90c056121dd9b85a7aafef135fb Mon Sep 17 00:00:00 2001 From: Fausto Date: Sun, 6 Mar 2022 13:19:06 -0500 Subject: [PATCH 05/12] cleanup - remove whitespace --- library/std/src/sys/sgx/net.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index f92a5f48952a8..e2e67292faa77 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -13,7 +13,6 @@ use super::abi::usercalls; const DEFAULT_FAKE_TTL: u32 = 64; const DEFAULT_FAKE_HLIM: u32 = 64; - #[derive(Debug, Clone)] pub struct Socket { inner: Arc, From 36096cfd2bc61a2e5b50d0a8b76df728f314b469 Mon Sep 17 00:00:00 2001 From: Fausto Date: Sun, 6 Mar 2022 13:49:35 -0500 Subject: [PATCH 06/12] fix broken intra doc links --- library/std/src/net/tcp.rs | 8 ++++---- library/std/src/net/udp.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index e58ac3a747832..c0fc4a38a5d8b 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -562,7 +562,7 @@ impl TcpStream { /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`TcpStream::set_hop_limit_v6`]. /// /// # Examples /// @@ -602,7 +602,7 @@ impl TcpStream { /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`TcpStream::set_multicast_hlim_v6`]. /// /// # Examples /// @@ -1015,7 +1015,7 @@ impl TcpListener { /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`TcpListener::set_hop_limit_v6`]. /// /// # Examples /// @@ -1053,7 +1053,7 @@ impl TcpListener { /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`TcpListener::set_multicast_hlim_v6`]. /// /// # Examples /// diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 2ff09457af515..11f8a97fd6368 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -575,7 +575,7 @@ impl UdpSocket { /// Gets the value of the `IPV6_UNICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`UdpSocket::set_hop_limit_v6`]. /// /// # Examples /// @@ -613,7 +613,7 @@ impl UdpSocket { /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_hop_limit_ipv6`]. + /// For more information about this option, see [`UdpSocket::set_multicast_hlim_v6`]. /// /// # Examples /// From b3e9e948846331dd1dd757acbe0d8dccfb34ca20 Mon Sep 17 00:00:00 2001 From: Fausto Date: Tue, 8 Mar 2022 12:20:17 -0500 Subject: [PATCH 07/12] rename multicast methods --- library/std/src/net/tcp.rs | 32 +++++++++++++------------- library/std/src/net/udp.rs | 16 ++++++------- library/std/src/sys/hermit/net.rs | 12 +++++----- library/std/src/sys/sgx/net.rs | 12 +++++----- library/std/src/sys/unix/l4re.rs | 12 +++++----- library/std/src/sys/unsupported/net.rs | 12 +++++----- library/std/src/sys/wasi/net.rs | 12 +++++----- library/std/src/sys_common/net.rs | 12 +++++----- 8 files changed, 60 insertions(+), 60 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index c0fc4a38a5d8b..ac84c95cfa4c2 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -593,16 +593,16 @@ impl TcpStream { /// /// let stream = TcpStream::connect("127.0.0.1:54321") /// .expect("Couldn't connect to the server..."); - /// stream.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// stream.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { - self.0.set_multicast_hlim_v6(limit) + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_multicast_hop_limit_v6(limit) } /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`TcpStream::set_multicast_hlim_v6`]. + /// For more information about this option, see [`TcpStream::set_multicast_hop_limit_v6`]. /// /// # Examples /// @@ -612,12 +612,12 @@ impl TcpStream { /// /// let stream = TcpStream::connect("127.0.0.1:54321") /// .expect("Couldn't connect to the server..."); - /// stream.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); - /// assert_eq!(stream.multicast_hlim_v6().unwrap(), 88); + /// stream.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); + /// assert_eq!(stream.multicast_hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn multicast_hlim_v6(&self) -> io::Result { - self.0.multicast_hlim_v6() + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0.multicast_hop_limit_v6() } /// Gets the value of the `SO_ERROR` option on this socket. @@ -1044,16 +1044,16 @@ impl TcpListener { /// use std::net::TcpListener; /// /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); - /// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); + /// listener.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { - self.0.set_multicast_hlim_v6(limit) + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_multicast_hop_limit_v6(limit) } /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`TcpListener::set_multicast_hlim_v6`]. + /// For more information about this option, see [`TcpListener::set_multicast_hop_limit_v6`]. /// /// # Examples /// @@ -1062,12 +1062,12 @@ impl TcpListener { /// use std::net::TcpListener; /// /// let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); - /// listener.set_multicast_hlim_v6(88).expect("set_hop_limit_v6 call failed"); - /// assert_eq!(listener.multicast_hlim_v6().unwrap(), 88); + /// listener.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); + /// assert_eq!(listener.multicast_hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn multicast_hlim_v6(&self) -> io::Result { - self.0.multicast_hlim_v6() + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0.multicast_hop_limit_v6() } #[stable(feature = "net2_mutators", since = "1.9.0")] diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 11f8a97fd6368..52335ce7ed30a 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -604,16 +604,16 @@ impl UdpSocket { /// use std::net::UdpSocket; /// /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); - /// socket.set_multicast_hlim_v6(88).expect("set_multicast_hlim_v6 call failed"); + /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { - self.0.set_multicast_hlim_v6(limit) + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { + self.0.set_multicast_hop_limit_v6(limit) } /// Gets the value of the `IPV6_MULTICAST_HOPS` option on this socket. /// - /// For more information about this option, see [`UdpSocket::set_multicast_hlim_v6`]. + /// For more information about this option, see [`UdpSocket::set_multicast_hop_limit_v6`]. /// /// # Examples /// @@ -622,12 +622,12 @@ impl UdpSocket { /// use std::net::UdpSocket; /// /// let socket = UdpSocket::bind("127.0.0.1:54321").expect("couldn't bind to address"); - /// socket.set_multicast_hlim_v6(88).expect("set_multicast_hlim_v6 call failed"); - /// assert_eq!(socket.multicast_hlim_v6().unwrap(), 88); + /// socket.set_multicast_hop_limit_v6(88).expect("set_multicast_hop_limit_v6 call failed"); + /// assert_eq!(socket.multicast_hop_limit_v6().unwrap(), 88); /// ``` #[unstable(feature = "ipv6_hop_limit", issue = "47727")] - pub fn multicast_hlim_v6(&self) -> io::Result { - self.0.multicast_hlim_v6() + pub fn multicast_hop_limit_v6(&self) -> io::Result { + self.0.multicast_hop_limit_v6() } /// Executes an operation of the `IP_ADD_MEMBERSHIP` type. diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index b34963dc749fb..f53841aa14a0a 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -217,11 +217,11 @@ impl TcpStream { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } @@ -290,11 +290,11 @@ impl TcpListener { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } @@ -432,11 +432,11 @@ impl UdpSocket { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index e2e67292faa77..5622a7fc874de 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -216,11 +216,11 @@ impl TcpStream { sgx_ineffective(DEFAULT_FAKE_HLIM) } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { sgx_ineffective(()) } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { sgx_ineffective(DEFAULT_FAKE_HLIM) } @@ -308,11 +308,11 @@ impl TcpListener { sgx_ineffective(DEFAULT_FAKE_HLIM) } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { sgx_ineffective(()) } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { sgx_ineffective(DEFAULT_FAKE_HLIM) } @@ -462,11 +462,11 @@ impl UdpSocket { self.0 } - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { self.0 } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0 } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index 665f589344bdd..cd9292d5a7039 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -250,11 +250,11 @@ pub mod net { unimpl!() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unimpl!() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unimpl!() } @@ -328,11 +328,11 @@ pub mod net { unimpl!() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unimpl!() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unimpl!() } @@ -486,11 +486,11 @@ pub mod net { unimpl!() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unimpl!() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unimpl!() } diff --git a/library/std/src/sys/unsupported/net.rs b/library/std/src/sys/unsupported/net.rs index 9e969a00369b3..d79f506bbd496 100644 --- a/library/std/src/sys/unsupported/net.rs +++ b/library/std/src/sys/unsupported/net.rs @@ -108,11 +108,11 @@ impl TcpStream { self.0 } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { self.0 } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0 } @@ -166,11 +166,11 @@ impl TcpListener { self.0 } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { self.0 } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0 } @@ -308,11 +308,11 @@ impl UdpSocket { self.0 } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { self.0 } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { self.0 } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index c320e0b9eec63..2c15d84926833 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -160,11 +160,11 @@ impl TcpStream { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } @@ -258,11 +258,11 @@ impl TcpListener { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } @@ -443,11 +443,11 @@ impl UdpSocket { unsupported() } - pub fn set_multicast_hlim_v6(&self, _: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, _: u32) -> io::Result<()> { unsupported() } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { unsupported() } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 513f3fbe20b2c..a14b2ab2366cd 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -346,11 +346,11 @@ impl TcpStream { Ok(raw as u32) } - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; Ok(raw as u32) } @@ -464,11 +464,11 @@ impl TcpListener { Ok(raw as u32) } - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; Ok(raw as u32) } @@ -686,11 +686,11 @@ impl UdpSocket { Ok(raw as u32) } - pub fn set_multicast_hlim_v6(&self, limit: u32) -> io::Result<()> { + pub fn set_multicast_hop_limit_v6(&self, limit: u32) -> io::Result<()> { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS, limit as c_int) } - pub fn multicast_hlim_v6(&self) -> io::Result { + pub fn multicast_hop_limit_v6(&self) -> io::Result { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_HOPS)?; Ok(raw as u32) } From 5ed178741358db3258d804f332d82e497b7eb11a Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Tue, 30 Aug 2022 11:21:07 +0200 Subject: [PATCH 08/12] Implement `Ready::into_inner()` --- library/core/src/future/ready.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/core/src/future/ready.rs b/library/core/src/future/ready.rs index 48f20f90a3253..a07b63fb62b90 100644 --- a/library/core/src/future/ready.rs +++ b/library/core/src/future/ready.rs @@ -24,6 +24,30 @@ impl Future for Ready { } } +impl Ready { + /// Consumes the `Ready`, returning the wrapped value. + /// + /// # Panics + /// + /// Will panic if this [`Ready`] was already polled to completion. + /// + /// # Examples + /// + /// ``` + /// #![feature(ready_into_inner)] + /// use std::future; + /// + /// let a = future::ready(1); + /// assert_eq!(a.into_inner(), 1); + /// ``` + #[unstable(feature = "ready_into_inner", issue = "101196")] + #[must_use] + #[inline] + pub fn into_inner(self) -> T { + self.0.expect("Called `into_inner()` on `Ready` after completion") + } +} + /// Creates a future that is immediately ready with a value. /// /// Futures created through this function are functionally similar to those From 2f172b4f0b024990a0fd3df2fedd0fe18b48a303 Mon Sep 17 00:00:00 2001 From: Andrew Pollack Date: Wed, 28 Sep 2022 21:32:02 +0000 Subject: [PATCH 09/12] Adding target_rustcflags to TargetCfg --- src/tools/compiletest/src/common.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 4994fb9bbf941..b9ac6c9f36418 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -385,7 +385,8 @@ impl Config { } fn target_cfg(&self) -> &TargetCfg { - self.target_cfg.borrow_with(|| TargetCfg::new(&self.rustc_path, &self.target)) + self.target_cfg + .borrow_with(|| TargetCfg::new(&self.rustc_path, &self.target, &self.target_rustcflags)) } pub fn matches_arch(&self, arch: &str) -> bool { @@ -456,11 +457,12 @@ pub enum Endian { } impl TargetCfg { - fn new(rustc_path: &Path, target: &str) -> TargetCfg { + fn new(rustc_path: &Path, target: &str, target_rustcflags: &Option) -> TargetCfg { let output = match Command::new(rustc_path) .arg("--print=cfg") .arg("--target") .arg(target) + .args(target_rustcflags.into_iter().map(|s| s.split_whitespace()).flatten()) .output() { Ok(output) => output, From f088e543cb51afa12c05097c131969d7962eca36 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 2 Oct 2022 06:30:49 +0000 Subject: [PATCH 10/12] Delay evaluating lint primary message until after it would be suppressed --- compiler/rustc_middle/src/lint.rs | 5 ++++- src/test/ui/lint/auxiliary/trivial-cast-ice.rs | 7 +++++++ src/test/ui/lint/trivial-cast-ice.rs | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/auxiliary/trivial-cast-ice.rs create mode 100644 src/test/ui/lint/trivial-cast-ice.rs diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 328b7ad6a4954..41b8aeb48524e 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -354,7 +354,6 @@ pub fn struct_lint_level<'s, 'd>( (Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""), }; - err.set_primary_message(msg); err.set_is_lint(); // If this code originates in a foreign macro, aka something that this crate @@ -379,6 +378,10 @@ pub fn struct_lint_level<'s, 'd>( } } + // Delay evaluating and setting the primary message until after we've + // suppressed the lint due to macros. + err.set_primary_message(msg); + // Lint diagnostics that are covered by the expect level will not be emitted outside // the compiler. It is therefore not necessary to add any information for the user. // This will therefore directly call the decorate function which will in turn emit diff --git a/src/test/ui/lint/auxiliary/trivial-cast-ice.rs b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs new file mode 100644 index 0000000000000..ab2332d065655 --- /dev/null +++ b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs @@ -0,0 +1,7 @@ +#[macro_export] +macro_rules! foo { + () => { + let x: &Option = &Some(1); + let _y = x as *const Option; + } +} diff --git a/src/test/ui/lint/trivial-cast-ice.rs b/src/test/ui/lint/trivial-cast-ice.rs new file mode 100644 index 0000000000000..f781fab2212cc --- /dev/null +++ b/src/test/ui/lint/trivial-cast-ice.rs @@ -0,0 +1,12 @@ +// aux-build:trivial-cast-ice.rs +// check-pass + +// Demonstrates the ICE in #102561 + +#![deny(trivial_casts)] + +extern crate trivial_cast_ice; + +fn main() { + trivial_cast_ice::foo!(); +} From d33e113ba059c24fc6bcec86e3c39d07c7ca1c3e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 3 Oct 2022 09:29:26 -0700 Subject: [PATCH 11/12] rustdoc: remove font family CSS on `.rustdoc-toggle summary::before` This rule became irrelevant since c58246efe47bea09d4f3e70f536e4c9bb7770749 made it so that the `summary::before` pseudo-element contains an SVG instead of text. --- src/librustdoc/html/static/css/rustdoc.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 84e6df59f576b..6098d6da237cb 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -207,13 +207,10 @@ a.source, .item-left > a, .out-of-band, span.since, -details.rustdoc-toggle > summary::before, a.srclink, #help-button > button, details.rustdoc-toggle.top-doc > summary, -details.rustdoc-toggle.top-doc > summary::before, details.rustdoc-toggle.non-exhaustive > summary, -details.rustdoc-toggle.non-exhaustive > summary::before, .scraped-example-title, .more-examples-toggle summary, .more-examples-toggle .hide-more, .example-links a, @@ -1573,7 +1570,6 @@ details.rustdoc-toggle > summary::before { } details.rustdoc-toggle > summary.hideme > span, -details.rustdoc-toggle > summary::before, .more-examples-toggle summary, .more-examples-toggle .hide-more { color: var(--toggles-color); } From 8dcecdb4876e6f4ddc9ea392c0191874676f80de Mon Sep 17 00:00:00 2001 From: H4x5 Date: Mon, 3 Oct 2022 13:36:57 -0400 Subject: [PATCH 12/12] Change the parameter name of From::from to `value` --- library/core/src/convert/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 6f23b9d908dba..3253e0f4cad73 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -376,7 +376,7 @@ pub trait From: Sized { #[lang = "from"] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] - fn from(_: T) -> Self; + fn from(value: T) -> Self; } /// An attempted conversion that consumes `self`, which may or may not be