diff --git a/src/iface/interface/ipv4.rs b/src/iface/interface/ipv4.rs index a881817dd..1a07a086e 100644 --- a/src/iface/interface/ipv4.rs +++ b/src/iface/interface/ipv4.rs @@ -122,7 +122,7 @@ impl InterfaceInner { } match ipv4_repr.next_header { - IpProtocol::Icmp => self.process_icmpv4(sockets, ip_repr, ip_payload), + IpProtocol::Icmp => self.process_icmpv4(sockets, &ipv4_repr, ip_payload), #[cfg(feature = "proto-igmp")] IpProtocol::Igmp => self.process_igmp(ipv4_repr, ip_payload), @@ -140,8 +140,8 @@ impl InterfaceInner { self.process_udp( sockets, meta, - ip_repr, - udp_repr, + &ip_repr, + &udp_repr, handled_by_raw_socket, udp_packet.payload(), ip_payload, @@ -149,7 +149,17 @@ impl InterfaceInner { } #[cfg(feature = "socket-tcp")] - IpProtocol::Tcp => self.process_tcp(sockets, ip_repr, ip_payload), + IpProtocol::Tcp => { + let (src_addr, dst_addr) = (ip_repr.src_addr(), ip_repr.dst_addr()); + let tcp_packet = check!(TcpPacket::new_checked(ip_payload)); + let tcp_repr = check!(TcpRepr::parse( + &tcp_packet, + &src_addr, + &dst_addr, + &self.caps.checksum + )); + self.process_tcp(sockets, ip_repr, &tcp_repr) + } _ if handled_by_raw_socket => None, @@ -162,7 +172,7 @@ impl InterfaceInner { header: ipv4_repr, data: &ip_payload[0..payload_len], }; - self.icmpv4_reply(ipv4_repr, icmp_reply_repr) + self.icmpv4_reply(&ipv4_repr, &icmp_reply_repr) } } } @@ -236,7 +246,7 @@ impl InterfaceInner { pub(super) fn process_icmpv4<'frame>( &mut self, _sockets: &mut SocketSet, - ip_repr: IpRepr, + ip_repr: &Ipv4Repr, ip_payload: &'frame [u8], ) -> Option> { let icmp_packet = check!(Icmpv4Packet::new_checked(ip_payload)); @@ -250,8 +260,8 @@ impl InterfaceInner { .items_mut() .filter_map(|i| icmp::Socket::downcast_mut(&mut i.socket)) { - if icmp_socket.accepts(self, &ip_repr, &icmp_repr.into()) { - icmp_socket.process(self, &ip_repr, &icmp_repr.into()); + if icmp_socket.accepts(self, &IpRepr::Ipv4(*ip_repr), &icmp_repr.into()) { + icmp_socket.process(self, &IpRepr::Ipv4(*ip_repr), &icmp_repr.into()); handled_by_icmp_socket = true; } } @@ -269,11 +279,7 @@ impl InterfaceInner { seq_no, data, }; - match ip_repr { - IpRepr::Ipv4(ipv4_repr) => self.icmpv4_reply(ipv4_repr, icmp_reply_repr), - #[allow(unreachable_patterns)] - _ => unreachable!(), - } + self.icmpv4_reply(ip_repr, &icmp_reply_repr) } // Ignore any echo replies. @@ -291,8 +297,8 @@ impl InterfaceInner { pub(super) fn icmpv4_reply<'frame, 'icmp: 'frame>( &self, - ipv4_repr: Ipv4Repr, - icmp_repr: Icmpv4Repr<'icmp>, + ipv4_repr: &Ipv4Repr, + icmp_repr: &Icmpv4Repr<'icmp>, ) -> Option> { if !self.is_unicast_v4(ipv4_repr.src_addr) { // Do not send ICMP replies to non-unicast sources @@ -308,7 +314,7 @@ impl InterfaceInner { }; Some(IpPacket::new_ipv4( ipv4_reply_repr, - IpPayload::Icmpv4(icmp_repr), + IpPayload::Icmpv4(*icmp_repr), )) } else if self.is_broadcast_v4(ipv4_repr.dst_addr) { // Only reply to broadcasts for echo replies and not other ICMP messages @@ -324,7 +330,7 @@ impl InterfaceInner { }; Some(IpPacket::new_ipv4( ipv4_reply_repr, - IpPayload::Icmpv4(icmp_repr), + IpPayload::Icmpv4(*icmp_repr), )) } None => None, diff --git a/src/iface/interface/ipv6.rs b/src/iface/interface/ipv6.rs index de4867530..02d02b8ad 100644 --- a/src/iface/interface/ipv6.rs +++ b/src/iface/interface/ipv6.rs @@ -8,8 +8,9 @@ use super::{IpPacket, IpPayload}; use crate::socket::icmp; use crate::socket::AnySocket; +use crate::iface::ip_packet::Ipv6Packet; use crate::phy::PacketMeta; -use crate::wire::*; +use crate::wire::{Ipv6Packet as Ipv6PacketWire, *}; impl InterfaceInner { #[cfg(feature = "proto-ipv6")] @@ -17,153 +18,214 @@ impl InterfaceInner { &mut self, sockets: &mut SocketSet, meta: PacketMeta, - ipv6_packet: &Ipv6Packet<&'frame [u8]>, + ipv6_packet: &Ipv6PacketWire<&'frame [u8]>, ) -> Option> { let ipv6_repr = check!(Ipv6Repr::parse(ipv6_packet)); + let packet = check!(self.parse_ipv6(ipv6_repr, ipv6_packet.payload())); - if !ipv6_repr.src_addr.is_unicast() { + if !packet.header.src_addr.is_unicast() { // Discard packets with non-unicast source addresses. net_debug!("non-unicast source address"); return None; } - let ip_payload = ipv6_packet.payload(); + if let Some(hbh) = &packet.hop_by_hop { + self.process_hopbyhop(&packet.header, hbh)?; + } + + #[cfg(feature = "proto-ipv6-routing")] + if let Some(routing) = &packet.routing { + self.process_routing(&packet.header, routing); + } + + #[cfg(feature = "proto-ipv6-fragmentation")] + if let Some(fragment) = &packet.fragment { + self.process_fragment(&packet.header, fragment); + } #[cfg(feature = "socket-raw")] - let handled_by_raw_socket = self.raw_socket_filter(sockets, &ipv6_repr.into(), ip_payload); + let handled_by_raw_socket = + self.raw_socket_filter(sockets, &IpRepr::Ipv6(packet.header), ipv6_packet.payload()); #[cfg(not(feature = "socket-raw"))] let handled_by_raw_socket = false; - self.process_nxt_hdr( - sockets, - meta, - ipv6_repr, - ipv6_repr.next_header, - handled_by_raw_socket, - ip_payload, - ) - } - - /// Given the next header value forward the payload onto the correct process - /// function. - #[cfg(feature = "proto-ipv6")] - pub(super) fn process_nxt_hdr<'frame>( - &mut self, - sockets: &mut SocketSet, - meta: PacketMeta, - ipv6_repr: Ipv6Repr, - nxt_hdr: IpProtocol, - handled_by_raw_socket: bool, - ip_payload: &'frame [u8], - ) -> Option> { - match nxt_hdr { - IpProtocol::Icmpv6 => self.process_icmpv6(sockets, ipv6_repr.into(), ip_payload), - - #[cfg(any(feature = "socket-udp", feature = "socket-dns"))] - IpProtocol::Udp => { - let udp_packet = check!(UdpPacket::new_checked(ip_payload)); - let udp_repr = check!(UdpRepr::parse( - &udp_packet, - &ipv6_repr.src_addr.into(), - &ipv6_repr.dst_addr.into(), - &self.checksum_caps(), - )); - - self.process_udp( - sockets, - meta, - ipv6_repr.into(), - udp_repr, - handled_by_raw_socket, - udp_packet.payload(), - ip_payload, - ) - } - + match &packet.payload { #[cfg(feature = "socket-tcp")] - IpProtocol::Tcp => self.process_tcp(sockets, ipv6_repr.into(), ip_payload), - - IpProtocol::HopByHop => { - self.process_hopbyhop(sockets, meta, ipv6_repr, handled_by_raw_socket, ip_payload) - } - - #[cfg(feature = "socket-raw")] + IpPayload::Tcp(tcp) => self.process_tcp(sockets, IpRepr::Ipv6(ipv6_repr), tcp), + #[cfg(feature = "socket-udp")] + IpPayload::Udp(udp, data) => self.process_udp( + sockets, + meta, + &IpRepr::Ipv6(packet.header), + udp, + false, + data, + ipv6_packet.payload(), + ), + IpPayload::Icmpv6(icmp) => self.process_icmpv6(sockets, &packet.header, icmp), _ if handled_by_raw_socket => None, - _ => { // Send back as much of the original payload as we can. - let payload_len = - icmp_reply_payload_len(ip_payload.len(), IPV6_MIN_MTU, ipv6_repr.buffer_len()); + let payload_len = icmp_reply_payload_len( + ipv6_packet.payload().len(), + IPV6_MIN_MTU, + ipv6_repr.buffer_len(), + ); let icmp_reply_repr = Icmpv6Repr::ParamProblem { reason: Icmpv6ParamProblem::UnrecognizedNxtHdr, // The offending packet is after the IPv6 header. pointer: ipv6_repr.buffer_len() as u32, header: ipv6_repr, - data: &ip_payload[0..payload_len], + data: &ipv6_packet.payload()[0..payload_len], }; - self.icmpv6_reply(ipv6_repr, icmp_reply_repr) + self.icmpv6_reply(&ipv6_repr, &icmp_reply_repr) } } } - #[cfg(feature = "proto-ipv6")] + fn parse_ipv6<'payload>( + &self, + header: Ipv6Repr, + mut data: &'payload [u8], + ) -> Result> { + let mut packet = Ipv6Packet { + header, + hop_by_hop: None, + #[cfg(feature = "proto-ipv6-routing")] + routing: None, + #[cfg(feature = "proto-ipv6-fragmentation")] + fragment: None, + payload: IpPayload::Raw(data), + }; + + let mut next_header = Some(header.next_header); + + while let Some(nh) = next_header { + match nh { + IpProtocol::HopByHop => { + let ext_hdr = Ipv6ExtHeader::new_checked(data)?; + let ext_repr = Ipv6ExtHeaderRepr::parse(&ext_hdr)?; + let hbh_hdr = Ipv6HopByHopHeader::new_checked(ext_repr.data)?; + let hbh_repr = Ipv6HopByHopRepr::parse(&hbh_hdr)?; + + next_header = Some(ext_repr.next_header); + data = &data[ext_repr.header_len() + ext_repr.data.len()..]; + + packet.hop_by_hop = Some(hbh_repr); + } + #[cfg(feature = "proto-ipv6-routing")] + IpProtocol::Ipv6Route => { + let ext_hdr = Ipv6ExtHeader::new_checked(data)?; + let ext_repr = Ipv6ExtHeaderRepr::parse(&ext_hdr)?; + let routing_hdr = Ipv6RoutingHeader::new_checked(ext_repr.data)?; + let routing_repr = Ipv6RoutingRepr::parse(&routing_hdr)?; + + next_header = Some(ext_repr.next_header); + data = &data[ext_repr.header_len() + ext_repr.data.len()..]; + packet.routing = Some(routing_repr); + } + #[cfg(feature = "proto-ipv6-fragmentation")] + IpProtocol::Ipv6Frag => { + let ext_hdr = Ipv6ExtHeader::new_checked(data)?; + let ext_repr = Ipv6ExtHeaderRepr::parse(&ext_hdr)?; + let fragment_hdr = Ipv6FragmentHeader::new_checked(ext_repr.data)?; + let fragment_repr = Ipv6FragmentRepr::parse(&fragment_hdr)?; + + next_header = Some(ext_repr.next_header); + data = &data[ext_repr.header_len() + ext_repr.data.len()..]; + packet.fragment = Some(fragment_repr); + } + + IpProtocol::Icmpv6 => { + let icmp_packet = Icmpv6Packet::new_checked(data)?; + let icmp_repr = Icmpv6Repr::parse( + &header.src_addr.into(), + &header.dst_addr.into(), + &icmp_packet, + &self.caps.checksum, + )?; + + packet.payload = IpPayload::Icmpv6(icmp_repr); + break; + } + #[cfg(feature = "socket-tcp")] + IpProtocol::Tcp => { + let tcp_packet = TcpPacket::new_checked(data)?; + let tcp_repr = TcpRepr::parse( + &tcp_packet, + &header.src_addr.into(), + &header.dst_addr.into(), + &self.caps.checksum, + )?; + + packet.payload = IpPayload::Tcp(tcp_repr); + break; + } + #[cfg(feature = "socket-udp")] + IpProtocol::Udp => { + let udp_packet = UdpPacket::new_checked(data)?; + let udp_repr = UdpRepr::parse( + &udp_packet, + &header.src_addr.into(), + &header.dst_addr.into(), + &self.checksum_caps(), + )?; + + packet.payload = IpPayload::Udp(udp_repr, udp_packet.payload()); + break; + } + + _ => { + packet.payload = IpPayload::Raw(data); + break; + } + } + } + + Ok(packet) + } + pub(super) fn process_icmpv6<'frame>( &mut self, _sockets: &mut SocketSet, - ip_repr: IpRepr, - ip_payload: &'frame [u8], + header: &Ipv6Repr, + icmp: &Icmpv6Repr<'frame>, ) -> Option> { - let icmp_packet = check!(Icmpv6Packet::new_checked(ip_payload)); - let icmp_repr = check!(Icmpv6Repr::parse( - &ip_repr.src_addr(), - &ip_repr.dst_addr(), - &icmp_packet, - &self.caps.checksum, - )); - #[cfg(feature = "socket-icmp")] let mut handled_by_icmp_socket = false; - #[cfg(all(feature = "socket-icmp", feature = "proto-ipv6"))] + #[cfg(feature = "socket-icmp")] for icmp_socket in _sockets .items_mut() .filter_map(|i| icmp::Socket::downcast_mut(&mut i.socket)) { - if icmp_socket.accepts(self, &ip_repr, &icmp_repr.into()) { - icmp_socket.process(self, &ip_repr, &icmp_repr.into()); + if icmp_socket.accepts(self, &IpRepr::Ipv6(*header), &IcmpRepr::Ipv6(*icmp)) { + icmp_socket.process(self, &IpRepr::Ipv6(*header), &IcmpRepr::Ipv6(*icmp)); handled_by_icmp_socket = true; } } - match icmp_repr { + match icmp { // Respond to echo requests. Icmpv6Repr::EchoRequest { ident, seq_no, data, - } => match ip_repr { - IpRepr::Ipv6(ipv6_repr) => { - let icmp_reply_repr = Icmpv6Repr::EchoReply { - ident, - seq_no, - data, - }; - self.icmpv6_reply(ipv6_repr, icmp_reply_repr) - } - #[allow(unreachable_patterns)] - _ => unreachable!(), - }, + } => { + let icmp_reply_repr = Icmpv6Repr::EchoReply { + ident: *ident, + seq_no: *seq_no, + data, + }; + self.icmpv6_reply(header, &icmp_reply_repr) + } // Ignore any echo replies. Icmpv6Repr::EchoReply { .. } => None, // Forward any NDISC packets to the ndisc packet handler #[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(ipv6_repr, repr), - #[allow(unreachable_patterns)] - _ => unreachable!(), - }, + Icmpv6Repr::Ndisc(repr) if header.hop_limit == 0xff => self.process_ndisc(header, repr), // Don't report an error if a packet with unknown type // has been handled by an ICMP socket @@ -175,14 +237,11 @@ impl InterfaceInner { } } - #[cfg(all( - any(feature = "medium-ethernet", feature = "medium-ieee802154"), - feature = "proto-ipv6" - ))] + #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))] pub(super) fn process_ndisc<'frame>( &mut self, - ip_repr: Ipv6Repr, - repr: NdiscRepr<'frame>, + ip_repr: &Ipv6Repr, + repr: &NdiscRepr<'frame>, ) -> Option> { match repr { NdiscRepr::NeighborAdvert { @@ -218,15 +277,15 @@ impl InterfaceInner { .fill(ip_repr.src_addr.into(), lladdr, self.now); } - if self.has_solicited_node(ip_repr.dst_addr) && self.has_ip_addr(target_addr) { + if self.has_solicited_node(ip_repr.dst_addr) && self.has_ip_addr(*target_addr) { let advert = Icmpv6Repr::Ndisc(NdiscRepr::NeighborAdvert { flags: NdiscNeighborFlags::SOLICITED, - target_addr, + target_addr: *target_addr, #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))] lladdr: Some(self.hardware_addr.into()), }); let ip_repr = Ipv6Repr { - src_addr: target_addr, + src_addr: *target_addr, dst_addr: ip_repr.src_addr, next_header: IpProtocol::Icmpv6, hop_limit: 0xff, @@ -241,21 +300,12 @@ impl InterfaceInner { } } - #[cfg(feature = "proto-ipv6")] - pub(super) fn process_hopbyhop<'frame>( + pub(super) fn process_hopbyhop( &mut self, - sockets: &mut SocketSet, - meta: PacketMeta, - ipv6_repr: Ipv6Repr, - handled_by_raw_socket: bool, - ip_payload: &'frame [u8], - ) -> Option> { - let ext_hdr = check!(Ipv6ExtHeader::new_checked(ip_payload)); - let ext_repr = check!(Ipv6ExtHeaderRepr::parse(&ext_hdr)); - let hbh_hdr = check!(Ipv6HopByHopHeader::new_checked(ext_repr.data)); - let hbh_repr = check!(Ipv6HopByHopRepr::parse(&hbh_hdr)); - - for opt_repr in &hbh_repr.options { + _ipv6_repr: &Ipv6Repr, + hbh: &Ipv6HopByHopRepr, + ) -> Option<()> { + for opt_repr in &hbh.options { match opt_repr { Ipv6OptionRepr::Pad1 | Ipv6OptionRepr::PadN(_) => (), #[cfg(feature = "proto-rpl")] @@ -276,21 +326,35 @@ impl InterfaceInner { } } } - self.process_nxt_hdr( - sockets, - meta, - ipv6_repr, - ext_repr.next_header, - handled_by_raw_socket, - &ip_payload[ext_repr.header_len() + ext_repr.data.len()..], - ) + + Some(()) + } + + #[cfg(feature = "proto-ipv6-routing")] + pub(super) fn process_routing<'frame>( + &mut self, + ipv6_repr: &Ipv6Repr, + routing: &Ipv6RoutingRepr<'frame>, + ) { + match routing { + Ipv6RoutingRepr::Type2 { .. } => { + net_debug!("IPv6 Type2 routing header not supported yet"); + } + Ipv6RoutingRepr::Rpl { .. } => { + net_debug!("IPv6 Rpl routing header not supported yet"); + } + } + } + + #[cfg(feature = "proto-ipv6-fragmentation")] + pub(super) fn process_fragment(&mut self, ipv6_repr: &ipv6repr, fragment: &ipv6fragmentrepr) { + net_debug!("IPv6 Fragment header not supported yet"); } - #[cfg(feature = "proto-ipv6")] pub(super) fn icmpv6_reply<'frame, 'icmp: 'frame>( &self, - ipv6_repr: Ipv6Repr, - icmp_repr: Icmpv6Repr<'icmp>, + ipv6_repr: &Ipv6Repr, + icmp_repr: &Icmpv6Repr<'icmp>, ) -> Option> { if ipv6_repr.dst_addr.is_unicast() { let ipv6_reply_repr = Ipv6Repr { @@ -302,7 +366,7 @@ impl InterfaceInner { }; Some(IpPacket::new_ipv6( ipv6_reply_repr, - IpPayload::Icmpv6(icmp_repr), + IpPayload::Icmpv6(*icmp_repr), )) } else { // Do not send any ICMP replies to a broadcast destination address. diff --git a/src/iface/interface/mod.rs b/src/iface/interface/mod.rs index bd682496d..fa20971d0 100644 --- a/src/iface/interface/mod.rs +++ b/src/iface/interface/mod.rs @@ -1148,8 +1148,8 @@ impl InterfaceInner { &mut self, sockets: &mut SocketSet, meta: PacketMeta, - ip_repr: IpRepr, - udp_repr: UdpRepr, + ip_repr: &IpRepr, + udp_repr: &UdpRepr, handled_by_raw_socket: bool, udp_payload: &'frame [u8], ip_payload: &'frame [u8], @@ -1159,8 +1159,8 @@ impl InterfaceInner { .items_mut() .filter_map(|i| udp::Socket::downcast_mut(&mut i.socket)) { - if udp_socket.accepts(self, &ip_repr, &udp_repr) { - udp_socket.process(self, meta, &ip_repr, &udp_repr, udp_payload); + if udp_socket.accepts(self, ip_repr, udp_repr) { + udp_socket.process(self, meta, ip_repr, udp_repr, udp_payload); return None; } } @@ -1170,8 +1170,8 @@ impl InterfaceInner { .items_mut() .filter_map(|i| dns::Socket::downcast_mut(&mut i.socket)) { - if dns_socket.accepts(&ip_repr, &udp_repr) { - dns_socket.process(self, &ip_repr, &udp_repr, udp_payload); + if dns_socket.accepts(ip_repr, udp_repr) { + dns_socket.process(self, ip_repr, udp_repr, udp_payload); return None; } } @@ -1188,10 +1188,10 @@ impl InterfaceInner { icmp_reply_payload_len(ip_payload.len(), IPV4_MIN_MTU, ipv4_repr.buffer_len()); let icmpv4_reply_repr = Icmpv4Repr::DstUnreachable { reason: Icmpv4DstUnreachable::PortUnreachable, - header: ipv4_repr, + header: *ipv4_repr, data: &ip_payload[0..payload_len], }; - self.icmpv4_reply(ipv4_repr, icmpv4_reply_repr) + self.icmpv4_reply(ipv4_repr, &icmpv4_reply_repr) } #[cfg(feature = "proto-ipv6")] IpRepr::Ipv6(ipv6_repr) => { @@ -1199,10 +1199,10 @@ impl InterfaceInner { icmp_reply_payload_len(ip_payload.len(), IPV6_MIN_MTU, ipv6_repr.buffer_len()); let icmpv6_reply_repr = Icmpv6Repr::DstUnreachable { reason: Icmpv6DstUnreachable::PortUnreachable, - header: ipv6_repr, + header: *ipv6_repr, data: &ip_payload[0..payload_len], }; - self.icmpv6_reply(ipv6_repr, icmpv6_reply_repr) + self.icmpv6_reply(ipv6_repr, &icmpv6_reply_repr) } } } @@ -1212,24 +1212,16 @@ impl InterfaceInner { &mut self, sockets: &mut SocketSet, ip_repr: IpRepr, - ip_payload: &'frame [u8], + //ip_payload: &'frame [u8], + tcp_repr: &TcpRepr, ) -> Option> { - let (src_addr, dst_addr) = (ip_repr.src_addr(), ip_repr.dst_addr()); - let tcp_packet = check!(TcpPacket::new_checked(ip_payload)); - let tcp_repr = check!(TcpRepr::parse( - &tcp_packet, - &src_addr, - &dst_addr, - &self.caps.checksum - )); - for tcp_socket in sockets .items_mut() .filter_map(|i| tcp::Socket::downcast_mut(&mut i.socket)) { - if tcp_socket.accepts(self, &ip_repr, &tcp_repr) { + if tcp_socket.accepts(self, &ip_repr, tcp_repr) { return tcp_socket - .process(self, &ip_repr, &tcp_repr) + .process(self, &ip_repr, tcp_repr) .map(|(ip, tcp)| IpPacket::new(ip, IpPayload::Tcp(tcp))); } } @@ -1239,7 +1231,7 @@ impl InterfaceInner { None } else { // The packet wasn't handled by a socket, send a TCP RST packet. - let (ip, tcp) = tcp::Socket::rst_reply(&ip_repr, &tcp_repr); + let (ip, tcp) = tcp::Socket::rst_reply(&ip_repr, tcp_repr); Some(IpPacket::new(ip, IpPayload::Tcp(tcp))) } } diff --git a/src/iface/interface/sixlowpan.rs b/src/iface/interface/sixlowpan.rs index bd079bd0e..9ef55ab1a 100644 --- a/src/iface/interface/sixlowpan.rs +++ b/src/iface/interface/sixlowpan.rs @@ -566,8 +566,7 @@ impl InterfaceInner { checksum_caps, ); } - #[cfg(feature = "socket-raw")] - IpPayload::Raw(_raw) => todo!(), + IpPayload::Raw(_) => todo!(), #[allow(unreachable_patterns)] _ => unreachable!(), diff --git a/src/iface/interface/tests/ipv4.rs b/src/iface/interface/tests/ipv4.rs index b5c167a40..32ba0e02d 100644 --- a/src/iface/interface/tests/ipv4.rs +++ b/src/iface/interface/tests/ipv4.rs @@ -239,8 +239,8 @@ fn test_icmp_error_port_unreachable(#[case] medium: Medium) { iface.inner.process_udp( &mut sockets, PacketMeta::default(), - ip_repr, - udp_repr, + &ip_repr, + &udp_repr, false, &UDP_PAYLOAD, data @@ -273,8 +273,8 @@ fn test_icmp_error_port_unreachable(#[case] medium: Medium) { iface.inner.process_udp( &mut sockets, PacketMeta::default(), - ip_repr, - udp_repr, + &ip_repr, + &udp_repr, false, &UDP_PAYLOAD, packet_broadcast.into_inner(), @@ -573,7 +573,6 @@ fn test_icmpv4_socket(#[case] medium: Medium) { payload_len: 24, hop_limit: 64, }; - let ip_repr = IpRepr::Ipv4(ipv4_repr); // Open a socket and ensure the packet is handled due to the listening // socket. @@ -591,7 +590,9 @@ fn test_icmpv4_socket(#[case] medium: Medium) { ..ipv4_repr }; assert_eq!( - iface.inner.process_icmpv4(&mut sockets, ip_repr, icmp_data), + iface + .inner + .process_icmpv4(&mut sockets, &ipv4_repr, icmp_data), Some(IpPacket::new_ipv4( ipv4_reply, IpPayload::Icmpv4(echo_reply) @@ -957,8 +958,8 @@ fn test_icmp_reply_size(#[case] medium: Medium) { iface.inner.process_udp( &mut sockets, PacketMeta::default(), - ip_repr.into(), - udp_repr, + &IpRepr::Ipv4(ip_repr), + &udp_repr, false, &vec![0x2a; MAX_PAYLOAD_LEN], payload, diff --git a/src/iface/interface/tests/ipv6.rs b/src/iface/interface/tests/ipv6.rs index 216d1941e..fdc2f8f08 100644 --- a/src/iface/interface/tests/ipv6.rs +++ b/src/iface/interface/tests/ipv6.rs @@ -721,8 +721,8 @@ fn test_icmp_reply_size(#[case] medium: Medium) { iface.inner.process_udp( &mut sockets, PacketMeta::default(), - ip_repr.into(), - udp_repr, + &IpRepr::Ipv6(ip_repr), + &udp_repr, false, &vec![0x2a; MAX_PAYLOAD_LEN], payload, diff --git a/src/iface/interface/tests/mod.rs b/src/iface/interface/tests/mod.rs index 8489a6a79..fdafd53a0 100644 --- a/src/iface/interface/tests/mod.rs +++ b/src/iface/interface/tests/mod.rs @@ -129,8 +129,8 @@ fn test_handle_udp_broadcast( iface.inner.process_udp( &mut sockets, PacketMeta::default(), - ip_repr, - udp_repr, + &ip_repr, + &udp_repr, false, &UDP_PAYLOAD, packet.into_inner(), diff --git a/src/iface/ip_packet.rs b/src/iface/ip_packet.rs index 8de72aa1b..1765dcdaf 100644 --- a/src/iface/ip_packet.rs +++ b/src/iface/ip_packet.rs @@ -42,7 +42,6 @@ impl<'p> IpPacket<'p> { pub(crate) fn new_ipv6(ip_repr: Ipv6Repr, payload: IpPayload<'p>) -> Self { Self::Ipv6(Ipv6Packet { header: ip_repr, - #[cfg(feature = "proto-ipv6-hbh")] hop_by_hop: None, #[cfg(feature = "proto-ipv6-fragmentation")] fragment: None, @@ -90,7 +89,6 @@ impl<'p> IpPacket<'p> { &mut Icmpv6Packet::new_unchecked(payload), &caps.checksum, ), - #[cfg(feature = "socket-raw")] IpPayload::Raw(raw_packet) => payload.copy_from_slice(raw_packet), #[cfg(any(feature = "socket-udp", feature = "socket-dns"))] IpPayload::Udp(udp_repr, inner_payload) => udp_repr.emit( @@ -154,7 +152,6 @@ pub(crate) struct Ipv4Packet<'p> { #[cfg(feature = "proto-ipv6")] pub(crate) struct Ipv6Packet<'p> { pub(crate) header: Ipv6Repr, - #[cfg(feature = "proto-ipv6-hbh")] pub(crate) hop_by_hop: Option>, #[cfg(feature = "proto-ipv6-fragmentation")] pub(crate) fragment: Option, @@ -172,7 +169,6 @@ pub(crate) enum IpPayload<'p> { Igmp(IgmpRepr), #[cfg(feature = "proto-ipv6")] Icmpv6(Icmpv6Repr<'p>), - #[cfg(feature = "socket-raw")] Raw(&'p [u8]), #[cfg(any(feature = "socket-udp", feature = "socket-dns"))] Udp(UdpRepr, &'p [u8]), @@ -198,8 +194,7 @@ impl<'p> IpPayload<'p> { Self::Tcp(_) => SixlowpanNextHeader::Uncompressed(IpProtocol::Tcp), #[cfg(feature = "socket-udp")] Self::Udp(..) => SixlowpanNextHeader::Compressed, - #[cfg(feature = "socket-raw")] - Self::Raw(_) => todo!(), + Self::Raw(_) => unreachable!(), } } } diff --git a/src/wire/ipv6hbh.rs b/src/wire/ipv6hbh.rs index 4ac965758..27affa8d7 100644 --- a/src/wire/ipv6hbh.rs +++ b/src/wire/ipv6hbh.rs @@ -66,7 +66,7 @@ pub struct Repr<'a> { impl<'a> Repr<'a> { /// Parse an IPv6 Hop-by-Hop Header and return a high-level representation. - pub fn parse(header: &'a Header<&'a T>) -> Result> + pub fn parse(header: &Header<&'a T>) -> Result> where T: AsRef<[u8]> + ?Sized, { diff --git a/src/wire/ipv6routing.rs b/src/wire/ipv6routing.rs index f5f9c4138..be14805ed 100644 --- a/src/wire/ipv6routing.rs +++ b/src/wire/ipv6routing.rs @@ -223,12 +223,14 @@ impl> Header { let data = self.buffer.as_ref(); data[field::PAD] >> 4 } +} +impl<'a, T: AsRef<[u8]> + ?Sized> Header<&'a T> { /// Return the address vector in bytes /// /// # Panics /// This function may panic if this header is not the RPL Source Routing Header routing type. - pub fn addresses(&self) -> &[u8] { + pub fn addresses(&self) -> &'a [u8] { let data = self.buffer.as_ref(); &data[field::ADDRESSES..] } @@ -372,7 +374,7 @@ pub enum Repr<'a> { impl<'a> Repr<'a> { /// Parse an IPv6 Routing Header and return a high-level representation. - pub fn parse(header: &'a Header<&'a T>) -> Result> + pub fn parse(header: &Header<&'a T>) -> Result> where T: AsRef<[u8]> + ?Sized, {