Skip to content

Commit

Permalink
iface: rename IpPacket to Packet
Browse files Browse the repository at this point in the history
  • Loading branch information
thvdveld committed Dec 11, 2023
1 parent c647a32 commit e480268
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/iface/interface/ieee802154.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl InterfaceInner {
meta: PacketMeta,
sixlowpan_payload: &'payload [u8],
_fragments: &'output mut FragmentsBuffer,
) -> Option<IpPacket<'output>> {
) -> Option<Packet<'output>> {
let ieee802154_frame = check!(Ieee802154Frame::new_checked(sixlowpan_payload));
let ieee802154_repr = check!(Ieee802154Repr::parse(&ieee802154_frame));

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/iface/interface/igmp.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -231,7 +232,7 @@ impl InterfaceInner {
&mut self,
ipv4_repr: Ipv4Repr,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
let igmp_packet = check!(IgmpPacket::new_checked(ip_payload));
let igmp_repr = check!(IgmpRepr::parse(&igmp_packet));

Expand Down
21 changes: 9 additions & 12 deletions src/iface/interface/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl InterfaceInner {
meta: PacketMeta,
ipv4_packet: &Ipv4PacketWire<&'a [u8]>,
frag: &'a mut FragmentsBuffer,
) -> Option<IpPacket<'a>> {
) -> Option<Packet<'a>> {
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
Expand Down Expand Up @@ -238,7 +238,7 @@ impl InterfaceInner {
_sockets: &mut SocketSet,
ip_repr: IpRepr,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
let icmp_packet = check!(Icmpv4Packet::new_checked(ip_payload));
let icmp_repr = check!(Icmpv4Repr::parse(&icmp_packet, &self.caps.checksum));

Expand Down Expand Up @@ -293,7 +293,7 @@ impl InterfaceInner {
&self,
ipv4_repr: Ipv4Repr,
icmp_repr: Icmpv4Repr<'icmp>,
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
if !self.is_unicast_v4(ipv4_repr.src_addr) {
// Do not send ICMP replies to non-unicast sources
None
Expand All @@ -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),
))
Expand All @@ -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),
))
Expand Down Expand Up @@ -405,13 +405,13 @@ impl InterfaceInner {
&self,
version: IgmpVersion,
group_addr: Ipv4Address,
) -> Option<IpPacket<'any>> {
) -> Option<Packet<'any>> {
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
Expand All @@ -427,13 +427,10 @@ impl InterfaceInner {
}

#[cfg(feature = "proto-igmp")]
pub(super) fn igmp_leave_packet<'any>(
&self,
group_addr: Ipv4Address,
) -> Option<IpPacket<'any>> {
pub(super) fn igmp_leave_packet<'any>(&self, group_addr: Ipv4Address) -> Option<Packet<'any>> {
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,
Expand Down
42 changes: 17 additions & 25 deletions src/iface/interface/ipv6.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +13,7 @@ impl InterfaceInner {
sockets: &mut SocketSet,
meta: PacketMeta,
ipv6_packet: &Ipv6Packet<&'frame [u8]>,
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
let ipv6_repr = check!(Ipv6Repr::parse(ipv6_packet));

if !ipv6_repr.src_addr.is_unicast() {
Expand Down Expand Up @@ -53,7 +49,7 @@ impl InterfaceInner {
nxt_hdr: IpProtocol,
handled_by_raw_socket: bool,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
match nxt_hdr {
IpProtocol::Icmpv6 => self.process_icmpv6(sockets, ipv6_repr.into(), ip_payload),

Expand Down Expand Up @@ -109,7 +105,7 @@ impl InterfaceInner {
_sockets: &mut SocketSet,
ip_repr: IpRepr,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
let icmp_packet = check!(Icmpv6Packet::new_checked(ip_payload));
let icmp_repr = check!(Icmpv6Repr::parse(
&ip_repr.src_addr(),
Expand Down Expand Up @@ -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!(),
},
Expand All @@ -188,7 +180,7 @@ impl InterfaceInner {
&mut self,
ip_repr: Ipv6Repr,
repr: NdiscRepr<'frame>,
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
match repr {
NdiscRepr::NeighborAdvert {
lladdr,
Expand Down Expand Up @@ -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
}
Expand All @@ -253,7 +245,7 @@ impl InterfaceInner {
ipv6_repr: Ipv6Repr,
handled_by_raw_socket: bool,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
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));
Expand Down Expand Up @@ -294,7 +286,7 @@ impl InterfaceInner {
&self,
ipv6_repr: Ipv6Repr,
icmp_repr: Icmpv6Repr<'icmp>,
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
if ipv6_repr.dst_addr.is_unicast() {
let ipv6_reply_repr = Ipv6Repr {
src_addr: ipv6_repr.dst_addr,
Expand All @@ -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),
))
Expand Down
32 changes: 16 additions & 16 deletions src/iface/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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");
Expand All @@ -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")]
Expand All @@ -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!(),
Expand All @@ -814,15 +814,15 @@ 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")]
Socket::Tcp(socket) => socket.dispatch(&mut self.inner, |inner, (ip, tcp)| {
respond(
inner,
PacketMeta::default(),
IpPacket::new(ip, IpPayload::Tcp(tcp)),
Packet::new(ip, IpPayload::Tcp(tcp)),
)
}),
#[cfg(feature = "socket-dhcpv4")]
Expand All @@ -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)),
)
})
}
Expand All @@ -840,7 +840,7 @@ impl Interface {
respond(
inner,
PacketMeta::default(),
IpPacket::new(ip, IpPayload::Udp(udp, dns)),
Packet::new(ip, IpPayload::Udp(udp, dns)),
)
}),
};
Expand Down Expand Up @@ -1174,7 +1174,7 @@ impl InterfaceInner {
meta: PacketMeta,
ip_payload: &'frame [u8],
frag: &'frame mut FragmentsBuffer,
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
match IpVersion::of_packet(ip_payload) {
#[cfg(feature = "proto-ipv4")]
Ok(IpVersion::Ipv4) => {
Expand Down Expand Up @@ -1260,7 +1260,7 @@ impl InterfaceInner {
handled_by_raw_socket: bool,
udp_payload: &'frame [u8],
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
#[cfg(feature = "socket-udp")]
for udp_socket in sockets
.items_mut()
Expand Down Expand Up @@ -1320,7 +1320,7 @@ impl InterfaceInner {
sockets: &mut SocketSet,
ip_repr: IpRepr,
ip_payload: &'frame [u8],
) -> Option<IpPacket<'frame>> {
) -> Option<Packet<'frame>> {
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(
Expand All @@ -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)));
}
}

Expand All @@ -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)))
}
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit e480268

Please sign in to comment.