-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmod.rs
110 lines (93 loc) · 2.38 KB
/
mod.rs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! A module with all the nftables expressions that can be added to [`Rule`]s to build up how
//! they match against packets.
//!
//! [`Rule`]: struct.Rule.html
use super::rule::Rule;
use nftnl_sys::{self as sys, libc};
/// Trait for every safe wrapper of an nftables expression.
pub trait Expression {
/// Allocates and returns the low level `nftnl_expr` representation of this expression.
/// The caller to this method is responsible for freeing the expression.
fn to_expr(&self, rule: &Rule) -> *mut sys::nftnl_expr;
}
/// A netfilter data register. The expressions store and read data to and from these
/// when evaluating rule statements.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[repr(i32)]
pub enum Register {
Reg1 = libc::NFT_REG_1,
Reg2 = libc::NFT_REG_2,
Reg3 = libc::NFT_REG_3,
Reg4 = libc::NFT_REG_4,
}
impl Register {
pub fn to_raw(self) -> u32 {
self as u32
}
}
mod bitwise;
pub use self::bitwise::*;
mod cmp;
pub use self::cmp::*;
mod counter;
pub use self::counter::*;
pub mod ct;
pub use self::ct::*;
mod immediate;
pub use self::immediate::*;
mod log;
pub use self::log::*;
mod lookup;
pub use self::lookup::*;
mod masquerade;
pub use self::masquerade::*;
mod meta;
pub use self::meta::*;
mod nat;
pub use self::nat::*;
mod payload;
pub use self::payload::*;
mod verdict;
pub use self::verdict::*;
#[macro_export(local_inner_macros)]
macro_rules! nft_expr {
(bitwise mask $mask:expr,xor $xor:expr) => {
nft_expr_bitwise!(mask $mask, xor $xor)
};
(cmp $op:tt $data:expr) => {
nft_expr_cmp!($op $data)
};
(counter) => {
$crate::expr::Counter
};
(ct $key:ident set) => {
nft_expr_ct!($key set)
};
(ct $key:ident) => {
nft_expr_ct!($key)
};
(verdict $verdict:ident) => {
nft_expr_verdict!($verdict)
};
(verdict $verdict:ident $chain:expr) => {
nft_expr_verdict!($verdict $chain)
};
(lookup $set:expr) => {
nft_expr_lookup!($set)
};
(masquerade) => {
$crate::expr::Masquerade
};
(meta $expr:ident set) => {
nft_expr_meta!($expr set)
};
(meta $expr:ident) => {
nft_expr_meta!($expr)
};
(payload $proto:ident $field:ident) => {
nft_expr_payload!($proto $field)
};
(immediate $expr:ident $value:expr) => {
nft_expr_immediate!($expr $value)
};
}