diff --git a/src/iface/interface/ieee802154.rs b/src/iface/interface/ieee802154.rs index 916bb0435..0feca5ed1 100644 --- a/src/iface/interface/ieee802154.rs +++ b/src/iface/interface/ieee802154.rs @@ -10,7 +10,7 @@ impl InterfaceInner { meta: PacketMeta, sixlowpan_payload: &'payload [u8], _fragments: &'output mut FragmentsBuffer, - ) -> Option> { + ) -> Option> { let ieee802154_frame = check!(Ieee802154Frame::new_checked(sixlowpan_payload)); let ieee802154_repr = check!(Ieee802154Repr::parse(&ieee802154_frame)); @@ -45,7 +45,7 @@ impl InterfaceInner { ll_dst_a: Ieee802154Address, tx_token: Tx, meta: PacketMeta, - packet: IpPacket, + packet: Packet, frag: &mut Fragmenter, ) { let ll_src_a = self.hardware_addr.ieee802154_or_panic(); diff --git a/src/iface/interface/igmp.rs b/src/iface/interface/igmp.rs index 9bf6ad946..f0258c84c 100644 --- a/src/iface/interface/igmp.rs +++ b/src/iface/interface/igmp.rs @@ -1,4 +1,5 @@ -use super::{check, IgmpReportState, Interface, InterfaceInner, IpPacket}; +use super::*; + use crate::phy::{Device, PacketMeta}; use crate::time::{Duration, Instant}; use crate::wire::*; @@ -231,7 +232,7 @@ impl InterfaceInner { &mut self, ipv4_repr: Ipv4Repr, ip_payload: &'frame [u8], - ) -> Option> { + ) -> Option> { let igmp_packet = check!(IgmpPacket::new_checked(ip_payload)); let igmp_repr = check!(IgmpRepr::parse(&igmp_packet)); diff --git a/src/iface/interface/ipv4.rs b/src/iface/interface/ipv4.rs index a881817dd..dea5be3da 100644 --- a/src/iface/interface/ipv4.rs +++ b/src/iface/interface/ipv4.rs @@ -17,7 +17,7 @@ impl InterfaceInner { meta: PacketMeta, ipv4_packet: &Ipv4PacketWire<&'a [u8]>, frag: &'a mut FragmentsBuffer, - ) -> Option> { + ) -> Option> { let ipv4_repr = check!(Ipv4Repr::parse(ipv4_packet, &self.caps.checksum)); if !self.is_unicast_v4(ipv4_repr.src_addr) && !ipv4_repr.src_addr.is_unspecified() { // Discard packets with non-unicast source addresses but allow unspecified @@ -238,7 +238,7 @@ impl InterfaceInner { _sockets: &mut SocketSet, ip_repr: IpRepr, ip_payload: &'frame [u8], - ) -> Option> { + ) -> Option> { let icmp_packet = check!(Icmpv4Packet::new_checked(ip_payload)); let icmp_repr = check!(Icmpv4Repr::parse(&icmp_packet, &self.caps.checksum)); @@ -293,7 +293,7 @@ impl InterfaceInner { &self, ipv4_repr: Ipv4Repr, icmp_repr: Icmpv4Repr<'icmp>, - ) -> Option> { + ) -> Option> { if !self.is_unicast_v4(ipv4_repr.src_addr) { // Do not send ICMP replies to non-unicast sources None @@ -306,7 +306,7 @@ impl InterfaceInner { payload_len: icmp_repr.buffer_len(), hop_limit: 64, }; - Some(IpPacket::new_ipv4( + Some(Packet::new_ipv4( ipv4_reply_repr, IpPayload::Icmpv4(icmp_repr), )) @@ -322,7 +322,7 @@ impl InterfaceInner { payload_len: icmp_repr.buffer_len(), hop_limit: 64, }; - Some(IpPacket::new_ipv4( + Some(Packet::new_ipv4( ipv4_reply_repr, IpPayload::Icmpv4(icmp_repr), )) @@ -405,13 +405,13 @@ impl InterfaceInner { &self, version: IgmpVersion, group_addr: Ipv4Address, - ) -> Option> { + ) -> Option> { let iface_addr = self.ipv4_addr()?; let igmp_repr = IgmpRepr::MembershipReport { group_addr, version, }; - let pkt = IpPacket::new_ipv4( + let pkt = Packet::new_ipv4( Ipv4Repr { src_addr: iface_addr, // Send to the group being reported @@ -427,13 +427,10 @@ impl InterfaceInner { } #[cfg(feature = "proto-igmp")] - pub(super) fn igmp_leave_packet<'any>( - &self, - group_addr: Ipv4Address, - ) -> Option> { + pub(super) fn igmp_leave_packet<'any>(&self, group_addr: Ipv4Address) -> Option> { self.ipv4_addr().map(|iface_addr| { let igmp_repr = IgmpRepr::LeaveGroup { group_addr }; - IpPacket::new_ipv4( + Packet::new_ipv4( Ipv4Repr { src_addr: iface_addr, dst_addr: Ipv4Address::MULTICAST_ALL_ROUTERS, diff --git a/src/iface/interface/ipv6.rs b/src/iface/interface/ipv6.rs index db0f39b45..dcfaffa76 100644 --- a/src/iface/interface/ipv6.rs +++ b/src/iface/interface/ipv6.rs @@ -1,8 +1,4 @@ -use super::check; -use super::icmp_reply_payload_len; -use super::InterfaceInner; -use super::SocketSet; -use super::{IpPacket, IpPayload}; +use super::*; #[cfg(feature = "socket-icmp")] use crate::socket::icmp; @@ -17,7 +13,7 @@ impl InterfaceInner { sockets: &mut SocketSet, meta: PacketMeta, ipv6_packet: &Ipv6Packet<&'frame [u8]>, - ) -> Option> { + ) -> Option> { let ipv6_repr = check!(Ipv6Repr::parse(ipv6_packet)); if !ipv6_repr.src_addr.is_unicast() { @@ -53,7 +49,7 @@ impl InterfaceInner { nxt_hdr: IpProtocol, handled_by_raw_socket: bool, ip_payload: &'frame [u8], - ) -> Option> { + ) -> Option> { match nxt_hdr { IpProtocol::Icmpv6 => self.process_icmpv6(sockets, ipv6_repr.into(), ip_payload), @@ -109,7 +105,7 @@ impl InterfaceInner { _sockets: &mut SocketSet, ip_repr: IpRepr, ip_payload: &'frame [u8], - ) -> Option> { + ) -> Option> { let icmp_packet = check!(Icmpv6Packet::new_checked(ip_payload)); let icmp_repr = check!(Icmpv6Repr::parse( &ip_repr.src_addr(), @@ -157,18 +153,14 @@ impl InterfaceInner { // 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) => { - use crate::phy::Medium; - - match self.caps.medium { - #[cfg(feature = "medium-ethernet")] - Medium::Ethernet => self.process_ndisc(ipv6_repr, repr), - #[cfg(feature = "medium-ieee802154")] - Medium::Ieee802154 => self.process_ndisc(ipv6_repr, repr), - #[cfg(feature = "medium-ip")] - Medium::Ip => None, - } - } + IpRepr::Ipv6(ipv6_repr) => match self.caps.medium { + #[cfg(feature = "medium-ethernet")] + Medium::Ethernet => self.process_ndisc(ipv6_repr, repr), + #[cfg(feature = "medium-ieee802154")] + Medium::Ieee802154 => self.process_ndisc(ipv6_repr, repr), + #[cfg(feature = "medium-ip")] + Medium::Ip => None, + }, #[allow(unreachable_patterns)] _ => unreachable!(), }, @@ -188,7 +180,7 @@ impl InterfaceInner { &mut self, ip_repr: Ipv6Repr, repr: NdiscRepr<'frame>, - ) -> Option> { + ) -> Option> { match repr { NdiscRepr::NeighborAdvert { lladdr, @@ -237,7 +229,7 @@ impl InterfaceInner { hop_limit: 0xff, payload_len: advert.buffer_len(), }; - Some(IpPacket::new_ipv6(ip_repr, IpPayload::Icmpv6(advert))) + Some(Packet::new_ipv6(ip_repr, IpPayload::Icmpv6(advert))) } else { None } @@ -253,7 +245,7 @@ impl InterfaceInner { ipv6_repr: Ipv6Repr, handled_by_raw_socket: bool, ip_payload: &'frame [u8], - ) -> Option> { + ) -> 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)); @@ -294,7 +286,7 @@ impl InterfaceInner { &self, ipv6_repr: Ipv6Repr, icmp_repr: Icmpv6Repr<'icmp>, - ) -> Option> { + ) -> Option> { if ipv6_repr.dst_addr.is_unicast() { let ipv6_reply_repr = Ipv6Repr { src_addr: ipv6_repr.dst_addr, @@ -303,7 +295,7 @@ impl InterfaceInner { payload_len: icmp_repr.buffer_len(), hop_limit: 64, }; - Some(IpPacket::new_ipv6( + Some(Packet::new_ipv6( ipv6_reply_repr, IpPayload::Icmpv6(icmp_repr), )) diff --git a/src/iface/interface/mod.rs b/src/iface/interface/mod.rs index 1af458215..54c6d0935 100644 --- a/src/iface/interface/mod.rs +++ b/src/iface/interface/mod.rs @@ -23,7 +23,7 @@ mod igmp; #[cfg(feature = "proto-igmp")] pub use igmp::MulticastError; -use super::ip_packet::*; +use super::packet::*; use core::result::Result; use heapless::{LinearMap, Vec}; @@ -767,7 +767,7 @@ impl Interface { } let mut neighbor_addr = None; - let mut respond = |inner: &mut InterfaceInner, meta: PacketMeta, response: IpPacket| { + let mut respond = |inner: &mut InterfaceInner, meta: PacketMeta, response: Packet| { neighbor_addr = Some(response.ip_repr().dst_addr()); let t = device.transmit(inner.now).ok_or_else(|| { net_debug!("failed to transmit IP: device exhausted"); @@ -789,7 +789,7 @@ impl Interface { respond( inner, PacketMeta::default(), - IpPacket::new(ip, IpPayload::Raw(raw)), + Packet::new(ip, IpPayload::Raw(raw)), ) }), #[cfg(feature = "socket-icmp")] @@ -799,13 +799,13 @@ impl Interface { (IpRepr::Ipv4(ipv4_repr), IcmpRepr::Ipv4(icmpv4_repr)) => respond( inner, PacketMeta::default(), - IpPacket::new_ipv4(ipv4_repr, IpPayload::Icmpv4(icmpv4_repr)), + Packet::new_ipv4(ipv4_repr, IpPayload::Icmpv4(icmpv4_repr)), ), #[cfg(feature = "proto-ipv6")] (IpRepr::Ipv6(ipv6_repr), IcmpRepr::Ipv6(icmpv6_repr)) => respond( inner, PacketMeta::default(), - IpPacket::new_ipv6(ipv6_repr, IpPayload::Icmpv6(icmpv6_repr)), + Packet::new_ipv6(ipv6_repr, IpPayload::Icmpv6(icmpv6_repr)), ), #[allow(unreachable_patterns)] _ => unreachable!(), @@ -814,7 +814,7 @@ impl Interface { #[cfg(feature = "socket-udp")] Socket::Udp(socket) => { socket.dispatch(&mut self.inner, |inner, meta, (ip, udp, payload)| { - respond(inner, meta, IpPacket::new(ip, IpPayload::Udp(udp, payload))) + respond(inner, meta, Packet::new(ip, IpPayload::Udp(udp, payload))) }) } #[cfg(feature = "socket-tcp")] @@ -822,7 +822,7 @@ impl Interface { respond( inner, PacketMeta::default(), - IpPacket::new(ip, IpPayload::Tcp(tcp)), + Packet::new(ip, IpPayload::Tcp(tcp)), ) }), #[cfg(feature = "socket-dhcpv4")] @@ -831,7 +831,7 @@ impl Interface { respond( inner, PacketMeta::default(), - IpPacket::new_ipv4(ip, IpPayload::Dhcpv4(udp, dhcp)), + Packet::new_ipv4(ip, IpPayload::Dhcpv4(udp, dhcp)), ) }) } @@ -840,7 +840,7 @@ impl Interface { respond( inner, PacketMeta::default(), - IpPacket::new(ip, IpPayload::Udp(udp, dns)), + Packet::new(ip, IpPayload::Udp(udp, dns)), ) }), }; @@ -1174,7 +1174,7 @@ impl InterfaceInner { meta: PacketMeta, ip_payload: &'frame [u8], frag: &'frame mut FragmentsBuffer, - ) -> Option> { + ) -> Option> { match IpVersion::of_packet(ip_payload) { #[cfg(feature = "proto-ipv4")] Ok(IpVersion::Ipv4) => { @@ -1260,7 +1260,7 @@ impl InterfaceInner { handled_by_raw_socket: bool, udp_payload: &'frame [u8], ip_payload: &'frame [u8], - ) -> Option> { + ) -> Option> { #[cfg(feature = "socket-udp")] for udp_socket in sockets .items_mut() @@ -1320,7 +1320,7 @@ impl InterfaceInner { sockets: &mut SocketSet, ip_repr: IpRepr, ip_payload: &'frame [u8], - ) -> Option> { + ) -> 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( @@ -1337,7 +1337,7 @@ impl InterfaceInner { if tcp_socket.accepts(self, &ip_repr, &tcp_repr) { return tcp_socket .process(self, &ip_repr, &tcp_repr) - .map(|(ip, tcp)| IpPacket::new(ip, IpPayload::Tcp(tcp))); + .map(|(ip, tcp)| Packet::new(ip, IpPayload::Tcp(tcp))); } } @@ -1351,7 +1351,7 @@ impl InterfaceInner { } 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); - Some(IpPacket::new(ip, IpPayload::Tcp(tcp))) + Some(Packet::new(ip, IpPayload::Tcp(tcp))) } } @@ -1535,7 +1535,7 @@ impl InterfaceInner { lladdr: Some(self.hardware_addr.into()), }); - let packet = IpPacket::new_ipv6( + let packet = Packet::new_ipv6( Ipv6Repr { src_addr, dst_addr: dst_addr.solicited_node(), @@ -1574,7 +1574,7 @@ impl InterfaceInner { // the feature set that is used. #[allow(unused_mut)] mut tx_token: Tx, meta: PacketMeta, - packet: IpPacket, + packet: Packet, frag: &mut Fragmenter, ) -> Result<(), DispatchError> { let mut ip_repr = packet.ip_repr(); diff --git a/src/iface/interface/sixlowpan.rs b/src/iface/interface/sixlowpan.rs index 4dd0282ed..9ee81d3b8 100644 --- a/src/iface/interface/sixlowpan.rs +++ b/src/iface/interface/sixlowpan.rs @@ -1,6 +1,5 @@ use super::*; -use crate::iface::ip_packet::Ipv6Packet; use crate::phy::ChecksumCapabilities; use crate::wire::{Ipv6Packet as Ipv6PacketWire, *}; @@ -16,7 +15,7 @@ impl InterfaceInner { ieee802154_repr: &Ieee802154Repr, payload: &'payload [u8], f: &'output mut FragmentsBuffer, - ) -> Option> { + ) -> Option> { let payload = match check!(SixlowpanPacket::dispatch(payload)) { #[cfg(not(feature = "proto-sixlowpan-fragmentation"))] SixlowpanPacket::FragmentHeader => { @@ -327,14 +326,14 @@ impl InterfaceInner { &mut self, mut tx_token: Tx, meta: PacketMeta, - packet: IpPacket, + packet: Packet, ieee_repr: Ieee802154Repr, frag: &mut Fragmenter, ) { let packet = match packet { #[cfg(feature = "proto-ipv4")] - IpPacket::Ipv4(_) => unreachable!(), - IpPacket::Ipv6(packet) => packet, + Packet::Ipv4(_) => unreachable!(), + Packet::Ipv6(packet) => packet, }; // First we calculate the size we are going to need. If the size is bigger than the MTU, @@ -454,7 +453,7 @@ impl InterfaceInner { fn ipv6_to_sixlowpan( checksum_caps: &ChecksumCapabilities, - mut packet: Ipv6Packet, + mut packet: PacketV6, ieee_repr: &Ieee802154Repr, mut buffer: &mut [u8], ) { @@ -589,7 +588,7 @@ impl InterfaceInner { /// - uncompressed header size: the size of the headers that are not compressed /// They are returned as a tuple in the same order. fn compressed_packet_size( - packet: &Ipv6Packet, + packet: &PacketV6, ieee_repr: &Ieee802154Repr, ) -> (usize, usize, usize) { let last_header = packet.payload.as_sixlowpan_next_header(); @@ -785,7 +784,7 @@ mod tests { src_addr: Some(Ieee802154Address::Extended([0, 3, 0, 3, 0, 3, 0, 3])), }; - let mut ip_packet = Ipv6Packet { + let mut ip_packet = PacketV6 { header: Ipv6Repr { src_addr: Ipv6Address::from_bytes(&[ 253, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 3, 0, 3, 0, 3, @@ -868,7 +867,7 @@ mod tests { })) .unwrap(); - let mut ip_packet = Ipv6Packet { + let mut ip_packet = PacketV6 { header: Ipv6Repr { src_addr: addr, dst_addr: parent_address, diff --git a/src/iface/interface/tests/ipv4.rs b/src/iface/interface/tests/ipv4.rs index b5c167a40..0e10efca4 100644 --- a/src/iface/interface/tests/ipv4.rs +++ b/src/iface/interface/tests/ipv4.rs @@ -76,7 +76,7 @@ fn test_icmp_error_no_payload(#[case] medium: Medium) { data: &NO_BYTES, }; - let expected_repr = IpPacket::new_ipv4( + let expected_repr = Packet::new_ipv4( Ipv4Repr { src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]), dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]), @@ -222,7 +222,7 @@ fn test_icmp_error_port_unreachable(#[case] medium: Medium) { }, data, }; - let expected_repr = IpPacket::new_ipv4( + let expected_repr = Packet::new_ipv4( Ipv4Repr { src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]), dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]), @@ -341,7 +341,7 @@ fn test_handle_ipv4_broadcast(#[case] medium: Medium) { payload_len: expected_icmpv4_repr.buffer_len(), }; let expected_packet = - IpPacket::new_ipv4(expected_ipv4_repr, IpPayload::Icmpv4(expected_icmpv4_repr)); + Packet::new_ipv4(expected_ipv4_repr, IpPayload::Icmpv4(expected_icmpv4_repr)); assert_eq!( iface.inner.process_ipv4( @@ -592,10 +592,7 @@ fn test_icmpv4_socket(#[case] medium: Medium) { }; assert_eq!( iface.inner.process_icmpv4(&mut sockets, ip_repr, icmp_data), - Some(IpPacket::new_ipv4( - ipv4_reply, - IpPayload::Icmpv4(echo_reply) - )) + Some(Packet::new_ipv4(ipv4_reply, IpPayload::Icmpv4(echo_reply))) ); let socket = sockets.get_mut::(socket_handle); @@ -963,7 +960,7 @@ fn test_icmp_reply_size(#[case] medium: Medium) { &vec![0x2a; MAX_PAYLOAD_LEN], payload, ), - Some(IpPacket::new_ipv4( + Some(Packet::new_ipv4( expected_ip_repr, IpPayload::Icmpv4(expected_icmp_repr) )) diff --git a/src/iface/interface/tests/ipv6.rs b/src/iface/interface/tests/ipv6.rs index 4867711b5..79f70ff34 100644 --- a/src/iface/interface/tests/ipv6.rs +++ b/src/iface/interface/tests/ipv6.rs @@ -1,6 +1,6 @@ use super::*; -fn parse_ipv6(data: &[u8]) -> crate::wire::Result> { +fn parse_ipv6(data: &[u8]) -> crate::wire::Result> { let ipv6_header = Ipv6PacketWire::new_checked(data)?; let ipv6 = Ipv6Repr::parse(&ipv6_header)?; @@ -21,7 +21,7 @@ fn parse_ipv6(data: &[u8]) -> crate::wire::Result> { &Icmpv6Packet::new_checked(ipv6_header.payload())?, &Default::default(), )?; - Ok(IpPacket::new_ipv6(ipv6, IpPayload::Icmpv6(icmp))) + Ok(Packet::new_ipv6(ipv6, IpPayload::Icmpv6(icmp))) } IpProtocol::Ipv6NoNxt => todo!(), IpProtocol::Ipv6Opts => todo!(), @@ -78,7 +78,7 @@ fn hop_by_hop_skip_with_icmp(#[case] medium: Medium) { 0x0, 0x2a, 0x1, 0xa4, 0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x49, 0x70, 0x73, 0x75, 0x6d, ]; - let response = Some(IpPacket::new_ipv6( + let response = Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), @@ -156,7 +156,7 @@ fn imcp_empty_echo_request(#[case] medium: Medium) { assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -172,7 +172,7 @@ fn imcp_empty_echo_request(#[case] medium: Medium) { )) ); - let response = Some(IpPacket::new_ipv6( + let response = Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), @@ -216,7 +216,7 @@ fn icmp_echo_request(#[case] medium: Medium) { assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -232,7 +232,7 @@ fn icmp_echo_request(#[case] medium: Medium) { )) ); - let response = Some(IpPacket::new_ipv6( + let response = Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), @@ -276,7 +276,7 @@ fn icmp_echo_reply_as_input(#[case] medium: Medium) { assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -350,7 +350,7 @@ fn unknown_proto(#[case] medium: Medium) { 0x0, 0x0, 0x0, 0x0, 0x1, ]; - let response = Some(IpPacket::new_ipv6( + let response = Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), @@ -398,7 +398,7 @@ fn ndsic_neighbor_advertisement_ethernet(#[case] medium: Medium) { assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -452,7 +452,7 @@ fn ndsic_neighbor_advertisement_ethernet_multicast_addr(#[case] medium: Medium) assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -506,7 +506,7 @@ fn ndsic_neighbor_advertisement_ieee802154(#[case] medium: Medium) { assert_eq!( parse_ipv6(&data), - Ok(IpPacket::new_ipv6( + Ok(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0002]), dst_addr: Ipv6Address::from_parts(&[0xfdbe, 0, 0, 0, 0, 0, 0, 0x0001]), @@ -605,7 +605,7 @@ fn test_handle_valid_ndisc_request(#[case] medium: Medium) { frame.into_inner(), &mut iface.fragments ), - Some(EthernetPacket::Ip(IpPacket::new_ipv6( + Some(EthernetPacket::Ip(Packet::new_ipv6( ipv6_expected, IpPayload::Icmpv6(icmpv6_expected) ))) @@ -729,7 +729,7 @@ fn test_icmp_reply_size(#[case] medium: Medium) { &vec![0x2a; MAX_PAYLOAD_LEN], payload, ), - Some(IpPacket::new_ipv6( + Some(Packet::new_ipv6( expected_ip_repr, IpPayload::Icmpv6(expected_icmp_repr) )) diff --git a/src/iface/interface/tests/mod.rs b/src/iface/interface/tests/mod.rs index 5dbbbb0c5..b4b4416b0 100644 --- a/src/iface/interface/tests/mod.rs +++ b/src/iface/interface/tests/mod.rs @@ -151,8 +151,6 @@ fn test_handle_udp_broadcast( #[test] #[cfg(all(feature = "medium-ip", feature = "socket-tcp", feature = "proto-ipv6"))] pub fn tcp_not_accepted() { - use crate::iface::ip_packet::{IpPacket, IpPayload, Ipv6Packet}; - let (mut iface, mut sockets, _) = setup(Medium::Ip); let tcp = TcpRepr { src_port: 4242, @@ -189,23 +187,15 @@ pub fn tcp_not_accepted() { }), &tcp_bytes, ), - Some(IpPacket::Ipv6(Ipv6Packet { - header: Ipv6Repr { + Some(Packet::new_ipv6( + Ipv6Repr { src_addr: Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1), dst_addr: Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 2), next_header: IpProtocol::Tcp, payload_len: tcp.buffer_len(), hop_limit: 64, }, - - #[cfg(feature = "proto-ipv6-hbh")] - hop_by_hop: None, - #[cfg(feature = "proto-ipv6-fragmentation")] - fragment: None, - #[cfg(feature = "proto-ipv6-routing")] - routing: None, - - payload: IpPayload::Tcp(TcpRepr { + IpPayload::Tcp(TcpRepr { src_port: 4243, dst_port: 4242, control: TcpControl::Rst, @@ -218,7 +208,7 @@ pub fn tcp_not_accepted() { sack_ranges: [None, None, None], payload: &[], }) - })), + )) ); // Unspecified destination address. tcp.emit( diff --git a/src/iface/interface/tests/sixlowpan.rs b/src/iface/interface/tests/sixlowpan.rs index 229c75b44..62cba96fe 100644 --- a/src/iface/interface/tests/sixlowpan.rs +++ b/src/iface/interface/tests/sixlowpan.rs @@ -38,7 +38,7 @@ fn icmp_echo_request(#[case] medium: Medium) { 0x37, ]; - let response = Some(IpPacket::new_ipv6( + let response = Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::from_parts(&[0xfe80, 0, 0, 0, 0x180b, 0x4242, 0x4242, 0x4242]), dst_addr: Ipv6Address::from_parts(&[0xfe80, 0, 0, 0, 0x241c, 0x2957, 0x34a6, 0x3a62]), @@ -190,7 +190,7 @@ fn test_echo_request_sixlowpan_128_bytes() { assert_eq!( result, - Some(IpPacket::new_ipv6( + Some(Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address([ 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x92, 0xfc, 0x48, 0xc2, 0xa4, 0x41, @@ -362,7 +362,7 @@ In at rhoncus tortor. Cras blandit tellus diam, varius vestibulum nibh commodo n Ieee802154Address::default(), tx_token, PacketMeta::default(), - IpPacket::new_ipv6( + Packet::new_ipv6( Ipv6Repr { src_addr: Ipv6Address::default(), dst_addr: Ipv6Address::default(), diff --git a/src/iface/mod.rs b/src/iface/mod.rs index 505d3e33b..c421382a3 100644 --- a/src/iface/mod.rs +++ b/src/iface/mod.rs @@ -15,7 +15,7 @@ mod rpl; mod socket_meta; mod socket_set; -mod ip_packet; +mod packet; #[cfg(feature = "proto-igmp")] pub use self::interface::MulticastError; diff --git a/src/iface/ip_packet.rs b/src/iface/packet.rs similarity index 94% rename from src/iface/ip_packet.rs rename to src/iface/packet.rs index 8de72aa1b..4fdb19d77 100644 --- a/src/iface/ip_packet.rs +++ b/src/iface/packet.rs @@ -8,19 +8,19 @@ use crate::wire::*; pub(crate) enum EthernetPacket<'a> { #[cfg(feature = "proto-ipv4")] Arp(ArpRepr), - Ip(IpPacket<'a>), + Ip(Packet<'a>), } #[derive(Debug, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum IpPacket<'p> { +pub(crate) enum Packet<'p> { #[cfg(feature = "proto-ipv4")] - Ipv4(Ipv4Packet<'p>), + Ipv4(PacketV4<'p>), #[cfg(feature = "proto-ipv6")] - Ipv6(Ipv6Packet<'p>), + Ipv6(PacketV6<'p>), } -impl<'p> IpPacket<'p> { +impl<'p> Packet<'p> { pub(crate) fn new(ip_repr: IpRepr, payload: IpPayload<'p>) -> Self { match ip_repr { #[cfg(feature = "proto-ipv4")] @@ -32,7 +32,7 @@ impl<'p> IpPacket<'p> { #[cfg(feature = "proto-ipv4")] pub(crate) fn new_ipv4(ip_repr: Ipv4Repr, payload: IpPayload<'p>) -> Self { - Self::Ipv4(Ipv4Packet { + Self::Ipv4(PacketV4 { header: ip_repr, payload, }) @@ -40,7 +40,7 @@ impl<'p> IpPacket<'p> { #[cfg(feature = "proto-ipv6")] pub(crate) fn new_ipv6(ip_repr: Ipv6Repr, payload: IpPayload<'p>) -> Self { - Self::Ipv6(Ipv6Packet { + Self::Ipv6(PacketV6 { header: ip_repr, #[cfg(feature = "proto-ipv6-hbh")] hop_by_hop: None, @@ -55,18 +55,18 @@ impl<'p> IpPacket<'p> { pub(crate) fn ip_repr(&self) -> IpRepr { match self { #[cfg(feature = "proto-ipv4")] - IpPacket::Ipv4(p) => IpRepr::Ipv4(p.header), + Packet::Ipv4(p) => IpRepr::Ipv4(p.header), #[cfg(feature = "proto-ipv6")] - IpPacket::Ipv6(p) => IpRepr::Ipv6(p.header), + Packet::Ipv6(p) => IpRepr::Ipv6(p.header), } } pub(crate) fn payload(&self) -> &IpPayload<'p> { match self { #[cfg(feature = "proto-ipv4")] - IpPacket::Ipv4(p) => &p.payload, + Packet::Ipv4(p) => &p.payload, #[cfg(feature = "proto-ipv6")] - IpPacket::Ipv6(p) => &p.payload, + Packet::Ipv6(p) => &p.payload, } } @@ -144,7 +144,7 @@ impl<'p> IpPacket<'p> { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg(feature = "proto-ipv4")] -pub(crate) struct Ipv4Packet<'p> { +pub(crate) struct PacketV4<'p> { header: Ipv4Repr, payload: IpPayload<'p>, } @@ -152,7 +152,7 @@ pub(crate) struct Ipv4Packet<'p> { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg(feature = "proto-ipv6")] -pub(crate) struct Ipv6Packet<'p> { +pub(crate) struct PacketV6<'p> { pub(crate) header: Ipv6Repr, #[cfg(feature = "proto-ipv6-hbh")] pub(crate) hop_by_hop: Option>,