1
1
// SPDX-License-Identifier: Apache-2.0
2
2
// Copyright Open Network Fabric Authors
3
3
4
- //! Packet definition
4
+ //! Definition of [`Headers`] and related methods and types.
5
5
#![ allow( missing_docs, clippy:: pedantic) ] // temporary
6
6
7
7
use crate :: eth:: ethtype:: EthType ;
@@ -28,7 +28,7 @@ const MAX_NET_EXTENSIONS: usize = 2;
28
28
29
29
// TODO: remove `pub` from all fields
30
30
#[ derive( Debug ) ]
31
- pub struct Packet {
31
+ pub struct Headers {
32
32
pub eth : Eth ,
33
33
pub vlan : ArrayVec < Vlan , MAX_VLANS > ,
34
34
pub net : Option < Net > ,
@@ -128,7 +128,7 @@ impl ParsePayload for Header {
128
128
ext. parse_payload_with ( & ipv6. next_header ( ) , cursor)
129
129
. map ( Header :: from)
130
130
} else {
131
- debug ! ( "ipv6 extension header outside ipv6 packet " ) ;
131
+ debug ! ( "ipv6 extension header outside ipv6 header " ) ;
132
132
None
133
133
}
134
134
}
@@ -138,14 +138,14 @@ impl ParsePayload for Header {
138
138
}
139
139
}
140
140
141
- impl Parse for Packet {
141
+ impl Parse for Headers {
142
142
type Error = EthError ;
143
143
144
144
fn parse ( buf : & [ u8 ] ) -> Result < ( Self , NonZero < u16 > ) , ParseError < Self :: Error > > {
145
145
let mut cursor =
146
146
Reader :: new ( buf) . map_err ( |IllegalBufferLength ( len) | ParseError :: BufferTooLong ( len) ) ?;
147
147
let ( eth, _) = cursor. parse :: < Eth > ( ) ?;
148
- let mut this = Packet {
148
+ let mut this = Headers {
149
149
eth : eth. clone ( ) ,
150
150
net : None ,
151
151
transport : None ,
@@ -204,7 +204,7 @@ impl Parse for Packet {
204
204
}
205
205
}
206
206
207
- impl DeParse for Packet {
207
+ impl DeParse for Headers {
208
208
type Error = ( ) ;
209
209
210
210
fn size ( & self ) -> NonZero < u16 > {
@@ -292,13 +292,13 @@ impl DeParse for Packet {
292
292
}
293
293
294
294
#[ 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})" ) ]
296
296
pub struct TooManyVlans ;
297
297
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 {
302
302
eth,
303
303
vlan : ArrayVec :: default ( ) ,
304
304
net : None ,
@@ -318,12 +318,12 @@ impl Packet {
318
318
///
319
319
/// # Safety:
320
320
///
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
322
322
/// which does not align with the next header below it.
323
323
///
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`])
327
327
#[ allow( unsafe_code) ]
328
328
#[ allow( dead_code) ]
329
329
unsafe fn push_vlan_header_unchecked ( & mut self , vlan : Vlan ) -> Result < ( ) , TooManyVlans > {
@@ -335,7 +335,7 @@ impl Packet {
335
335
}
336
336
}
337
337
338
- /// Push a vlan header onto the VLAN stack of this packet .
338
+ /// Push a vlan header onto the VLAN stack of this [`Headers`] .
339
339
///
340
340
/// This method will ensure that the `eth` field has its [`EthType`] adjusted to
341
341
/// [`EthType::VLAN`] if there are no [`Vlan`]s on the stack at the time this method was called.
@@ -355,9 +355,9 @@ impl Packet {
355
355
/// Returns [`None`] if no [`Vlan`]s are on the stack.
356
356
///
357
357
/// If `Some` is returned, the popped [`Vlan`]s ethtype is assigned to the `eth` header to
358
- /// preserve packet structure.
358
+ /// preserve structure.
359
359
///
360
- /// If `None` is returned, the `Packet` is not modified.
360
+ /// If `None` is returned, the [`Headers`] is not modified.
361
361
pub fn pop_vlan ( & mut self ) -> Option < Vlan > {
362
362
match self . vlan . pop ( ) {
363
363
None => None ,
0 commit comments