Skip to content

Commit b65e1b6

Browse files
committed
Add x_ prefix to all IP methods that collide with unstable core's.
1 parent 803fa87 commit b65e1b6

File tree

7 files changed

+63
-49
lines changed

7 files changed

+63
-49
lines changed

src/iface/interface/ipv4.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl InterfaceInner {
7070

7171
/// Checks if an ipv4 address is unicast, taking into account subnet broadcast addresses
7272
fn is_unicast_v4(&self, address: Ipv4Address) -> bool {
73-
address.is_unicast() && !self.is_broadcast_v4(address)
73+
address.x_is_unicast() && !self.is_broadcast_v4(address)
7474
}
7575

7676
/// Get the first IPv4 address of the interface.
@@ -182,7 +182,7 @@ impl InterfaceInner {
182182
// Ignore IP packets not directed at us, or broadcast, or any of the multicast groups.
183183
// If AnyIP is enabled, also check if the packet is routed locally.
184184
if !self.any_ip
185-
|| !ipv4_repr.dst_addr.is_unicast()
185+
|| !ipv4_repr.dst_addr.x_is_unicast()
186186
|| self
187187
.routes
188188
.lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), self.now)
@@ -260,7 +260,7 @@ impl InterfaceInner {
260260
}
261261

262262
// Discard packets with non-unicast source addresses.
263-
if !source_protocol_addr.is_unicast() || !source_hardware_addr.is_unicast() {
263+
if !source_protocol_addr.x_is_unicast() || !source_hardware_addr.is_unicast() {
264264
net_debug!("arp: non-unicast source address");
265265
return None;
266266
}

src/iface/interface/ipv6.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl InterfaceInner {
3737
}
3838

3939
if dst_addr.is_multicast()
40-
&& matches!(dst_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal)
40+
&& matches!(dst_addr.x_multicast_scope(), Ipv6MulticastScope::LinkLocal)
4141
&& src_addr.is_multicast()
42-
&& !matches!(src_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal)
42+
&& !matches!(src_addr.x_multicast_scope(), Ipv6MulticastScope::LinkLocal)
4343
{
4444
return false;
4545
}
@@ -111,15 +111,16 @@ impl InterfaceInner {
111111
}
112112

113113
// Rule 2: prefer appropriate scope.
114-
if (candidate.address().multicast_scope() as u8)
115-
< (addr.address().multicast_scope() as u8)
114+
if (candidate.address().x_multicast_scope() as u8)
115+
< (addr.address().x_multicast_scope() as u8)
116116
{
117-
if (candidate.address().multicast_scope() as u8)
118-
< (dst_addr.multicast_scope() as u8)
117+
if (candidate.address().x_multicast_scope() as u8)
118+
< (dst_addr.x_multicast_scope() as u8)
119119
{
120120
candidate = addr;
121121
}
122-
} else if (addr.address().multicast_scope() as u8) > (dst_addr.multicast_scope() as u8)
122+
} else if (addr.address().x_multicast_scope() as u8)
123+
> (dst_addr.x_multicast_scope() as u8)
123124
{
124125
candidate = addr;
125126
}
@@ -192,7 +193,7 @@ impl InterfaceInner {
192193
) -> Option<Packet<'frame>> {
193194
let ipv6_repr = check!(Ipv6Repr::parse(ipv6_packet));
194195

