Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install libpcap
run: |
sudo apt-get update
sudo apt-get install --yes libpcap-dev
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
Expand Down
34 changes: 10 additions & 24 deletions nex-datalink/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::bindings::linux;
use crate::{RawReceiver, RawSender};
use nex_core::interface::Interface;
use nex_core::mac::MacAddr;
use nex_sys;
use std::io;
use std::mem;
use std::sync::Arc;
Expand Down Expand Up @@ -64,13 +63,13 @@ pub(crate) struct Config {
fn poll_timeout_ms(timeout: Option<libc::timespec>) -> libc::c_int {
timeout
.map(|to| {
let ms = (to.tv_sec as i64 * 1000) + (to.tv_nsec as i64 / 1_000_000);
ms.clamp(i64::from(libc::c_int::MIN), i64::from(libc::c_int::MAX)) as libc::c_int
let ms = i128::from(to.tv_sec) * 1000 + i128::from(to.tv_nsec) / 1_000_000;
ms.clamp(i128::from(libc::c_int::MIN), i128::from(libc::c_int::MAX)) as libc::c_int
})
.unwrap_or(-1)
}

impl<'a> From<&'a super::Config> for Config {
impl From<&super::Config> for Config {
fn from(config: &super::Config) -> Config {
Config {
write_buffer_size: config.write_buffer_size,
Expand Down Expand Up @@ -166,11 +165,11 @@ pub(crate) fn channel(network_interface: &Interface, config: Config) -> io::Resu
} as u32;
// set defrag flag
if fanout.defrag {
typ = typ | linux::PACKET_FANOUT_FLAG_DEFRAG;
typ |= linux::PACKET_FANOUT_FLAG_DEFRAG;
}
// set rollover flag
if fanout.rollover {
typ = typ | linux::PACKET_FANOUT_FLAG_ROLLOVER;
typ |= linux::PACKET_FANOUT_FLAG_ROLLOVER;
}
// set uniqueid flag -- probably not needed atm.
// PACKET_FANOUT_FLAG_UNIQUEID
Expand Down Expand Up @@ -207,16 +206,12 @@ pub(crate) fn channel(network_interface: &Interface, config: Config) -> io::Resu
// live while this same-sized value is copied.
send_addr: unsafe { *(send_addr as *const libc::sockaddr_ll) },
send_addr_len: len,
timeout: config
.write_timeout
.map(|to| nex_sys::duration_to_timespec(to)),
timeout: config.write_timeout.map(nex_sys::duration_to_timespec),
});
let receiver = Box::new(RawReceiverImpl {
socket: fd.clone(),
read_buffer: vec![0; config.read_buffer_size],
timeout: config
.read_timeout
.map(|to| nex_sys::duration_to_timespec(to)),
timeout: config.read_timeout.map(nex_sys::duration_to_timespec),
});

Ok(super::Channel::Ethernet(sender, receiver))
Expand Down Expand Up @@ -293,10 +288,7 @@ impl RawSender for RawSenderImpl {
return Some(Err(e));
}
} else {
return Some(Err(io::Error::new(
io::ErrorKind::Other,
"Unexpected poll event",
)));
return Some(Err(io::Error::other("Unexpected poll event")));
}
}

Expand Down Expand Up @@ -349,10 +341,7 @@ impl RawSender for RawSenderImpl {
Ok(_) => Some(Ok(())),
}
} else {
Some(Err(io::Error::new(
io::ErrorKind::Other,
"Unexpected poll event",
)))
Some(Err(io::Error::other("Unexpected poll event")))
}
}
}
Expand Down Expand Up @@ -403,10 +392,7 @@ impl RawReceiver for RawReceiverImpl {
Err(e) => Err(e),
}
} else {
Err(io::Error::new(
io::ErrorKind::Other,
"Unexpected poll event",
))
Err(io::Error::other("Unexpected poll event"))
}
}
}
2 changes: 1 addition & 1 deletion nex-datalink/src/pcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<T: Activated + State + Send + Sync> RawReceiver for RawReceiverImpl<T> {
let mut cap = lock_capture(&self.capture)?;
match cap.next_packet() {
Ok(pkt) => {
self.read_buffer.truncate(0);
self.read_buffer.clear();
self.read_buffer.extend(pkt.data);
}
Err(e) => return Err(io::Error::other(e)),
Expand Down
6 changes: 2 additions & 4 deletions nex-packet/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,8 @@ impl DnsQueryPacket {
if !qname.is_empty() {
qname.push('.');
}
match str::from_utf8(&name[offset + 1..offset + 1 + label_len]) {
Ok(label) => qname.push_str(label),
Err(e) => return Err(e),
}
let label = str::from_utf8(&name[offset + 1..offset + 1 + label_len])?;
qname.push_str(label);
offset += label_len + 1;
}
Ok(qname)
Expand Down
2 changes: 1 addition & 1 deletion nex-sys/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn timespec_to_duration(ts: libc::timespec) -> Duration {
pub fn duration_to_timespec(dur: Duration) -> libc::timespec {
libc::timespec {
tv_sec: dur.as_secs() as libc::time_t,
tv_nsec: (dur.subsec_nanos() as TvUsecType).into(),
tv_nsec: dur.subsec_nanos() as _,
}
}

Expand Down
Loading