Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #60

Merged
merged 7 commits into from
Jun 4, 2024
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
8 changes: 7 additions & 1 deletion nftnl/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub struct Batch {
unsafe impl Send for Batch {}
unsafe impl Sync for Batch {}

impl Default for Batch {
fn default() -> Self {
Self::new()
}
}

impl Batch {
/// Creates a new nftnl batch with the [default page size].
///
Expand Down Expand Up @@ -141,7 +147,7 @@ impl FinalizedBatch {
};
num_pages
];
let iovecs_ptr = iovecs.as_mut_ptr() as *mut sys::libc::iovec;
let iovecs_ptr = iovecs.as_mut_ptr();
unsafe {
sys::nftnl_batch_iovec(self.batch.as_raw_batch(), iovecs_ptr, num_pages as u32);
}
Expand Down
2 changes: 1 addition & 1 deletion nftnl/src/expr/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub trait ToSlice {
fn to_slice(&self) -> Cow<'_, [u8]>;
}

impl<'a> ToSlice for [u8; 0] {
impl ToSlice for [u8; 0] {
fn to_slice(&self) -> Cow<'_, [u8]> {
Cow::Borrowed(&[])
}
Expand Down
2 changes: 1 addition & 1 deletion nftnl/src/expr/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::mem::size_of_val;
use std::os::raw::c_char;

/// An immediate expression. Used to set immediate data.
/// Verdicts are handled separately by [Verdict].
/// Verdicts are handled separately by [Verdict](super::Verdict).
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Immediate<T> {
pub data: T,
Expand Down
4 changes: 2 additions & 2 deletions nftnl/src/expr/verdict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ pub enum RejectionType {
}

impl RejectionType {
fn to_raw(&self, family: ProtoFamily) -> u32 {
fn to_raw(self, family: ProtoFamily) -> u32 {
use libc::*;
let value = match *self {
let value = match self {
RejectionType::Icmp(..) => match family {
ProtoFamily::Bridge | ProtoFamily::Inet => NFT_REJECT_ICMPX_UNREACH,
_ => NFT_REJECT_ICMP_UNREACH,
Expand Down
9 changes: 7 additions & 2 deletions nftnl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,21 @@ pub enum ProtoFamily {

/// Trait for all types in this crate that can serialize to a Netlink message.
///
/// # Unsafe
/// # Safety
///
/// This trait is unsafe to implement because it must never serialize to anything larger than the
/// largest possible netlink message. Internally the `nft_nlmsg_maxsize()` function is used to make
/// largest possible netlink message. Internally the [`nft_nlmsg_maxsize`] function is used to make
/// sure the `buf` pointer passed to `write` always has room for the largest possible Netlink
/// message.
pub unsafe trait NlMsg {
/// Serializes the Netlink message to the buffer at `buf`. `buf` must have space for at least
/// `nft_nlmsg_maxsize()` bytes. This is not checked by the compiler, which is why this method
/// is unsafe.
///
/// # Safety
///
/// The caller must pass a `buf` with enough space for the largest possible netlink message.
/// This size can be obtained with [`nft_nlmsg_maxsize`].
unsafe fn write(&self, buf: *mut c_void, seq: u32, msg_type: MsgType);
}

Expand Down
2 changes: 1 addition & 1 deletion nftnl/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ pub fn get_tables_cb(header: &libc::nlmsghdr, tables: &mut HashSet<CString>) ->
tables.insert(table_name);
sys::nftnl_table_free(nf_table);
};
return 1;
1
}