195-
if !ipv6_repr.src_addr.is_unicast() {
196+
if !ipv6_repr.src_addr.x_is_unicast() {
196197
// Discard packets with non-unicast source addresses.
197198
net_debug!("non-unicast source address");
198199
return None;
@@ -213,7 +214,7 @@ impl InterfaceInner {
213214
{
214215
// If AnyIP is enabled, also check if the packet is routed locally.
215216
if !self.any_ip
216-
|| !ipv6_repr.dst_addr.is_unicast()
217+
|| !ipv6_repr.dst_addr.x_is_unicast()
217218
|| self
218219
.routes
219220
.lookup(&IpAddress::Ipv6(ipv6_repr.dst_addr), self.now)
@@ -230,7 +231,7 @@ impl InterfaceInner {
230231
let handled_by_raw_socket = false;
231232

232233
#[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
233-
if ipv6_repr.dst_addr.is_unicast() {
234+
if ipv6_repr.dst_addr.x_is_unicast() {
234235
self.neighbor_cache.reset_expiry_if_existing(
235236
IpAddress::Ipv6(ipv6_repr.src_addr),
236237
source_hardware_addr,
@@ -436,7 +437,7 @@ impl InterfaceInner {
436437
let ip_addr = ip_repr.src_addr.into();
437438
if let Some(lladdr) = lladdr {
438439
let lladdr = check!(lladdr.parse(self.caps.medium));
439-
if !lladdr.is_unicast() || !target_addr.is_unicast() {
440+
if !lladdr.is_unicast() || !target_addr.x_is_unicast() {
440441
return None;
441442
}
442443
if flags.contains(NdiscNeighborFlags::OVERRIDE)
@@ -454,7 +455,7 @@ impl InterfaceInner {
454455
} => {
455456
if let Some(lladdr) = lladdr {
456457
let lladdr = check!(lladdr.parse(self.caps.medium));
457-
if !lladdr.is_unicast() || !target_addr.is_unicast() {
458+
if !lladdr.is_unicast() || !target_addr.x_is_unicast() {
458459
return None;
459460
}
460461
self.neighbor_cache
@@ -492,7 +493,7 @@ impl InterfaceInner {
492493
let src_addr = ipv6_repr.dst_addr;
493494
let dst_addr = ipv6_repr.src_addr;
494495

495-
let src_addr = if src_addr.is_unicast() {
496+
let src_addr = if src_addr.x_is_unicast() {
496497
src_addr
497498
} else {
498499
self.get_source_address_ipv6(&dst_addr)

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ compile_error!("at least one socket needs to be enabled"); */
8787
#![allow(clippy::option_map_unit_fn)]
8888
#![allow(clippy::unit_arg)]
8989
#![allow(clippy::new_without_default)]
90-
#![allow(unstable_name_collisions)]
9190

9291
#[cfg(feature = "alloc")]
9392
extern crate alloc;

src/socket/dhcpv4.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'a> Socket<'a> {
366366

367367
match (&mut self.state, dhcp_repr.message_type) {
368368
(ClientState::Discovering(_state), DhcpMessageType::Offer) => {
369-
if !dhcp_repr.your_ip.is_unicast() {
369+
if !dhcp_repr.your_ip.x_is_unicast() {
370370
net_debug!("DHCP ignoring OFFER because your_ip is not unicast");
371371
return;
372372
}
@@ -462,7 +462,7 @@ impl<'a> Socket<'a> {
462462
}
463463
};
464464

465-
if !dhcp_repr.your_ip.is_unicast() {
465+
if !dhcp_repr.your_ip.x_is_unicast() {
466466
net_debug!("DHCP ignoring ACK because your_ip is not unicast");
467467
return None;
468468
}
@@ -483,7 +483,7 @@ impl<'a> Socket<'a> {
483483
.dns_servers
484484
.iter()
485485
.flatten()
486-
.filter(|s| s.is_unicast())
486+
.filter(|s| s.x_is_unicast())
487487
.for_each(|a| {
488488
// This will never produce an error, as both the arrays and `dns_servers`
489489
// have length DHCP_MAX_DNS_SERVER_COUNT

src/wire/ip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ impl Address {
131131
pub fn is_unicast(&self) -> bool {
132132
match self {
133133
#[cfg(feature = "proto-ipv4")]
134-
Address::Ipv4(addr) => addr.is_unicast(),
134+
Address::Ipv4(addr) => addr.x_is_unicast(),
135135
#[cfg(feature = "proto-ipv6")]
136-
Address::Ipv6(addr) => addr.is_unicast(),
136+
Address::Ipv6(addr) => addr.x_is_unicast(),
137137
}
138138
}
139139

src/wire/ipv4.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub(crate) trait AddressExt {
5151
fn from_bytes(data: &[u8]) -> Self;
5252

5353
/// Query whether the address is an unicast address.
54-
fn is_unicast(&self) -> bool;
54+
///
55+
/// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
56+
fn x_is_unicast(&self) -> bool;
5557

5658
/// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`,
5759
/// where `prefix_len` is the number of leading zeroes. Return `None` otherwise.
@@ -66,7 +68,7 @@ impl AddressExt for Address {
6668
}
6769

6870
/// Query whether the address is an unicast address.
69-
fn is_unicast(&self) -> bool {
71+
fn x_is_unicast(&self) -> bool {
7072
!(self.is_broadcast() || self.is_multicast() || self.is_unspecified())
7173
}
7274

src/wire/ipv6.rs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ pub(crate) trait AddressExt {
8686
/// Query whether the IPv6 address is an [unicast address].
8787
///
8888
/// [unicast address]: https://tools.ietf.org/html/rfc4291#section-2.5
89-
fn is_unicast(&self) -> bool;
89+
///
90+
/// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
91+
fn x_is_unicast(&self) -> bool;
9092

9193
/// Query whether the IPv6 address is a [global unicast address].
9294
///
@@ -101,7 +103,9 @@ pub(crate) trait AddressExt {
101103
/// Query whether the IPv6 address is a [Unique Local Address] (ULA).
102104
///
103105
/// [Unique Local Address]: https://tools.ietf.org/html/rfc4193
104-
fn is_unique_local(&self) -> bool;
106+
///
107+
/// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
108+
fn x_is_unique_local(&self) -> bool;
105109

106110
/// Helper function used to mask an address given a prefix.
107111
///
@@ -117,7 +121,9 @@ pub(crate) trait AddressExt {
117121
fn solicited_node(&self) -> Address;
118122

119123
/// Return the scope of the address.
120-
fn multicast_scope(&self) -> MulticastScope;
124+
///
125+
/// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
126+
fn x_multicast_scope(&self) -> MulticastScope;
121127

122128
/// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`,
123129
/// where `prefix_len` is the number of leading zeroes. Return `None` otherwise.
@@ -131,7 +137,7 @@ impl AddressExt for Address {
131137
Address::from(bytes)
132138
}
133139

134-
fn is_unicast(&self) -> bool {
140+
fn x_is_unicast(&self) -> bool {
135141
!(self.is_multicast() || self.is_unspecified())
136142
}
137143

@@ -143,7 +149,7 @@ impl AddressExt for Address {
143149
self.octets()[0..8] == [0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
144150
}
145151

146-
fn is_unique_local(&self) -> bool {
152+
fn x_is_unique_local(&self) -> bool {
147153
(self.octets()[0] & 0b1111_1110) == 0xfc
148154
}
149155

@@ -163,22 +169,22 @@ impl AddressExt for Address {
163169
}
164170

165171
fn solicited_node(&self) -> Address {
166-
assert!(self.is_unicast());
172+
assert!(self.x_is_unicast());
167173
let o = self.octets();
168174
Address::from([
169175
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, o[13],
170176
o[14], o[15],
171177
])
172178
}
173179

174-
fn multicast_scope(&self) -> MulticastScope {
180+
fn x_multicast_scope(&self) -> MulticastScope {
175181
if self.is_multicast() {
176182
return MulticastScope::from(self.octets()[1] & 0b1111);
177183
}
178184

179185
if self.is_link_local() {
180186
MulticastScope::LinkLocal
181-
} else if self.is_unique_local() || self.is_global_unicast() {
187+
} else if self.x_is_unique_local() || self.is_global_unicast() {
182188
// ULA are considered global scope
183189
// https://www.rfc-editor.org/rfc/rfc6724#section-3.1
184190
MulticastScope::Global
@@ -680,13 +686,13 @@ pub(crate) mod test {
680686
assert!(LINK_LOCAL_ALL_ROUTERS.is_multicast());
681687
assert!(!LINK_LOCAL_ALL_ROUTERS.is_link_local());
682688
assert!(!LINK_LOCAL_ALL_ROUTERS.is_loopback());
683-
assert!(!LINK_LOCAL_ALL_ROUTERS.is_unique_local());
689+
assert!(!LINK_LOCAL_ALL_ROUTERS.x_is_unique_local());
684690
assert!(!LINK_LOCAL_ALL_ROUTERS.is_global_unicast());
685691
assert!(!LINK_LOCAL_ALL_NODES.is_unspecified());
686692
assert!(LINK_LOCAL_ALL_NODES.is_multicast());
687693
assert!(!LINK_LOCAL_ALL_NODES.is_link_local());
688694
assert!(!LINK_LOCAL_ALL_NODES.is_loopback());
689-
assert!(!LINK_LOCAL_ALL_NODES.is_unique_local());
695+
assert!(!LINK_LOCAL_ALL_NODES.x_is_unique_local());
690696
assert!(!LINK_LOCAL_ALL_NODES.is_global_unicast());
691697
}
692698

@@ -696,7 +702,7 @@ pub(crate) mod test {
696702
assert!(!LINK_LOCAL_ADDR.is_multicast());
697703
assert!(LINK_LOCAL_ADDR.is_link_local());
698704
assert!(!LINK_LOCAL_ADDR.is_loopback());
699-
assert!(!LINK_LOCAL_ADDR.is_unique_local());
705+
assert!(!LINK_LOCAL_ADDR.x_is_unique_local());
700706
assert!(!LINK_LOCAL_ADDR.is_global_unicast());
701707
}
702708

@@ -706,7 +712,7 @@ pub(crate) mod test {
706712
assert!(!Address::LOCALHOST.is_multicast());
707713
assert!(!Address::LOCALHOST.is_link_local());
708714
assert!(Address::LOCALHOST.is_loopback());
709-
assert!(!Address::LOCALHOST.is_unique_local());
715+
assert!(!Address::LOCALHOST.x_is_unique_local());
710716
assert!(!Address::LOCALHOST.is_global_unicast());
711717
}
712718

@@ -716,7 +722,7 @@ pub(crate) mod test {
716722
assert!(!UNIQUE_LOCAL_ADDR.is_multicast());
717723
assert!(!UNIQUE_LOCAL_ADDR.is_link_local());
718724
assert!(!UNIQUE_LOCAL_ADDR.is_loopback());
719-
assert!(UNIQUE_LOCAL_ADDR.is_unique_local());
725+
assert!(UNIQUE_LOCAL_ADDR.x_is_unique_local());
720726
assert!(!UNIQUE_LOCAL_ADDR.is_global_unicast());
721727
}
722728

@@ -726,7 +732,7 @@ pub(crate) mod test {
726732
assert!(!GLOBAL_UNICAST_ADDR.is_multicast());
727733
assert!(!GLOBAL_UNICAST_ADDR.is_link_local());
728734
assert!(!GLOBAL_UNICAST_ADDR.is_loopback());
729-
assert!(!GLOBAL_UNICAST_ADDR.is_unique_local());
735+
assert!(!GLOBAL_UNICAST_ADDR.x_is_unique_local());
730736
assert!(GLOBAL_UNICAST_ADDR.is_global_unicast());
731737
}
732738

@@ -903,46 +909,52 @@ pub(crate) mod test {
903909
fn test_scope() {
904910
use super::*;
905911
assert_eq!(
906-
Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
912+
Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
907913
MulticastScope::InterfaceLocal
908914
);
909915
assert_eq!(
910-
Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
916+
Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
911917
MulticastScope::LinkLocal
912918
);
913919
assert_eq!(
914-
Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
920+
Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
915921
MulticastScope::Unknown
916922
);
917923
assert_eq!(
918-
Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
924+
Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
919925
MulticastScope::AdminLocal
920926
);
921927
assert_eq!(
922-
Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
928+
Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
923929
MulticastScope::SiteLocal
924930
);
925931
assert_eq!(
926-
Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
932+
Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
927933
MulticastScope::OrganizationLocal
928934
);
929935
assert_eq!(
930-
Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).multicast_scope(),
936+
Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(),
931937
MulticastScope::Global
932938
);
933939

934940
assert_eq!(
935-
LINK_LOCAL_ALL_NODES.multicast_scope(),
941+
LINK_LOCAL_ALL_NODES.x_multicast_scope(),
936942
MulticastScope::LinkLocal
937943
);
938944

939945
// For source address selection, unicast addresses also have a scope:
940-
assert_eq!(LINK_LOCAL_ADDR.multicast_scope(), MulticastScope::LinkLocal);
941946
assert_eq!(
942-
GLOBAL_UNICAST_ADDR.multicast_scope(),
947+
LINK_LOCAL_ADDR.x_multicast_scope(),
948+
MulticastScope::LinkLocal
949+
);
950+
assert_eq!(
951+
GLOBAL_UNICAST_ADDR.x_multicast_scope(),
952+
MulticastScope::Global
953+
);
954+
assert_eq!(
955+
UNIQUE_LOCAL_ADDR.x_multicast_scope(),
943956
MulticastScope::Global
944957
);
945-
assert_eq!(UNIQUE_LOCAL_ADDR.multicast_scope(), MulticastScope::Global);
946958
}
947959

948960
static REPR_PACKET_BYTES: [u8; 52] = [

0 commit comments

Comments
 (0)