Skip to content

Commit 83e9f5e

Browse files
daniel-nolandmvachhar
authored andcommitted
fix(net)!: rename Packet to Headers
BREAKING_CHANGE: the net `Packet` struct is now named `Headers` This is more accurate to the core function of the struct. It also opens up the module name `Packet` to serve the actual function of a packet (rather than just header manipulation). Signed-off-by: Daniel Noland <daniel@githedgehog.com>
1 parent a3508f5 commit 83e9f5e

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

dataplane/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use dpdk::mem::{Pool, PoolConfig, PoolParams, RteAllocator};
1313
use dpdk::queue::rx::{RxQueueConfig, RxQueueIndex};
1414
use dpdk::queue::tx::{TxQueueConfig, TxQueueIndex};
1515
use dpdk::{dev, eal, socket};
16-
use net::headers::Packet;
16+
use net::headers::Headers;
1717
use net::parse::{DeParse, Parse};
1818
use tracing::{info, trace, warn};
1919

@@ -114,7 +114,7 @@ fn start_rte_workers(devices: &Vec<Dev>) {
114114
loop {
115115
let mbufs = rx_queue.receive();
116116
let pkts = mbufs.filter_map(|mut mbuf| {
117-
let packet_result = Packet::parse(mbuf.raw_data_mut());
117+
let packet_result = Headers::parse(mbuf.raw_data_mut());
118118
let packet = match packet_result {
119119
Ok(packet) => packet.0,
120120
Err(e) => {

dataplane/src/pipeline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use std::error::Error;
1515

1616
use dpdk::mem::Mbuf;
17-
use net::headers::Packet;
17+
use net::headers::Headers;
1818
use net::vxlan::Vni;
1919

2020
use crate::config::Config;
@@ -26,11 +26,11 @@ pub struct Metadata {
2626
}
2727

2828
pub struct MetaPacket {
29-
pub packet: Packet,
29+
pub packet: Headers,
3030
#[allow(dead_code)]
3131
pub metadata: Metadata,
3232
#[allow(dead_code)]
33-
pub outer_packet: Option<Box<Packet>>,
33+
pub outer_packet: Option<Box<Headers>>,
3434
pub mbuf: Mbuf,
3535
}
3636

@@ -140,7 +140,7 @@ mod test {
140140
use net::eth::ethertype::EthType;
141141
use net::eth::mac::{DestinationMac, Mac, SourceMac};
142142
use net::eth::Eth;
143-
use net::headers::Packet;
143+
use net::headers::Headers;
144144

145145
#[test]
146146
fn test_passthrough_process() {
@@ -151,7 +151,7 @@ mod test {
151151
let src_mac = SourceMac::new(Mac::from([0x00, 0x00, 0x00, 0x00, 0x00, 0x01])).unwrap();
152152
let dst_mac = DestinationMac::new(Mac::from([0x00, 0x00, 0x00, 0x00, 0x00, 0x02])).unwrap();
153153
let test_packet = MetaPacket {
154-
packet: Packet::new(Eth::new(src_mac, dst_mac, EthType::IPV4)),
154+
packet: Headers::new(Eth::new(src_mac, dst_mac, EthType::IPV4)),
155155
metadata: Metadata { vni: None },
156156
outer_packet: None,
157157
// Temporary mbuf fake, need to have a proper mockable interface

net/src/eth/mac.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl DestinationMac {
210210

211211
/// Errors which can occur while setting the source [`Mac`] of a [`Packet`]
212212
///
213-
/// [`Packet`]: crate::headers::Packet
213+
/// [`Packet`]: crate::headers::Headers
214214
#[derive(Debug, thiserror::Error)]
215215
pub enum SourceMacAddressError {
216216
/// Multicast [`Mac`]s are not legal as a source [`Mac`]
@@ -223,7 +223,7 @@ pub enum SourceMacAddressError {
223223

224224
/// Errors which can occur while setting the destination [`Mac`] of a [`Packet`]
225225
///
226-
/// [`Packet`]: crate::headers::Packet
226+
/// [`Packet`]: crate::headers::Headers
227227
#[derive(Debug, thiserror::Error)]
228228
pub enum DestinationMacAddressError {
229229
/// Zero is not a legal source

net/src/headers.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Open Network Fabric Authors
33

4-
//! Packet definition
4+
//! Definition of [`Headers`] and related methods and types.
55
#![allow(missing_docs, clippy::pedantic)] // temporary
66

77
use crate::eth::ethtype::EthType;
@@ -28,7 +28,7 @@ const MAX_NET_EXTENSIONS: usize = 2;
2828

2929
// TODO: remove `pub` from all fields
3030
#[derive(Debug)]
31-
pub struct Packet {
31+
pub struct Headers {
3232
pub eth: Eth,
3333
pub vlan: ArrayVec<Vlan, MAX_VLANS>,
3434
pub net: Option<Net>,
@@ -128,7 +128,7 @@ impl ParsePayload for Header {
128128
ext.parse_payload_with(&ipv6.next_header(), cursor)
129129
.map(Header::from)
130130
} else {
131-
debug!("ipv6 extension header outside ipv6 packet");
131+
debug!("ipv6 extension header outside ipv6 header");
132132
None
133133
}
134134
}
@@ -138,14 +138,14 @@ impl ParsePayload for Header {
138138
}
139139
}
140140

141-
impl Parse for Packet {
141+
impl Parse for Headers {
142142
type Error = EthError;
143143

144144
fn parse(buf: &[u8]) -> Result<(Self, NonZero<u16>), ParseError<Self::Error>> {
145145
let mut cursor =
146146
Reader::new(buf).map_err(|IllegalBufferLength(len)| ParseError::BufferTooLong(len))?;
147147
let (eth, _) = cursor.parse::<Eth>()?;
148-
let mut this = Packet {
148+
let mut this = Headers {
149149
eth: eth.clone(),
150150
net: None,
151151
transport: None,
@@ -204,7 +204,7 @@ impl Parse for Packet {
204204
}
205205
}
206206

207-
impl DeParse for Packet {
207+
impl DeParse for Headers {
208208
type Error = ();
209209

210210
fn size(&self) -> NonZero<u16> {
@@ -292,13 +292,13 @@ impl DeParse for Packet {
292292
}
293293

294294
#[derive(Debug, thiserror::Error)]
295-
#[error("Packet already has as many VLAN headers as parser can support (max is {MAX_VLANS})")]
295+
#[error("Header already has as many VLAN headers as parser can support (max is {MAX_VLANS})")]
296296
pub struct TooManyVlans;
297297

298-
impl Packet {
299-
/// Create a new packet with the supplied `Eth` header.
300-
pub fn new(eth: Eth) -> Packet {
301-
Packet {
298+
impl Headers {
299+
/// Create a new [`Headers`] with the supplied `Eth` header.
300+
pub fn new(eth: Eth) -> Headers {
301+
Headers {
302302
eth,
303303
vlan: ArrayVec::default(),
304304
net: None,
@@ -318,12 +318,12 @@ impl Packet {
318318
///
319319
/// # Safety:
320320
///
321-
/// This method will create an invalid packet if the header you push has an _inner_ ethtype
321+
/// This method will create an invalid [`Headers`] if the header you push has an _inner_ ethtype
322322
/// which does not align with the next header below it.
323323
///
324-
/// This method will create an invalid packet if the _outer_ ethtype (i.e., the ethtype of the
325-
/// `Eth` header or prior [`Vlan`] in the stack) is not some flavor of `Vlan` ethtype (e.g.
326-
/// [`EthType::VLAN`] or [`EthType::VLAN_QINQ`])
324+
/// This method will create an invalid [`Headers`] if the _outer_ ethtype (i.e., the ethtype of
325+
/// the [`Eth`] header or prior [`Vlan`] in the stack) is not some flavor of `Vlan` ethtype
326+
/// (e.g. [`EthType::VLAN`] or [`EthType::VLAN_QINQ`])
327327
#[allow(unsafe_code)]
328328
#[allow(dead_code)]
329329
unsafe fn push_vlan_header_unchecked(&mut self, vlan: Vlan) -> Result<(), TooManyVlans> {
@@ -335,7 +335,7 @@ impl Packet {
335335
}
336336
}
337337

338-
/// Push a vlan header onto the VLAN stack of this packet.
338+
/// Push a vlan header onto the VLAN stack of this [`Headers`].
339339
///
340340
/// This method will ensure that the `eth` field has its [`EthType`] adjusted to
341341
/// [`EthType::VLAN`] if there are no [`Vlan`]s on the stack at the time this method was called.
@@ -355,9 +355,9 @@ impl Packet {
355355
/// Returns [`None`] if no [`Vlan`]s are on the stack.
356356
///
357357
/// If `Some` is returned, the popped [`Vlan`]s ethtype is assigned to the `eth` header to
358-
/// preserve packet structure.
358+
/// preserve structure.
359359
///
360-
/// If `None` is returned, the `Packet` is not modified.
360+
/// If `None` is returned, the [`Headers`] is not modified.
361361
pub fn pop_vlan(&mut self) -> Option<Vlan> {
362362
match self.vlan.pop() {
363363
None => None,

0 commit comments

Comments
 (0)