diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-08-14 09:02:44 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-08-14 09:02:44 +0200 |
commit | bd37cca1ad4cfafe5098146e53fc6b55b5081d4a (patch) | |
tree | 82c3bd6ab9ebaf4a8d1bd8ebadbb09c121a564a5 /src | |
parent | 733a036da4ccd3c067f33695582495615ac55bcd (diff) |
apply nat to modem traffic
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs index b525e47..3431850 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,8 @@ use thiserror::Error; pub enum Error { #[error("parse ip address: {0}")] AddrParse(#[from] std::net::AddrParseError), + #[error("ipnetwork: {0}")] + IpNetwork(#[from] ipnetwork::IpNetworkError), #[error("rustables builder: {0}")] RustablesBuilder(#[from] rustables::error::BuilderError), #[error("rustables query: {0}")] diff --git a/src/main.rs b/src/main.rs index 4d604af..1d91419 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ use rsdsl_netfilterd::error::Result; +use std::net::Ipv4Addr; use std::thread; use std::time::Duration; +use ipnetwork::Ipv4Network; use rustables::{ Batch, Chain, ChainPolicy, ChainType, Hook, HookClass, MsgType, Protocol, ProtocolFamily, Rule, Table, @@ -26,8 +28,14 @@ fn nat() -> Result<()> { batch.add(&postrouting, MsgType::Add); - let rule = Rule::new(&postrouting)?.oface("ppp0")?.masquerade(); - batch.add(&rule, MsgType::Add); + let masq_outbound_modem = Rule::new(&postrouting)? + .oface("eth1")? + .dnetwork(Ipv4Network::new(Ipv4Addr::new(192, 168, 1, 0), 24)?.into())? + .masquerade(); + batch.add(&masq_outbound_modem, MsgType::Add); + + let masq_outbound_wan = Rule::new(&postrouting)?.oface("ppp0")?.masquerade(); + batch.add(&masq_outbound_wan, MsgType::Add); // +------------------+ // | PREROUTING chain | |