Przeglądaj źródła

Remove IpRepr::Sixlowpan

Thibaut Vandervelden 3 lat temu
rodzic
commit
ddfd6f883c
3 zmienionych plików z 18 dodań i 104 usunięć
  1. 17 78
      src/iface/interface.rs
  2. 0 25
      src/wire/ip.rs
  3. 1 1
      src/wire/sixlowpan.rs

+ 17 - 78
src/iface/interface.rs

@@ -1125,7 +1125,13 @@ impl<'a> InterfaceInner<'a> {
         )?;
 
         let payload = iphc_packet.payload();
-        let ip_repr = IpRepr::Sixlowpan(iphc_repr);
+        let mut ipv6_repr = Ipv6Repr {
+            src_addr: iphc_repr.src_addr,
+            dst_addr: iphc_repr.dst_addr,
+            hop_limit: iphc_repr.hop_limit,
+            next_header: IpProtocol::Unknown(0),
+            payload_len: iphc_repr.buffer_len(),
+        };
 
         // Currently we assume the next header is a UDP, so we mark all the rest with todo.
         match iphc_repr.next_header {
@@ -1136,6 +1142,7 @@ impl<'a> InterfaceInner<'a> {
                         Ok(None)
                     }
                     SixlowpanNhcPacket::UdpHeader(udp_packet) => {
+                        ipv6_repr.next_header = IpProtocol::Udp;
                         // Handle the UDP
                         let udp_repr = SixlowpanUdpRepr::parse(
                             &udp_packet,
@@ -1147,36 +1154,21 @@ impl<'a> InterfaceInner<'a> {
                         // Look for UDP sockets that will accept the UDP packet.
                         // If it does not accept the packet, then send an ICMP message.
                         for mut udp_socket in sockets.iter_mut().filter_map(UdpSocket::downcast) {
-                            if !udp_socket.accepts(&ip_repr, &udp_repr) {
+                            if !udp_socket.accepts(&IpRepr::Ipv6(ipv6_repr), &udp_repr) {
                                 continue;
                             }
 
-                            match udp_socket.process(cx, &ip_repr, &udp_repr, udp_packet.payload())
-                            {
+                            match udp_socket.process(
+                                cx,
+                                &IpRepr::Ipv6(ipv6_repr),
+                                &udp_repr,
+                                udp_packet.payload(),
+                            ) {
                                 Ok(()) => return Ok(None),
                                 Err(e) => return Err(e),
                             }
                         }
 
-                        // TODO(thvdveld): verify this implementation of sending an ICMP
-                        let src_addr = match ip_repr.src_addr() {
-                            IpAddress::Ipv6(addr) => addr,
-                            _ => unreachable!(),
-                        };
-
-                        let dst_addr = match ip_repr.dst_addr() {
-                            IpAddress::Ipv6(addr) => addr,
-                            _ => unreachable!(),
-                        };
-
-                        let ipv6_repr = Ipv6Repr {
-                            src_addr,
-                            dst_addr,
-                            hop_limit: ip_repr.hop_limit(),
-                            next_header: IpProtocol::Unknown(0),
-                            payload_len: ip_repr.payload_len(),
-                        };
-
                         let payload_len = icmp_reply_payload_len(
                             payload.len(),
                             IPV6_MIN_MTU,
@@ -1193,7 +1185,8 @@ impl<'a> InterfaceInner<'a> {
             }
             SixlowpanNextHeader::Uncompressed(nxt_hdr) => match nxt_hdr {
                 IpProtocol::Icmpv6 => {
-                    self.process_icmpv6(cx, sockets, ip_repr, iphc_packet.payload())
+                    ipv6_repr.next_header = IpProtocol::Icmpv6;
+                    self.process_icmpv6(cx, sockets, IpRepr::Ipv6(ipv6_repr), iphc_packet.payload())
                 }
                 _ => {
                     net_debug!("Headers other than ICMPv6 and compressed headers are currently not supported for 6LoWPAN");
@@ -1627,24 +1620,6 @@ impl<'a> InterfaceInner<'a> {
                     };
                     Ok(self.icmpv6_reply(ipv6_repr, icmp_reply_repr))
                 }
-                #[cfg(feature = "medium-ieee802154")]
-                IpRepr::Sixlowpan(sixlowpan_repr) => {
-                    let icmp_reply_repr = Icmpv6Repr::EchoReply {
-                        ident,
-                        seq_no,
-                        data,
-                    };
-                    Ok(self.icmpv6_reply(
-                        Ipv6Repr {
-                            src_addr: sixlowpan_repr.src_addr,
-                            dst_addr: sixlowpan_repr.dst_addr,
-                            next_header: IpProtocol::Unknown(0),
-                            payload_len: data.len(),
-                            hop_limit: 64,
-                        },
-                        icmp_reply_repr,
-                    ))
-                }
                 _ => Err(Error::Unrecognized),
             },
 
@@ -1655,20 +1630,6 @@ impl<'a> InterfaceInner<'a> {
             #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
             Icmpv6Repr::Ndisc(repr) if ip_repr.hop_limit() == 0xff => match ip_repr {
                 IpRepr::Ipv6(ipv6_repr) => self.process_ndisc(cx, ipv6_repr, repr),
-                #[cfg(feature = "medium-ieee802154")]
-                IpRepr::Sixlowpan(sixlowpan_repr) => {
-                    self.process_ndisc(
-                        cx,
-                        Ipv6Repr {
-                            src_addr: sixlowpan_repr.src_addr,
-                            dst_addr: sixlowpan_repr.dst_addr,
-                            next_header: IpProtocol::Unknown(0),
-                            payload_len: 10, // 2 + 8
-                            hop_limit: sixlowpan_repr.hop_limit,
-                        },
-                        repr,
-                    )
-                }
                 _ => Ok(None),
             },
 
@@ -1980,28 +1941,6 @@ impl<'a> InterfaceInner<'a> {
                 };
                 Ok(self.icmpv6_reply(ipv6_repr, icmpv6_reply_repr))
             }
-            #[cfg(feature = "proto-sixlowpan")]
-            IpRepr::Sixlowpan(sixlowpan_repr) => {
-                let ipv6_repr = Ipv6Repr {
-                    src_addr: sixlowpan_repr.src_addr,
-                    dst_addr: sixlowpan_repr.dst_addr,
-                    next_header: IpProtocol::Udp, // XXX
-                    payload_len: ip_payload.len(),
-                    hop_limit: sixlowpan_repr.hop_limit,
-                };
-
-                let payload_len = icmp_reply_payload_len(
-                    ip_payload.len(),
-                    IPV6_MIN_MTU,
-                    sixlowpan_repr.buffer_len(),
-                );
-                let icmpv6_reply_repr = Icmpv6Repr::DstUnreachable {
-                    reason: Icmpv6DstUnreachable::PortUnreachable,
-                    header: ipv6_repr,
-                    data: &ip_payload[0..payload_len],
-                };
-                Ok(self.icmpv6_reply(ipv6_repr, icmpv6_reply_repr))
-            }
             IpRepr::Unspecified { .. } => Err(Error::Unaddressable),
         }
     }

+ 0 - 25
src/wire/ip.rs

@@ -6,8 +6,6 @@ use crate::phy::ChecksumCapabilities;
 use crate::wire::{Ipv4Address, Ipv4Cidr, Ipv4Packet, Ipv4Repr};
 #[cfg(feature = "proto-ipv6")]
 use crate::wire::{Ipv6Address, Ipv6Cidr, Ipv6Packet, Ipv6Repr};
-#[cfg(feature = "proto-sixlowpan")]
-use crate::wire::{SixlowpanIphcPacket, SixlowpanIphcRepr};
 use crate::{Error, Result};
 
 /// Internet protocol version.
@@ -515,8 +513,6 @@ pub enum Repr {
     Ipv4(Ipv4Repr),
     #[cfg(feature = "proto-ipv6")]
     Ipv6(Ipv6Repr),
-    #[cfg(feature = "proto-sixlowpan")]
-    Sixlowpan(SixlowpanIphcRepr),
 }
 
 #[cfg(feature = "proto-ipv4")]
@@ -542,8 +538,6 @@ impl Repr {
             Repr::Ipv4(_) => Version::Ipv4,
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(_) => Version::Ipv6,
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(_) => Version::Ipv6,
         }
     }
 
@@ -555,8 +549,6 @@ impl Repr {
             Repr::Ipv4(repr) => Address::Ipv4(repr.src_addr),
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => Address::Ipv6(repr.src_addr),
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => Address::Ipv6(repr.src_addr),
         }
     }
 
@@ -568,8 +560,6 @@ impl Repr {
             Repr::Ipv4(repr) => Address::Ipv4(repr.dst_addr),
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => Address::Ipv6(repr.dst_addr),
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => Address::Ipv6(repr.dst_addr),
         }
     }
 
@@ -581,8 +571,6 @@ impl Repr {
             Repr::Ipv4(repr) => repr.protocol,
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => repr.next_header,
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => todo!("{:?}", repr),
         }
     }
 
@@ -594,8 +582,6 @@ impl Repr {
             Repr::Ipv4(repr) => repr.payload_len,
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => repr.payload_len,
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => todo!("{:?}", repr),
         }
     }
 
