-
Notifications
You must be signed in to change notification settings - Fork 26
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
fixes #45 - Add a log expression with group argument #46
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
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) | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -60,6 +60,9 @@ pub use self::nat::*; | |
mod payload; | ||
pub use self::payload::*; | ||
|
||
mod log; | ||
pub use self::log::*; | ||
|
||
mod verdict; | ||
pub use self::verdict::*; | ||
|
||
|
@@ -71,6 +74,12 @@ 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!() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you call |
||
}; | ||
(counter) => { | ||
$crate::expr::Counter | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any reason for limiting this to 8.
u16
seems to be the actual type, so I think it would make sense to use that.