Skip to content

Commit 1ec362b

Browse files
committed
Clarify how to back a PacketAssembler
1 parent 01db5e0 commit 1ec362b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/iface/fragmentation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ use crate::Error;
1010
use crate::Result;
1111

1212
/// Holds different fragments of one packet, used for assembling fragmented packets.
13+
///
14+
/// The buffer used for the `PacketAssembler` should either be dynamically sized (ex: Vec<u8>)
15+
/// or should be statically allocated based upon the MTU of the type of packet being
16+
/// assembled (ex: 1280 for a IPv6 frame).
1317
#[derive(Debug)]
1418
pub struct PacketAssembler<'a> {
1519
buffer: ManagedSlice<'a, u8>,

src/iface/interface.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,16 @@ impl<'a> InterfaceInner<'a> {
16601660
// This information is the total size of the packet when it is fully assmbled.
16611661
// We also pass the header size, since this is needed when other fragments
16621662
// (other than the first one) are added.
1663-
check!(check!(fragments.reserve_with_key(&key)).start(
1663+
let frag_slot = match fragments.reserve_with_key(&key) {
1664+
Ok(frag) => frag,
1665+
Err(Error::PacketAssemblerSetFull) => {
1666+
net_debug!("No available packet assembler for fragmented packet");
1667+
return Default::default();
1668+
}
1669+
e => check!(e),
1670+
};
1671+
1672+
check!(frag_slot.start(
16641673
Some(
16651674
frag.datagram_size() as usize - uncompressed_header_size
16661675
+ compressed_header_size

0 commit comments

Comments
 (0)