From 49a923bc6a67d39af0e8685ef5df699ad47b3fa2 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 6 Dec 2019 05:46:25 +0100 Subject: [PATCH 1/5] RFC: Move `std::net::IpAddr` types into `core:.net`. --- text/0000-core-net-ipaddr-types.md | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 text/0000-core-net-ipaddr-types.md diff --git a/text/0000-core-net-ipaddr-types.md b/text/0000-core-net-ipaddr-types.md new file mode 100644 index 00000000000..7528355d0df --- /dev/null +++ b/text/0000-core-net-ipaddr-types.md @@ -0,0 +1,95 @@ +- Feature Name: `core_net_ipaddr_types` +- Start Date: 2019-12-06 +- RFC PR: [rust-lang/rfcs#2832](https://github.com/rust-lang/rfcs/pull/2832) +- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) + +# Summary +[summary]: #summary + +Make the `IpAddr`, `Ipv4Addr` and `Ipv6Addr` types available in `no_std` +contexts by moving them into a `core::net` module. + +# Motivation +[motivation]: #motivation + +The motivation here is to provide common types for both `no_std` and `std` +targets which in turn will ease the creation of libraries based around IP +addresses. Embedded IoT development is one area where this will be beneficial. +IP addresses are portable across all platforms and have no external +dependencies which is in line with the definition of the core library. + +# Guide-level explanation +[guide-level-explanation]: #guide-level-explanation + +The `core::net::IpAddr`, `core::net::Ipv4Addr` and `core::net::Ipv6Addr` types +are available in `no_std` contexts. + +Library developers should use `core::net` to implement abstractions in order +for them to work in `no_std` contexts as well. + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +Currently, the IP address types depend on their corresponding `libc` +counterpart for their `inner` value. + +IPv4 addresses are well-defined. [IETF RFC 791] specifically states: + +> Addresses are fixed length of four octets (32 bits). + +IPv6 addresses are well-defined. [IETF RFC 4291] specifically states: + +> IPv6 addresses are 128-bit identifiers + +Since the size and representation of IPv4 and IPv6 addresses are well defined, +we can replace the `inner` value of `Ipv4Addr` with a `[u8; 4]` and the `inner` +value of `IPv6Addr` with a `[u8; 16]`. + +The inner types `[u8; 4]` and `[u8; 16]` are expected to correspond to `u32` +and `u128` in big-endian byte order. Currently, this is already ensured: + +- `u32::to_be` is used when constructing the corresponding `libc` type for + `Ipv4Addr`. +- The corresponding `libc` type for `IPv6Addr` is already represented as a + `[u8; 16]` internally on all platforms. + +[IETF RFC 791]: https://tools.ietf.org/html/rfc791 +[IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 + +# Drawbacks +[drawbacks]: #drawbacks + +Moving the `std::net` types to `core::net` makes the core library less *minimal*. + +# Rationale and alternatives +[rationale-and-alternatives]: #rationale-and-alternatives + +- Given the size of IP addresses is well defined by IETF RFCs, there is no + inherent need to have these types depend on `libc`. + +- Eliminates the need to use different abstractions for `no_std` and `std`. + +- Alternatively, move these types into a library other than `core`, so they + can be used without `std`. + +# Prior art +[prior-art]: #prior-art + +There was a prior discussion at + +https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247/15 + +and an experimental branch from [@Nemo157](https://github.com/Nemo157) at + +https://github.com/Nemo157/rust/tree/core-ip + +# Unresolved questions +[unresolved-questions]: #unresolved-questions + +None. + +# Future possibilities +[future-possibilities]: #future-possibilities + +`SocketAddr`, `SocketAddrV4` and `SocketAddrV6` could also be moved in the +future. From 21569bf2913eaa1c4e4f888a157d2f43cf922f0e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 12 Nov 2022 19:36:28 +0100 Subject: [PATCH 2/5] Update current state of IP and socket address types. --- text/0000-core-net-ipaddr-types.md | 49 +++++++++++------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/text/0000-core-net-ipaddr-types.md b/text/0000-core-net-ipaddr-types.md index 7528355d0df..7056a13832d 100644 --- a/text/0000-core-net-ipaddr-types.md +++ b/text/0000-core-net-ipaddr-types.md @@ -6,7 +6,8 @@ # Summary [summary]: #summary -Make the `IpAddr`, `Ipv4Addr` and `Ipv6Addr` types available in `no_std` +Make the `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, +`SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError` types available in `no_std` contexts by moving them into a `core::net` module. # Motivation @@ -21,8 +22,10 @@ dependencies which is in line with the definition of the core library. # Guide-level explanation [guide-level-explanation]: #guide-level-explanation -The `core::net::IpAddr`, `core::net::Ipv4Addr` and `core::net::Ipv6Addr` types -are available in `no_std` contexts. +The `core::net::IpAddr`, `core::net::Ipv4Addr`, `core::net::Ipv6Addr`, +`core::net::SocketAddr`, `core::net::SocketAddrV4`, `core::net::SocketAddrV6`, +`core::net::Ipv6MulticastScope` and `core::net::AddrParseError` types are +available in `no_std` contexts. Library developers should use `core::net` to implement abstractions in order for them to work in `no_std` contexts as well. @@ -30,31 +33,17 @@ for them to work in `no_std` contexts as well. # Reference-level explanation [reference-level-explanation]: #reference-level-explanation -Currently, the IP address types depend on their corresponding `libc` -counterpart for their `inner` value. +Since https://github.com/rust-lang/rust/pull/78802 has been merged, IP and +socket address types are implemented in ideal Rust layout instead of wrapping +their corresponding `libc` representation. -IPv4 addresses are well-defined. [IETF RFC 791] specifically states: +Formatting for these types has also been adjusted in +https://github.com/rust-lang/rust/pull/100625 and +https://github.com/rust-lang/rust/pull/100640 in order to remove the dependency +on `std::io::Write`. -> Addresses are fixed length of four octets (32 bits). - -IPv6 addresses are well-defined. [IETF RFC 4291] specifically states: - -> IPv6 addresses are 128-bit identifiers - -Since the size and representation of IPv4 and IPv6 addresses are well defined, -we can replace the `inner` value of `Ipv4Addr` with a `[u8; 4]` and the `inner` -value of `IPv6Addr` with a `[u8; 16]`. - -The inner types `[u8; 4]` and `[u8; 16]` are expected to correspond to `u32` -and `u128` in big-endian byte order. Currently, this is already ensured: - -- `u32::to_be` is used when constructing the corresponding `libc` type for - `Ipv4Addr`. -- The corresponding `libc` type for `IPv6Addr` is already represented as a - `[u8; 16]` internally on all platforms. - -[IETF RFC 791]: https://tools.ietf.org/html/rfc791 -[IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 +This means the types are now platform-agnostic, allowing them to be moved from +`std::net` into `core::net`. # Drawbacks [drawbacks]: #drawbacks @@ -64,13 +53,10 @@ Moving the `std::net` types to `core::net` makes the core library less *minimal* # Rationale and alternatives [rationale-and-alternatives]: #rationale-and-alternatives -- Given the size of IP addresses is well defined by IETF RFCs, there is no - inherent need to have these types depend on `libc`. - - Eliminates the need to use different abstractions for `no_std` and `std`. - Alternatively, move these types into a library other than `core`, so they - can be used without `std`. + can be used without `std`, and re-export them in `std`. # Prior art [prior-art]: #prior-art @@ -91,5 +77,4 @@ None. # Future possibilities [future-possibilities]: #future-possibilities -`SocketAddr`, `SocketAddrV4` and `SocketAddrV6` could also be moved in the -future. +None. From 90ecf8f8e449a8f0f0f67c735d476721bb22d7f6 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 12 Nov 2022 19:36:42 +0100 Subject: [PATCH 3/5] Rename feature. --- text/{0000-core-net-ipaddr-types.md => 0000-core-net-types.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename text/{0000-core-net-ipaddr-types.md => 0000-core-net-types.md} (98%) diff --git a/text/0000-core-net-ipaddr-types.md b/text/0000-core-net-types.md similarity index 98% rename from text/0000-core-net-ipaddr-types.md rename to text/0000-core-net-types.md index 7056a13832d..f576a6c0fa6 100644 --- a/text/0000-core-net-ipaddr-types.md +++ b/text/0000-core-net-types.md @@ -1,4 +1,4 @@ -- Feature Name: `core_net_ipaddr_types` +- Feature Name: `core_net_types` - Start Date: 2019-12-06 - RFC PR: [rust-lang/rfcs#2832](https://github.com/rust-lang/rfcs/pull/2832) - Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) From bd6b5499ace48c898351bbb81b6882a4ac1e1bb3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 12 Nov 2022 19:44:30 +0100 Subject: [PATCH 4/5] Mention `ToSocketAddrs`. --- text/0000-core-net-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0000-core-net-types.md b/text/0000-core-net-types.md index f576a6c0fa6..fad5fa7931b 100644 --- a/text/0000-core-net-types.md +++ b/text/0000-core-net-types.md @@ -77,4 +77,4 @@ None. # Future possibilities [future-possibilities]: #future-possibilities -None. +Move the `ToSocketAddrs` trait to `core::net` as well. This depends on having `core::io::Result`. From d73abe6e84cdf05bdcc429f9fe550a353f19fa39 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 24 Feb 2023 19:30:45 -0800 Subject: [PATCH 5/5] RFC 2832 --- text/{0000-core-net-types.md => 2832-core-net-types.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename text/{0000-core-net-types.md => 2832-core-net-types.md} (96%) diff --git a/text/0000-core-net-types.md b/text/2832-core-net-types.md similarity index 96% rename from text/0000-core-net-types.md rename to text/2832-core-net-types.md index fad5fa7931b..c251713f8a4 100644 --- a/text/0000-core-net-types.md +++ b/text/2832-core-net-types.md @@ -1,7 +1,7 @@ - Feature Name: `core_net_types` - Start Date: 2019-12-06 - RFC PR: [rust-lang/rfcs#2832](https://github.com/rust-lang/rfcs/pull/2832) -- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) +- Rust Issue: [rust-lang/rust#108443](https://github.com/rust-lang/rust/issues/108443) # Summary [summary]: #summary