Skip to content

Commit

Permalink
Fix buffer cutting from end
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasan6979 committed Jan 17, 2025
1 parent d740b17 commit 6c8d671
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions neptun/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ impl Device {
let (element, iter) = unsafe { TX_RING_BUFFER.get_next() };
if element.is_element_free.load(Ordering::Relaxed) {
const DATA_OFFSET: usize = 16;
let len = match iface.read(&mut element.data[DATA_OFFSET..mtu]) {
let len = match iface.read(&mut element.data[DATA_OFFSET..mtu + DATA_OFFSET]) {
Ok(src) => src.len(),
Err(Error::IfaceRead(e)) => {
let ek = e.kind();
Expand All @@ -1068,19 +1068,18 @@ impl Device {
{
break;
}
println!(
"Fatal read error on tun interface {e}"
tracing::error!(
message="Fatal read error on tun interface: errno", error=?e
);
return Action::Exit;
}
Err(e) => {
println!(
"Unexpected error on tun interface {e}"
tracing::error!(
message="Unexpected error on tun interface", error=?e
);
return Action::Exit;
}
};
println!("got data");

let dst_addr = match Tunn::dst_address(
&element.data[DATA_OFFSET..len + DATA_OFFSET],
Expand All @@ -1104,7 +1103,6 @@ impl Device {
}

let res = {
println!("queueing for encap");
let mut tun = peer.tunnel.lock();
tun.queue_encapsulate(len, element, iter, peer.endpoint_ref(), &mut t.dst_buf[..])
};
Expand Down Expand Up @@ -1181,7 +1179,6 @@ fn send_to_network(
udp6: Arc<Socket>,
) {
while let Ok(msg) = network_rx.recv() {
println!("send_to_network");
match &msg.res {
NeptunResult::Done => {}
NeptunResult::Err(e) => {
Expand Down

0 comments on commit 6c8d671

Please sign in to comment.