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 12, 2023
1 parent c647a32 commit ca755d7
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 155 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
27 changes: 12 additions & 15 deletions src/iface/interface/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use crate::socket::AnySocket;

use crate::phy::{Medium, TxToken};
use crate::time::Instant;
use crate::wire::{Ipv4Packet as Ipv4PacketWire, *};
use crate::wire::*;

impl InterfaceInner {
pub(super) fn process_ipv4<'a>(
&mut self,
sockets: &mut SocketSet,
meta: PacketMeta,
ipv4_packet: &Ipv4PacketWire<&'a [u8]>,
ipv4_packet: &Ipv4Packet<&'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 @@ -379,7 +379,7 @@ impl InterfaceInner {
}

let mut packet =
Ipv4PacketWire::new_unchecked(&mut tx_buffer[..frag.ipv4.repr.buffer_len()]);
Ipv4Packet::new_unchecked(&mut tx_buffer[..frag.ipv4.repr.buffer_len()]);
frag.ipv4.repr.emit(&mut packet, &caps.checksum);
packet.set_ident(frag.ipv4.ident);
packet.set_more_frags(more_frags);
Expand All @@ -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
Loading

0 comments on commit ca755d7

Please sign in to comment.