diff --git a/src/iface/interface/ipv4.rs b/src/iface/interface/ipv4.rs index 2e93a336e..a00044ae8 100644 --- a/src/iface/interface/ipv4.rs +++ b/src/iface/interface/ipv4.rs @@ -70,7 +70,7 @@ impl InterfaceInner { /// Checks if an ipv4 address is unicast, taking into account subnet broadcast addresses fn is_unicast_v4(&self, address: Ipv4Address) -> bool { - address.is_unicast() && !self.is_broadcast_v4(address) + address.x_is_unicast() && !self.is_broadcast_v4(address) } /// Get the first IPv4 address of the interface. @@ -182,7 +182,7 @@ impl InterfaceInner { // Ignore IP packets not directed at us, or broadcast, or any of the multicast groups. // If AnyIP is enabled, also check if the packet is routed locally. if !self.any_ip - || !ipv4_repr.dst_addr.is_unicast() + || !ipv4_repr.dst_addr.x_is_unicast() || self .routes .lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), self.now) @@ -260,7 +260,7 @@ impl InterfaceInner { } // Discard packets with non-unicast source addresses. - if !source_protocol_addr.is_unicast() || !source_hardware_addr.is_unicast() { + if !source_protocol_addr.x_is_unicast() || !source_hardware_addr.is_unicast() { net_debug!("arp: non-unicast source address"); return None; } diff --git a/src/iface/interface/ipv6.rs b/src/iface/interface/ipv6.rs index 9d2288483..9922c500b 100644 --- a/src/iface/interface/ipv6.rs +++ b/src/iface/interface/ipv6.rs @@ -37,9 +37,9 @@ impl InterfaceInner { } if dst_addr.is_multicast() - && matches!(dst_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal) + && matches!(dst_addr.x_multicast_scope(), Ipv6MulticastScope::LinkLocal) && src_addr.is_multicast() - && !matches!(src_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal) + && !matches!(src_addr.x_multicast_scope(), Ipv6MulticastScope::LinkLocal) { return false; } @@ -111,15 +111,16 @@ impl InterfaceInner { } // Rule 2: prefer appropriate scope. - if (candidate.address().multicast_scope() as u8) - < (addr.address().multicast_scope() as u8) + if (candidate.address().x_multicast_scope() as u8) + < (addr.address().x_multicast_scope() as u8) { - if (candidate.address().multicast_scope() as u8) - < (dst_addr.multicast_scope() as u8) + if (candidate.address().x_multicast_scope() as u8) + < (dst_addr.x_multicast_scope() as u8) { candidate = addr; } - } else if (addr.address().multicast_scope() as u8) > (dst_addr.multicast_scope() as u8) + } else if (addr.address().x_multicast_scope() as u8) + > (dst_addr.x_multicast_scope() as u8) { candidate = addr; } @@ -192,7 +193,7 @@ impl InterfaceInner { ) -> Option> { let ipv6_repr = check!(Ipv6Repr::parse(ipv6_packet)); - if !ipv6_repr.src_addr.is_unicast() { + if !ipv6_repr.src_addr.x_is_unicast() { // Discard packets with non-unicast source addresses. net_debug!("non-unicast source address"); return None; @@ -213,7 +214,7 @@ impl InterfaceInner { { // If AnyIP is enabled, also check if the packet is routed locally. if !self.any_ip - || !ipv6_repr.dst_addr.is_unicast() + || !ipv6_repr.dst_addr.x_is_unicast() || self .routes .lookup(&IpAddress::Ipv6(ipv6_repr.dst_addr), self.now) @@ -230,7 +231,7 @@ impl InterfaceInner { let handled_by_raw_socket = false; #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))] - if ipv6_repr.dst_addr.is_unicast() { + if ipv6_repr.dst_addr.x_is_unicast() { self.neighbor_cache.reset_expiry_if_existing( IpAddress::Ipv6(ipv6_repr.src_addr), source_hardware_addr, @@ -436,7 +437,7 @@ impl InterfaceInner { let ip_addr = ip_repr.src_addr.into(); if let Some(lladdr) = lladdr { let lladdr = check!(lladdr.parse(self.caps.medium)); - if !lladdr.is_unicast() || !target_addr.is_unicast() { + if !lladdr.is_unicast() || !target_addr.x_is_unicast() { return None; } if flags.contains(NdiscNeighborFlags::OVERRIDE) @@ -454,7 +455,7 @@ impl InterfaceInner { } => { if let Some(lladdr) = lladdr { let lladdr = check!(lladdr.parse(self.caps.medium)); - if !lladdr.is_unicast() || !target_addr.is_unicast() { + if !lladdr.is_unicast() || !target_addr.x_is_unicast() { return None; } self.neighbor_cache @@ -492,7 +493,7 @@ impl InterfaceInner { let src_addr = ipv6_repr.dst_addr; let dst_addr = ipv6_repr.src_addr; - let src_addr = if src_addr.is_unicast() { + let src_addr = if src_addr.x_is_unicast() { src_addr } else { self.get_source_address_ipv6(&dst_addr) diff --git a/src/lib.rs b/src/lib.rs index 124e7a46c..8f2ba3b37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,6 @@ compile_error!("at least one socket needs to be enabled"); */ #![allow(clippy::option_map_unit_fn)] #![allow(clippy::unit_arg)] #![allow(clippy::new_without_default)] -#![allow(unstable_name_collisions)] #[cfg(feature = "alloc")] extern crate alloc; diff --git a/src/socket/dhcpv4.rs b/src/socket/dhcpv4.rs index a7673ae62..72980a946 100644 --- a/src/socket/dhcpv4.rs +++ b/src/socket/dhcpv4.rs @@ -366,7 +366,7 @@ impl<'a> Socket<'a> { match (&mut self.state, dhcp_repr.message_type) { (ClientState::Discovering(_state), DhcpMessageType::Offer) => { - if !dhcp_repr.your_ip.is_unicast() { + if !dhcp_repr.your_ip.x_is_unicast() { net_debug!("DHCP ignoring OFFER because your_ip is not unicast"); return; } @@ -462,7 +462,7 @@ impl<'a> Socket<'a> { } }; - if !dhcp_repr.your_ip.is_unicast() { + if !dhcp_repr.your_ip.x_is_unicast() { net_debug!("DHCP ignoring ACK because your_ip is not unicast"); return None; } @@ -483,7 +483,7 @@ impl<'a> Socket<'a> { .dns_servers .iter() .flatten() - .filter(|s| s.is_unicast()) + .filter(|s| s.x_is_unicast()) .for_each(|a| { // This will never produce an error, as both the arrays and `dns_servers` // have length DHCP_MAX_DNS_SERVER_COUNT diff --git a/src/wire/ip.rs b/src/wire/ip.rs index a332bc12e..e61541cd0 100644 --- a/src/wire/ip.rs +++ b/src/wire/ip.rs @@ -131,9 +131,9 @@ impl Address { pub fn is_unicast(&self) -> bool { match self { #[cfg(feature = "proto-ipv4")] - Address::Ipv4(addr) => addr.is_unicast(), + Address::Ipv4(addr) => addr.x_is_unicast(), #[cfg(feature = "proto-ipv6")] - Address::Ipv6(addr) => addr.is_unicast(), + Address::Ipv6(addr) => addr.x_is_unicast(), } } diff --git a/src/wire/ipv4.rs b/src/wire/ipv4.rs index c5f1388c1..7629a46ed 100644 --- a/src/wire/ipv4.rs +++ b/src/wire/ipv4.rs @@ -51,7 +51,9 @@ pub(crate) trait AddressExt { fn from_bytes(data: &[u8]) -> Self; /// Query whether the address is an unicast address. - fn is_unicast(&self) -> bool; + /// + /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`. + fn x_is_unicast(&self) -> bool; /// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`, /// where `prefix_len` is the number of leading zeroes. Return `None` otherwise. @@ -66,7 +68,7 @@ impl AddressExt for Address { } /// Query whether the address is an unicast address. - fn is_unicast(&self) -> bool { + fn x_is_unicast(&self) -> bool { !(self.is_broadcast() || self.is_multicast() || self.is_unspecified()) } diff --git a/src/wire/ipv6.rs b/src/wire/ipv6.rs index d47d8faeb..8dc05c51d 100644 --- a/src/wire/ipv6.rs +++ b/src/wire/ipv6.rs @@ -86,7 +86,9 @@ pub(crate) trait AddressExt { /// Query whether the IPv6 address is an [unicast address]. /// /// [unicast address]: https://tools.ietf.org/html/rfc4291#section-2.5 - fn is_unicast(&self) -> bool; + /// + /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`. + fn x_is_unicast(&self) -> bool; /// Query whether the IPv6 address is a [global unicast address]. /// @@ -101,7 +103,9 @@ pub(crate) trait AddressExt { /// Query whether the IPv6 address is a [Unique Local Address] (ULA). /// /// [Unique Local Address]: https://tools.ietf.org/html/rfc4193 - fn is_unique_local(&self) -> bool; + /// + /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`. + fn x_is_unique_local(&self) -> bool; /// Helper function used to mask an address given a prefix. /// @@ -117,7 +121,9 @@ pub(crate) trait AddressExt { fn solicited_node(&self) -> Address; /// Return the scope of the address. - fn multicast_scope(&self) -> MulticastScope; + /// + /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`. + fn x_multicast_scope(&self) -> MulticastScope; /// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`, /// where `prefix_len` is the number of leading zeroes. Return `None` otherwise. @@ -131,7 +137,7 @@ impl AddressExt for Address { Address::from(bytes) } - fn is_unicast(&self) -> bool { + fn x_is_unicast(&self) -> bool { !(self.is_multicast() || self.is_unspecified()) } @@ -143,7 +149,7 @@ impl AddressExt for Address { self.octets()[0..8] == [0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] } - fn is_unique_local(&self) -> bool { + fn x_is_unique_local(&self) -> bool { (self.octets()[0] & 0b1111_1110) == 0xfc } @@ -163,7 +169,7 @@ impl AddressExt for Address { } fn solicited_node(&self) -> Address { - assert!(self.is_unicast()); + assert!(self.x_is_unicast()); let o = self.octets(); Address::from([ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, o[13], @@ -171,14 +177,14 @@ impl AddressExt for Address { ]) } - fn multicast_scope(&self) -> MulticastScope { + fn x_multicast_scope(&self) -> MulticastScope { if self.is_multicast() { return MulticastScope::from(self.octets()[1] & 0b1111); } if self.is_link_local() { MulticastScope::LinkLocal - } else if self.is_unique_local() || self.is_global_unicast() { + } else if self.x_is_unique_local() || self.is_global_unicast() { // ULA are considered global scope // https://www.rfc-editor.org/rfc/rfc6724#section-3.1 MulticastScope::Global @@ -680,13 +686,13 @@ pub(crate) mod test { assert!(LINK_LOCAL_ALL_ROUTERS.is_multicast()); assert!(!LINK_LOCAL_ALL_ROUTERS.is_link_local()); assert!(!LINK_LOCAL_ALL_ROUTERS.is_loopback()); - assert!(!LINK_LOCAL_ALL_ROUTERS.is_unique_local()); + assert!(!LINK_LOCAL_ALL_ROUTERS.x_is_unique_local()); assert!(!LINK_LOCAL_ALL_ROUTERS.is_global_unicast()); assert!(!LINK_LOCAL_ALL_NODES.is_unspecified()); assert!(LINK_LOCAL_ALL_NODES.is_multicast()); assert!(!LINK_LOCAL_ALL_NODES.is_link_local()); assert!(!LINK_LOCAL_ALL_NODES.is_loopback()); - assert!(!LINK_LOCAL_ALL_NODES.is_unique_local()); + assert!(!LINK_LOCAL_ALL_NODES.x_is_unique_local()); assert!(!LINK_LOCAL_ALL_NODES.is_global_unicast()); } @@ -696,7 +702,7 @@ pub(crate) mod test { assert!(!LINK_LOCAL_ADDR.is_multicast()); assert!(LINK_LOCAL_ADDR.is_link_local()); assert!(!LINK_LOCAL_ADDR.is_loopback()); - assert!(!LINK_LOCAL_ADDR.is_unique_local()); + assert!(!LINK_LOCAL_ADDR.x_is_unique_local()); assert!(!LINK_LOCAL_ADDR.is_global_unicast()); } @@ -706,7 +712,7 @@ pub(crate) mod test { assert!(!Address::LOCALHOST.is_multicast()); assert!(!Address::LOCALHOST.is_link_local()); assert!(Address::LOCALHOST.is_loopback()); - assert!(!Address::LOCALHOST.is_unique_local()); + assert!(!Address::LOCALHOST.x_is_unique_local()); assert!(!Address::LOCALHOST.is_global_unicast()); } @@ -716,7 +722,7 @@ pub(crate) mod test { assert!(!UNIQUE_LOCAL_ADDR.is_multicast()); assert!(!UNIQUE_LOCAL_ADDR.is_link_local()); assert!(!UNIQUE_LOCAL_ADDR.is_loopback()); - assert!(UNIQUE_LOCAL_ADDR.is_unique_local()); + assert!(UNIQUE_LOCAL_ADDR.x_is_unique_local()); assert!(!UNIQUE_LOCAL_ADDR.is_global_unicast()); } @@ -726,7 +732,7 @@ pub(crate) mod test { assert!(!GLOBAL_UNICAST_ADDR.is_multicast()); assert!(!GLOBAL_UNICAST_ADDR.is_link_local()); assert!(!GLOBAL_UNICAST_ADDR.is_loopback()); - assert!(!GLOBAL_UNICAST_ADDR.is_unique_local()); + assert!(!GLOBAL_UNICAST_ADDR.x_is_unique_local()); assert!(GLOBAL_UNICAST_ADDR.is_global_unicast()); } @@ -903,46 +909,52 @@ pub(crate) mod test { fn test_scope() { use super::*; assert_eq!( - Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::InterfaceLocal ); assert_eq!( - Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::LinkLocal ); assert_eq!( - Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::Unknown ); assert_eq!( - Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::AdminLocal ); assert_eq!( - Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::SiteLocal ); assert_eq!( - Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::OrganizationLocal ); assert_eq!( - Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).x_multicast_scope(), MulticastScope::Global ); assert_eq!( - LINK_LOCAL_ALL_NODES.multicast_scope(), + LINK_LOCAL_ALL_NODES.x_multicast_scope(), MulticastScope::LinkLocal ); // For source address selection, unicast addresses also have a scope: - assert_eq!(LINK_LOCAL_ADDR.multicast_scope(), MulticastScope::LinkLocal); assert_eq!( - GLOBAL_UNICAST_ADDR.multicast_scope(), + LINK_LOCAL_ADDR.x_multicast_scope(), + MulticastScope::LinkLocal + ); + assert_eq!( + GLOBAL_UNICAST_ADDR.x_multicast_scope(), + MulticastScope::Global + ); + assert_eq!( + UNIQUE_LOCAL_ADDR.x_multicast_scope(), MulticastScope::Global ); - assert_eq!(UNIQUE_LOCAL_ADDR.multicast_scope(), MulticastScope::Global); } static REPR_PACKET_BYTES: [u8; 52] = [