aboutsummaryrefslogtreecommitdiff
path: root/src/chain_methods.rs
diff options
context:
space:
mode:
authorSimon THOBY <git@nightmared.fr>2022-12-02 23:58:52 +0100
committerSimon THOBY <git@nightmared.fr>2022-12-02 23:58:52 +0100
commit9ff02d4e40113ae10b6244a8a3d94c6e0bad5427 (patch)
treec42cefbc3ef0aadcda1895255f4745fb760eae29 /src/chain_methods.rs
parentd1170d81c85254d2fe5ef5d3fc92cc6eb35357a4 (diff)
refactor to remove the enum AttributeType
Diffstat (limited to 'src/chain_methods.rs')
-rw-r--r--src/chain_methods.rs40
1 files changed, 0 insertions, 40 deletions
diff --git a/src/chain_methods.rs b/src/chain_methods.rs
deleted file mode 100644
index d384c35..0000000
--- a/src/chain_methods.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-use crate::{Batch, Chain, Hook, MsgType, Policy, Table};
-use std::ffi::CString;
-use std::rc::Rc;
-
-
-/// A helper trait over [`crate::Chain`].
-pub trait ChainMethods {
- /// Creates a new Chain instance from a [`crate::Hook`] over a [`crate::Table`].
- fn from_hook(hook: Hook, table: Rc<Table>) -> Self
- where Self: std::marker::Sized;
- /// Adds a [`crate::Policy`] to the current Chain.
- fn verdict(self, policy: Policy) -> Self;
- fn add_to_batch(self, batch: &mut Batch) -> Self;
-}
-
-
-impl ChainMethods for Chain {
- fn from_hook(hook: Hook, table: Rc<Table>) -> Self {
- let chain_name = match hook {
- Hook::PreRouting => "prerouting",
- Hook::Out => "out",
- Hook::PostRouting => "postrouting",
- Hook::Forward => "forward",
- Hook::In => "in",
- };
- let chain_name = CString::new(chain_name).unwrap();
- let mut chain = Chain::new(&chain_name, table);
- chain.set_hook(hook, 0);
- chain
- }
- fn verdict(mut self, policy: Policy) -> Self {
- self.set_policy(policy);
- self
- }
- fn add_to_batch(self, batch: &mut Batch) -> Self {
- batch.add(&self, MsgType::Add);
- self
- }
-}
-