Эх сурвалжийг харах

wire: remove HardwareAddress::BROADCAST

Dario Nieuwenhuis 3 жил өмнө
parent
commit
102db1d156

+ 21 - 12
src/iface/interface.rs

@@ -2165,42 +2165,51 @@ impl<'a> InterfaceInner<'a> {
     where
         Tx: TxToken,
     {
+        if dst_addr.is_broadcast() {
+            let hardware_addr = match cx.caps.medium {
+                #[cfg(feature = "medium-ethernet")]
+                Medium::Ethernet => HardwareAddress::Ethernet(EthernetAddress::BROADCAST),
+                #[cfg(feature = "medium-ieee802154")]
+                Medium::Ieee802154 => HardwareAddress::Ieee802154(Ieee802154Address::BROADCAST),
+                #[cfg(feature = "medium-ip")]
+                Medium::Ip => unreachable!(),
+            };
+
+            return Ok((hardware_addr, tx_token));
+        }
+
         if dst_addr.is_multicast() {
             let b = dst_addr.as_bytes();
             let hardware_addr = match *dst_addr {
-                IpAddress::Unspecified => None,
+                IpAddress::Unspecified => unreachable!(),
                 #[cfg(feature = "proto-ipv4")]
                 IpAddress::Ipv4(_addr) => {
-                    Some(HardwareAddress::Ethernet(EthernetAddress::from_bytes(&[
+                    HardwareAddress::Ethernet(EthernetAddress::from_bytes(&[
                         0x01,
                         0x00,
                         0x5e,
                         b[1] & 0x7F,
                         b[2],
                         b[3],
-                    ])))
+                    ]))
                 }
                 #[cfg(feature = "proto-ipv6")]
                 IpAddress::Ipv6(_addr) => match cx.caps.medium {
                     #[cfg(feature = "medium-ethernet")]
-                    Medium::Ethernet => {
-                        Some(HardwareAddress::Ethernet(EthernetAddress::from_bytes(&[
-                            0x33, 0x33, b[12], b[13], b[14], b[15],
-                        ])))
-                    }
+                    Medium::Ethernet => HardwareAddress::Ethernet(EthernetAddress::from_bytes(&[
+                        0x33, 0x33, b[12], b[13], b[14], b[15],
+                    ])),
                     #[cfg(feature = "medium-ieee802154")]
                     Medium::Ieee802154 => {
                         // Not sure if this is correct
-                        Some(HardwareAddress::Ieee802154(Ieee802154Address::BROADCAST))
+                        HardwareAddress::Ieee802154(Ieee802154Address::BROADCAST)
                     }
                     #[cfg(feature = "medium-ip")]
                     Medium::Ip => unreachable!(),
                 },
             };
 
-            if let Some(hardware_addr) = hardware_addr {
-                return Ok((hardware_addr, tx_token));
-            }
+            return Ok((hardware_addr, tx_token));
         }
 
         let dst_addr = self.route(dst_addr, cx.now)?;

+ 1 - 3
src/iface/neighbor.rs

@@ -196,9 +196,7 @@ impl<'a> Cache<'a> {
     }
 
     pub(crate) fn lookup(&self, protocol_addr: &IpAddress, timestamp: Instant) -> Answer {
-        if protocol_addr.is_broadcast() {
-            return Answer::Found(HardwareAddress::BROADCAST);
-        }
+        assert!(protocol_addr.is_unicast());
 
         if let Some(&Neighbor {
             expires_at,

+ 0 - 5
src/wire/mod.rs

@@ -246,7 +246,6 @@ pub use self::dhcpv4::{
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum HardwareAddress {
-    BROADCAST,
     #[cfg(feature = "medium-ethernet")]
     Ethernet(EthernetAddress),
     #[cfg(feature = "medium-ieee802154")]
@@ -260,7 +259,6 @@ impl HardwareAddress {
             HardwareAddress::Ethernet(addr) => addr.as_bytes(),
             #[cfg(feature = "medium-ieee802154")]
             HardwareAddress::Ieee802154(addr) => addr.as_bytes(),
-            _ => todo!(),
         }
     }
 
@@ -271,7 +269,6 @@ impl HardwareAddress {
             HardwareAddress::Ethernet(addr) => addr.is_unicast(),
             #[cfg(feature = "medium-ieee802154")]
             HardwareAddress::Ieee802154(addr) => addr.is_unicast(),
-            _ => todo!(),
         }
     }
 
@@ -282,7 +279,6 @@ impl HardwareAddress {
             HardwareAddress::Ethernet(addr) => addr.is_broadcast(),
             #[cfg(feature = "medium-ieee802154")]
             HardwareAddress::Ieee802154(addr) => addr.is_broadcast(),
-            _ => todo!(),
         }
     }
 }
@@ -290,7 +286,6 @@ impl HardwareAddress {
 impl core::fmt::Display for HardwareAddress {
     fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
         match self {
-            HardwareAddress::BROADCAST => write!(f, "BROADCAST"),
             #[cfg(feature = "medium-ethernet")]
             HardwareAddress::Ethernet(addr) => write!(f, "{}", addr),
             #[cfg(feature = "medium-ieee802154")]