blob: 3c722575f9163af8c61246d1470df911b0b7544c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use rustables_macros::nfnetlink_struct;
use super::{Expression, ExpressionError};
use crate::sys::{NFTA_LOG_GROUP, NFTA_LOG_PREFIX};
#[derive(Clone, PartialEq, Eq, Default, Debug)]
#[nfnetlink_struct]
/// A Log expression will log all packets that match the rule.
pub struct Log {
#[field(NFTA_LOG_GROUP)]
group: u32,
#[field(NFTA_LOG_PREFIX)]
prefix: String,
}
impl Log {
pub fn new(
group: Option<u16>,
prefix: Option<impl Into<String>>,
) -> Result<Log, ExpressionError> {
let mut res = Log::default();
if let Some(group) = group {
res.set_group(group);
}
if let Some(prefix) = prefix {
let prefix = prefix.into();
if prefix.bytes().count() > 127 {
return Err(ExpressionError::TooLongLogPrefix);
}
res.set_prefix(prefix);
}
Ok(res)
}
}
impl Expression for Log {
fn get_name() -> &'static str {
"log"
}
}
|