diff --git a/nftnl/src/expr/log.rs b/nftnl/src/expr/log.rs index 4250eae..236735c 100644 --- a/nftnl/src/expr/log.rs +++ b/nftnl/src/expr/log.rs @@ -6,10 +6,32 @@ 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 { @@ -17,7 +39,16 @@ impl Expression for Log { 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 } } @@ -25,7 +56,10 @@ impl Expression for Log { #[macro_export] macro_rules! nft_expr_log { + (group $group:ident) => { + $crate::expr::Log::new_with_group($group) + }; () => { - $crate::expr::Log {} + $crate::expr::Log::new() }; } diff --git a/nftnl/src/expr/mod.rs b/nftnl/src/expr/mod.rs index 7ea99a5..6bc96eb 100644 --- a/nftnl/src/expr/mod.rs +++ b/nftnl/src/expr/mod.rs @@ -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!() };