diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 11 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 26 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..1987292 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,11 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum Error { + #[error("rustables builder: {0}")] + RustablesBuilder(#[from] rustables::error::BuilderError), + #[error("rustables query: {0}")] + RustablesQuery(#[from] rustables::error::QueryError), +} + +pub type Result<T> = std::result::Result<T, Error>; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a91e735 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod error; diff --git a/src/main.rs b/src/main.rs index 977a5f7..239fe1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,25 @@ -use std::error::Error; +use rsdsl_netfilterd::error::Result; -fn main() -> Result<(), Box<dyn Error>> { - let ipt = iptables::new(false)?; +use rustables::{ + Batch, Chain, ChainPolicy, ChainType, Hook, HookClass, MsgType, ProtocolFamily, Rule, Table, +}; - ipt.append("nat", "POSTROUTING", "-o rsppp0 -j MASQUERADE")?; +fn main() -> Result<()> { + let mut batch = Batch::new(); - Ok(()) + let nat = Table::new(ProtocolFamily::Ipv4).with_name("nat"); + batch.add(&nat, MsgType::Add); + + let mut postrouting = Chain::new(&nat).with_name("POSTROUTING"); + + postrouting.set_type(ChainType::Nat); + postrouting.set_hook(Hook::new(HookClass::PostRouting, 100)); + postrouting.set_policy(ChainPolicy::Accept); + + batch.add(&postrouting, MsgType::Add); + + let rule = Rule::new(&postrouting)?.oface("rsppp0")?.masquerade(); + batch.add(&rule, MsgType::Add); + + Ok(batch.send()?) } |