aboutsummaryrefslogtreecommitdiff
path: root/src/expr/nat.rs
diff options
context:
space:
mode:
authorSimon THOBY <git@nightmared.fr>2022-12-07 23:22:01 +0100
committerSimon THOBY <git@nightmared.fr>2022-12-07 23:22:01 +0100
commitd43356f31a3d4062ea076376a5ee1b457be1b226 (patch)
tree8b14934c73bbd1388633ba677e19c4f7297c91c4 /src/expr/nat.rs
parentedb440a952320ea4f021c1d7063ff6d5f2f13818 (diff)
add the payload and nat expressions
Diffstat (limited to 'src/expr/nat.rs')
-rw-r--r--src/expr/nat.rs45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/expr/nat.rs b/src/expr/nat.rs
index ce6b881..8fb73fa 100644
--- a/src/expr/nat.rs
+++ b/src/expr/nat.rs
@@ -1,41 +1,41 @@
-use super::{DeserializationError, Expression, Register, Rule};
-use crate::ProtoFamily;
-use crate::sys::{self, libc};
-use std::{convert::TryFrom, os::raw::c_char};
+use rustables_macros::{nfnetlink_enum, nfnetlink_struct};
+
+use super::{Expression, Register};
+use crate::{
+ sys::{self, NFT_NAT_DNAT, NFT_NAT_SNAT},
+ ProtocolFamily,
+};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-#[repr(i32)]
+#[nfnetlink_enum(i32)]
pub enum NatType {
/// Source NAT. Changes the source address of a packet.
- SNat = libc::NFT_NAT_SNAT,
+ SNat = NFT_NAT_SNAT,
/// Destination NAT. Changes the destination address of a packet.
- DNat = libc::NFT_NAT_DNAT,
-}
-
-impl NatType {
- fn from_raw(val: u32) -> Result<Self, DeserializationError> {
- match val as i32 {
- libc::NFT_NAT_SNAT => Ok(NatType::SNat),
- libc::NFT_NAT_DNAT => Ok(NatType::DNat),
- _ => Err(DeserializationError::InvalidValue),
- }
- }
+ DNat = NFT_NAT_DNAT,
}
/// A source or destination NAT statement. Modifies the source or destination address (and possibly
/// port) of packets.
-#[derive(Debug, PartialEq)]
+#[derive(Default, Debug, Clone, PartialEq, Eq)]
+#[nfnetlink_struct(nested = true)]
pub struct Nat {
+ #[field(sys::NFTA_NAT_TYPE)]
pub nat_type: NatType,
- pub family: ProtoFamily,
+ #[field(sys::NFTA_NAT_FAMILY)]
+ pub family: ProtocolFamily,
+ #[field(sys::NFTA_NAT_REG_ADDR_MIN)]
pub ip_register: Register,
- pub port_register: Option<Register>,
+ #[field(sys::NFTA_NAT_REG_PROTO_MIN)]
+ pub port_register: Register,
}
impl Expression for Nat {
- fn get_raw_name() -> *const libc::c_char {
- b"nat\0" as *const _ as *const c_char
+ fn get_name() -> &'static str {
+ "nat"
}
+}
+/*
fn from_expr(expr: *const sys::nftnl_expr) -> Result<Self, DeserializationError>
where
@@ -97,3 +97,4 @@ impl Expression for Nat {
expr
}
}
+*/