Support for cloning packets whose underlying data is a `B: ByteSlice`.
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
**What is the name of your project?**
Fuchsia netstack3
**Please provide a link to your project (GitHub repository, crates.io page, etc).**
https://cs.opensource.google/fuchsia/fuchsia/+/main:src/connectivity/network/netstack3/
**What features would you like from zerocopy?**
Netstack3 uses the [packet-formats](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/connectivity/lib/packet-formats/) crate for parsing of various packet types, including IP Packets. For example, `Ipv4Packet`, is a known-to-be-valid IPv4 packet backed by an underlying byte slice. There are instances in Netstack3 where an IP packet must be multiplexed, such as supporting multicast routing, where a received IP packet may need to be forwarded out of multiple interfaces. Each send needs the ability to mutate the packet (E.g. for things like Network Address Translation), so I'd like each send to get their own unique copy of the original packet.
I can do this today with something similar to:
```
let packet: Ipv4Packet<&mut [u8]> = {...};
let copy_of_data = packet.to_vec();
let new_buffer = packet::serialize::Buf::new(copy_of_data.as_mut(), ..);
let new_packet: Ipv4Packet<&mut [u8]> = packet::serialize::ParseBufferMut::parse_mut(new_buffer);
```
However, the parse on the final line is wasted work: we already know the bytes encompass a valid `Ipv4Packet`. I'd like to be able to clone the underlying data and construct a new `Ipv4Packet` that simply adopts the new data as assumed to be valid.
Contributor guide
Assessment
This issue has not been assessed yet.