Commit remaining Burrow platform work
This commit is contained in:
parent
fff5475914
commit
7f280c08cf
48 changed files with 2508 additions and 1864 deletions
|
|
@ -33,7 +33,7 @@ impl TunInterface {
|
|||
Ok(result) => return result,
|
||||
Err(_would_block) => {
|
||||
tracing::debug!("WouldBlock");
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,10 @@ impl TunInterface {
|
|||
ifname_to_string(buf)
|
||||
}
|
||||
|
||||
pub(crate) fn packet_information_size(&self) -> usize {
|
||||
4
|
||||
}
|
||||
|
||||
#[throws]
|
||||
#[instrument]
|
||||
fn ifreq(&self) -> sys::ifreq {
|
||||
|
|
|
|||
|
|
@ -73,6 +73,21 @@ impl TunInterface {
|
|||
ifname_to_string(iff.ifr_name)
|
||||
}
|
||||
|
||||
pub(crate) fn packet_information_size(&self) -> usize {
|
||||
let mut iff = unsafe { mem::zeroed::<libc::ifreq>() };
|
||||
match unsafe { sys::tun_get_iff(self.socket.as_raw_fd(), &mut iff) } {
|
||||
Ok(_) => {
|
||||
let flags = unsafe { iff.ifr_ifru.ifru_flags };
|
||||
if flags & libc::IFF_NO_PI as i16 != 0 {
|
||||
0
|
||||
} else {
|
||||
4
|
||||
}
|
||||
}
|
||||
Err(_) => 4,
|
||||
}
|
||||
}
|
||||
|
||||
#[throws]
|
||||
#[instrument]
|
||||
fn ifreq(&self) -> sys::ifreq {
|
||||
|
|
@ -283,6 +298,16 @@ impl TunInterface {
|
|||
#[throws]
|
||||
#[instrument]
|
||||
pub fn send(&self, buf: &[u8]) -> usize {
|
||||
self.socket.send(buf)?
|
||||
let len = unsafe {
|
||||
libc::write(
|
||||
self.as_raw_fd(),
|
||||
buf.as_ptr().cast::<libc::c_void>(),
|
||||
buf.len(),
|
||||
)
|
||||
};
|
||||
if len < 0 {
|
||||
Err(Error::last_os_error())?;
|
||||
}
|
||||
len as usize
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,26 @@ impl TunInterface {
|
|||
#[throws]
|
||||
#[instrument]
|
||||
pub fn recv(&self, buf: &mut [u8]) -> usize {
|
||||
// Use IoVec to read directly into target buffer
|
||||
let mut tmp_buf = [MaybeUninit::uninit(); 1500];
|
||||
let len = self.socket.recv(&mut tmp_buf)?;
|
||||
let result_buf = unsafe { assume_init(&tmp_buf[4..len]) };
|
||||
buf[..len - 4].copy_from_slice(result_buf);
|
||||
len - 4
|
||||
let packet_information_size = self.packet_information_size();
|
||||
let mut tmp_buf = [MaybeUninit::uninit(); 1504];
|
||||
let len = unsafe {
|
||||
libc::read(
|
||||
self.as_raw_fd(),
|
||||
tmp_buf.as_mut_ptr().cast::<libc::c_void>(),
|
||||
tmp_buf.len(),
|
||||
)
|
||||
};
|
||||
if len < 0 {
|
||||
Err(Error::last_os_error())?;
|
||||
}
|
||||
let len = len as usize;
|
||||
if len < packet_information_size {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let result_buf = unsafe { assume_init(&tmp_buf[packet_information_size..len]) };
|
||||
buf[..len - packet_information_size].copy_from_slice(result_buf);
|
||||
len - packet_information_size
|
||||
}
|
||||
|
||||
#[throws]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue