diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/expr/lookup.rs | 2 | ||||
-rw-r--r-- | src/expr/payload.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/set.rs | 28 |
4 files changed, 18 insertions, 17 deletions
diff --git a/src/expr/lookup.rs b/src/expr/lookup.rs index 8e288a0..fa12197 100644 --- a/src/expr/lookup.rs +++ b/src/expr/lookup.rs @@ -13,7 +13,7 @@ pub struct Lookup { impl Lookup { /// Creates a new lookup entry. /// May return None if the set have no name. - pub fn new<K>(set: &Set<'_, K>) -> Option<Self> { + pub fn new<K>(set: &Set<K>) -> Option<Self> { set.get_name().map(|set_name| Lookup { set_name: set_name.to_owned(), set_id: set.get_id(), diff --git a/src/expr/payload.rs b/src/expr/payload.rs index 7612fd9..4ba47df 100644 --- a/src/expr/payload.rs +++ b/src/expr/payload.rs @@ -28,7 +28,7 @@ impl Payload { }), Payload::Transport(ref f) => RawPayload::Transport(RawPayloadData { offset: f.offset(), - len: f.offset(), + len: f.len(), }), } } @@ -77,8 +77,8 @@ use thiserror::Error; extern crate log; pub mod sys; -use sys::libc; use std::{convert::TryFrom, ffi::c_void, ops::Deref}; +use sys::libc; macro_rules! try_alloc { ($e:expr) => {{ @@ -123,6 +123,7 @@ mod rule_methods; pub use rule_methods::{iface_index, Protocol, RuleMethods, Error as MatchError}; pub mod set; +pub use set::Set; /// The type of the message as it's sent to netfilter. A message consists of an object, such as a /// [`Table`], [`Chain`] or [`Rule`] for example, and a [`MsgType`] to describe what to do with @@ -1,5 +1,5 @@ -use crate::{table::Table, MsgType, ProtoFamily}; use crate::sys::{self, libc}; +use crate::{table::Table, MsgType, ProtoFamily}; use std::{ cell::Cell, ffi::{c_void, CStr, CString}, @@ -26,15 +26,15 @@ macro_rules! nft_set { }}; } -pub struct Set<'a, K> { +pub struct Set<K> { pub(crate) set: *mut sys::nftnl_set, - pub(crate) table: &'a Table, + pub(crate) table: Rc<Table>, pub(crate) family: ProtoFamily, _marker: ::std::marker::PhantomData<K>, } -impl<'a, K> Set<'a, K> { - pub fn new(name: &CStr, id: u32, table: &'a Table, family: ProtoFamily) -> Self +impl<K> Set<K> { + pub fn new(name: &CStr, id: u32, table: Rc<Table>, family: ProtoFamily) -> Self where K: SetKey, { @@ -63,7 +63,7 @@ impl<'a, K> Set<'a, K> { } } - pub unsafe fn from_raw(set: *mut sys::nftnl_set, table: &'a Table, family: ProtoFamily) -> Self + pub unsafe fn from_raw(set: *mut sys::nftnl_set, table: Rc<Table>, family: ProtoFamily) -> Self where K: SetKey, { @@ -95,7 +95,7 @@ impl<'a, K> Set<'a, K> { } } - pub fn elems_iter(&'a self) -> SetElemsIter<'a, K> { + pub fn elems_iter(&self) -> SetElemsIter<K> { SetElemsIter::new(self) } @@ -146,13 +146,13 @@ impl<'a, K> Set<'a, K> { } } -impl<'a, K> Debug for Set<'a, K> { +impl<K> Debug for Set<K> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self.get_str()) } } -unsafe impl<'a, K> crate::NlMsg for Set<'a, K> { +unsafe impl<K> crate::NlMsg for Set<K> { unsafe fn write(&self, buf: *mut c_void, seq: u32, msg_type: MsgType) { let type_ = match msg_type { MsgType::Add => libc::NFT_MSG_NEWSET, @@ -169,20 +169,20 @@ unsafe impl<'a, K> crate::NlMsg for Set<'a, K> { } } -impl<'a, K> Drop for Set<'a, K> { +impl<K> Drop for Set<K> { fn drop(&mut self) { unsafe { sys::nftnl_set_free(self.set) }; } } pub struct SetElemsIter<'a, K> { - set: &'a Set<'a, K>, + set: &'a Set<K>, iter: *mut sys::nftnl_set_elems_iter, ret: Rc<Cell<i32>>, } impl<'a, K> SetElemsIter<'a, K> { - fn new(set: &'a Set<'a, K>) -> Self { + fn new(set: &'a Set<K>) -> Self { let iter = try_alloc!(unsafe { sys::nftnl_set_elems_iter_create(set.set as *const sys::nftnl_set) }); @@ -194,7 +194,7 @@ impl<'a, K> SetElemsIter<'a, K> { } } -impl<'a, K: 'a> Iterator for SetElemsIter<'a, K> { +impl<'a, K> Iterator for SetElemsIter<'a, K> { type Item = SetElemsMsg<'a, K>; fn next(&mut self) -> Option<Self::Item> { @@ -219,7 +219,7 @@ impl<'a, K> Drop for SetElemsIter<'a, K> { } pub struct SetElemsMsg<'a, K> { - set: &'a Set<'a, K>, + set: &'a Set<K>, iter: *mut sys::nftnl_set_elems_iter, ret: Rc<Cell<i32>>, } |