forked from mullvad/nftnl-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes mullvad#45 - turn Log in a struct to group future arguments
- Loading branch information
1 parent
4c49592
commit 34522c3
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use super::{Expression, Rule}; | ||
use nftnl_sys::{ | ||
self as sys, | ||
libc::c_char, | ||
}; | ||
|
||
/// A log expression. | ||
pub struct Log { | ||
group: Option<LogGroup>, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] | ||
pub enum LogGroup { | ||
LogGroupZero, | ||
LogGroupOne, | ||
LogGroupTwo, | ||
LogGroupThree, | ||
LogGroupFour, | ||
LogGroupFive, | ||
LogGroupSix, | ||
LogGroupSeven, | ||
} | ||
|
||
|
||
impl Log { | ||
pub fn new(group: Option<LogGroup>) -> Self { | ||
Log { 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 | ||
)); | ||
if let Some(group) = self.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($group) | ||
}; | ||
() => { | ||
$crate::expr::Log::new(None) | ||
}; | ||
} |