@@ -616,8 +602,6 @@ impl Repr {
                 ref mut payload_len,
                 ..
             }) => *payload_len = length,
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(_) => todo!(),
         }
     }
 
@@ -629,8 +613,6 @@ impl Repr {
             Repr::Ipv4(Ipv4Repr { hop_limit, .. }) => hop_limit,
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(Ipv6Repr { hop_limit, .. }) => hop_limit,
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(SixlowpanIphcRepr { hop_limit, .. }) => hop_limit,
         }
     }
 
@@ -771,9 +753,6 @@ impl Repr {
                 resolve_unspecified!(Repr::Ipv6, Address::Ipv6, repr, fallback_src_addrs)
             }
 
-            #[cfg(feature = "proto-sixlowpan")]
-            &Repr::Sixlowpan(_) => todo!(), // TODO(thvdveld): what do we need to do here?
-
             &Repr::Unspecified { .. } => {
                 panic!("source and destination IP address families do not match")
             }
@@ -791,8 +770,6 @@ impl Repr {
             Repr::Ipv4(repr) => repr.buffer_len(),
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => repr.buffer_len(),
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => repr.buffer_len(),
         }
     }
 
@@ -811,8 +788,6 @@ impl Repr {
             Repr::Ipv4(repr) => repr.emit(&mut Ipv4Packet::new_unchecked(buffer), _checksum_caps),
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => repr.emit(&mut Ipv6Packet::new_unchecked(buffer)),
-            #[cfg(feature = "proto-sixlowpan")]
-            Repr::Sixlowpan(repr) => repr.emit(&mut SixlowpanIphcPacket::new_unchecked(buffer)),
         }
     }
 

+ 1 - 1
src/wire/sixlowpan.rs

@@ -1381,7 +1381,7 @@ pub mod nhc {
     impl<'a, T: AsRef<[u8]> + AsMut<[u8]>> UdpPacket<T> {
         /// Return a mutable pointer to the payload.
         pub fn payload_mut(&mut self) -> &mut [u8] {
-            let start = 1 + self.ports_size() + self.checksum_size();
+            let start = 1 + self.ports_size() + 2; // XXX(thvdveld): we assume we put the checksum inlined.
             &mut self.buffer.as_mut()[start..]
         }