Skip to content

Commit

Permalink
add group param to log expr
Browse files Browse the repository at this point in the history
  • Loading branch information
lafleurdeboum committed Sep 28, 2021
1 parent e9c9e51 commit d2c9bc7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
42 changes: 38 additions & 4 deletions nftnl/src/expr/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,60 @@ use nftnl_sys::{

/// A log expression.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Log {}
pub enum Log {
NoGroup,
Group(LogGroup),
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum LogGroup {
LogGroupZero,
LogGroupOne,
LogGroupTwo,
LogGroupThree,
LogGroupFour,
LogGroupFive,
LogGroupSix,
LogGroupSeven,
}


impl Log {}
impl Log {
pub fn new() -> Self {
Log::NoGroup
}
pub fn new_with_group(group: LogGroup) -> Self {
Log::Group(group)
}
}

impl Expression for Log {
fn to_expr(&self, _rule: &Rule) -> *mut sys::nftnl_expr {
unsafe {
let expr = try_alloc!(sys::nftnl_expr_alloc(
b"log\0" as *const _ as *const c_char
));

match self {
Log::NoGroup => (),
Log::Group(group) => {
sys::nftnl_expr_set_u32(
expr,
sys::NFTNL_EXPR_LOG_GROUP as u16,
*group as u32,
);
}
}
expr
}
}
}

#[macro_export]
macro_rules! nft_expr_log {
(group $group:ident) => {
$crate::expr::Log::new_with_group($group)
};
() => {
$crate::expr::Log {}
$crate::expr::Log::new()
};
}
3 changes: 3 additions & 0 deletions nftnl/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ macro_rules! nft_expr {
(cmp $op:tt $data:expr) => {
nft_expr_cmp!($op $data)
};
(log group $group:ident) => {
nft_expr_log!(group $group)
};
(log) => {
nft_expr_log!()
};
Expand Down

0 comments on commit d2c9bc7

Please sign in to comment.