diff --git a/vm/devices/net/net_consomme/consomme/src/tcp.rs b/vm/devices/net/net_consomme/consomme/src/tcp.rs index 8737d84e0b..8c1a206eef 100644 --- a/vm/devices/net/net_consomme/consomme/src/tcp.rs +++ b/vm/devices/net/net_consomme/consomme/src/tcp.rs @@ -438,13 +438,6 @@ impl Sender<'_, T> { let mut eth_packet = EthernetFrame::new_unchecked(&mut buffer[..]); eth_packet.set_dst_addr(self.state.params.client_mac); eth_packet.set_src_addr(self.state.params.gateway_mac); - let copy_payload_into_buffer = |buf: &mut [u8], payload: Option>| { - if let Some(payload) = payload { - for (b, c) in buf.iter_mut().zip(payload.iter()) { - *b = *c; - } - } - }; let ip = IpRepr::new( self.ft.dst.ip().into(), self.ft.src.ip().into(), @@ -488,7 +481,9 @@ impl Sender<'_, T> { ); // Copy payload into TCP packet - copy_payload_into_buffer(tcp_packet.payload_mut(), payload); + if let Some(payload) = &payload { + payload.copy_to_slice(tcp_packet.payload_mut()); + } tcp_packet.fill_checksum(&self.ft.dst.ip().into(), &self.ft.src.ip().into()); let n = ETHERNET_HEADER_LEN + ip_total_len; let checksum_state = match self.ft.dst { diff --git a/vm/devices/net/net_consomme/consomme/src/tcp/ring.rs b/vm/devices/net/net_consomme/consomme/src/tcp/ring.rs index 7402535700..d9443b100c 100644 --- a/vm/devices/net/net_consomme/consomme/src/tcp/ring.rs +++ b/vm/devices/net/net_consomme/consomme/src/tcp/ring.rs @@ -101,9 +101,14 @@ impl<'a> View<'a> { } } - pub fn iter(&self) -> impl '_ + Iterator { + /// Copies the view contents into `buf`. + /// + /// # Panics + /// Panics if `buf` is smaller than the view length. + pub fn copy_to_slice(&self, buf: &mut [u8]) { let (a, b) = self.as_slices(); - a.iter().chain(b) + buf[..a.len()].copy_from_slice(a); + buf[a.len()..a.len() + b.len()].copy_from_slice(b); } }