diff --git a/src/iface/interface/ipv6.rs b/src/iface/interface/ipv6.rs index 7fc858e6c..c193cec1d 100644 --- a/src/iface/interface/ipv6.rs +++ b/src/iface/interface/ipv6.rs @@ -32,9 +32,9 @@ impl InterfaceInner { } if dst_addr.is_multicast() - && matches!(dst_addr.scope(), Ipv6AddressScope::LinkLocal) + && matches!(dst_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal) && src_addr.is_multicast() - && !matches!(src_addr.scope(), Ipv6AddressScope::LinkLocal) + && !matches!(src_addr.multicast_scope(), Ipv6MulticastScope::LinkLocal) { return false; } @@ -96,11 +96,16 @@ impl InterfaceInner { } // Rule 2: prefer appropriate scope. - if (candidate.address().scope() as u8) < (addr.address().scope() as u8) { - if (candidate.address().scope() as u8) < (dst_addr.scope() as u8) { + if (candidate.address().multicast_scope() as u8) + < (addr.address().multicast_scope() as u8) + { + if (candidate.address().multicast_scope() as u8) + < (dst_addr.multicast_scope() as u8) + { candidate = addr; } - } else if (addr.address().scope() as u8) > (dst_addr.scope() as u8) { + } else if (addr.address().multicast_scope() as u8) > (dst_addr.multicast_scope() as u8) + { candidate = addr; } diff --git a/src/wire/ipv6.rs b/src/wire/ipv6.rs index f69645945..a436cc466 100644 --- a/src/wire/ipv6.rs +++ b/src/wire/ipv6.rs @@ -30,7 +30,7 @@ pub const IPV4_MAPPED_PREFIX_SIZE: usize = ADDR_SIZE - 4; // 4 == ipv4::ADDR_SIZ /// [scope]: https://www.rfc-editor.org/rfc/rfc4291#section-2.7 #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum Scope { +pub(crate) enum MulticastScope { /// Interface Local scope InterfaceLocal = 0x1, /// Link local scope @@ -47,7 +47,7 @@ pub(crate) enum Scope { Unknown = 0xFF, } -impl From for Scope { +impl From for MulticastScope { fn from(value: u8) -> Self { match value { 0x1 => Self::InterfaceLocal, @@ -280,19 +280,19 @@ impl Address { } /// Return the scope of the address. - pub(crate) fn scope(&self) -> Scope { + pub(crate) fn multicast_scope(&self) -> MulticastScope { if self.is_multicast() { - return Scope::from(self.as_bytes()[1] & 0b1111); + return MulticastScope::from(self.as_bytes()[1] & 0b1111); } if self.is_link_local() { - Scope::LinkLocal + MulticastScope::LinkLocal } else if self.is_unique_local() || self.is_global_unicast() { // ULA are considered global scope // https://www.rfc-editor.org/rfc/rfc6724#section-3.1 - Scope::Global + MulticastScope::Global } else { - Scope::Unknown + MulticastScope::Unknown } } @@ -1263,40 +1263,46 @@ pub(crate) mod test { fn test_scope() { use super::*; assert_eq!( - Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::InterfaceLocal + Address::new(0xff01, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::InterfaceLocal ); assert_eq!( - Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::LinkLocal + Address::new(0xff02, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::LinkLocal ); assert_eq!( - Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::Unknown + Address::new(0xff03, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::Unknown ); assert_eq!( - Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::AdminLocal + Address::new(0xff04, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::AdminLocal ); assert_eq!( - Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::SiteLocal + Address::new(0xff05, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::SiteLocal ); assert_eq!( - Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::OrganizationLocal + Address::new(0xff08, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::OrganizationLocal ); assert_eq!( - Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).scope(), - Scope::Global + Address::new(0xff0e, 0, 0, 0, 0, 0, 0, 1).multicast_scope(), + MulticastScope::Global ); - assert_eq!(Address::LINK_LOCAL_ALL_NODES.scope(), Scope::LinkLocal); + assert_eq!( + Address::LINK_LOCAL_ALL_NODES.multicast_scope(), + MulticastScope::LinkLocal + ); // For source address selection, unicast addresses also have a scope: - assert_eq!(LINK_LOCAL_ADDR.scope(), Scope::LinkLocal); - assert_eq!(GLOBAL_UNICAST_ADDR.scope(), Scope::Global); - assert_eq!(UNIQUE_LOCAL_ADDR.scope(), Scope::Global); + assert_eq!(LINK_LOCAL_ADDR.multicast_scope(), MulticastScope::LinkLocal); + assert_eq!( + GLOBAL_UNICAST_ADDR.multicast_scope(), + MulticastScope::Global + ); + assert_eq!(UNIQUE_LOCAL_ADDR.multicast_scope(), MulticastScope::Global); } static REPR_PACKET_BYTES: [u8; 52] = [ diff --git a/src/wire/mod.rs b/src/wire/mod.rs index abfa8bdfc..98861912f 100644 --- a/src/wire/mod.rs +++ b/src/wire/mod.rs @@ -191,7 +191,7 @@ pub use self::ipv4::{ }; #[cfg(feature = "proto-ipv6")] -pub(crate) use self::ipv6::Scope as Ipv6AddressScope; +pub(crate) use self::ipv6::MulticastScope as Ipv6MulticastScope; #[cfg(feature = "proto-ipv6")] pub use self::ipv6::{ Address as Ipv6Address, Cidr as Ipv6Cidr, Packet as Ipv6Packet, Repr as Ipv6Repr,