aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-08-14 09:02:44 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-08-14 09:02:44 +0200
commitbd37cca1ad4cfafe5098146e53fc6b55b5081d4a (patch)
tree82c3bd6ab9ebaf4a8d1bd8ebadbb09c121a564a5
parent733a036da4ccd3c067f33695582495615ac55bcd (diff)
apply nat to modem traffic
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml3
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs12
4 files changed, 25 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8bb6472..a3831d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -220,6 +220,9 @@ name = "ipnetwork"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e"
+dependencies = [
+ "serde",
+]
[[package]]
name = "lazy_static"
@@ -390,9 +393,10 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rsdsl_netfilterd"
-version = "0.5.0"
+version = "0.5.1"
dependencies = [
"failure",
+ "ipnetwork",
"rustables",
"thiserror",
]
@@ -438,6 +442,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
+name = "serde"
+version = "1.0.183"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c"
+
+[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 223d274..a886406 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,11 +1,12 @@
[package]
name = "rsdsl_netfilterd"
-version = "0.5.0"
+version = "0.5.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
failure = "0.1.8"
+ipnetwork = "0.20.0"
rustables = { git = "https://github.com/rsdsl/rustables.git", version = "0.14.0" }
thiserror = "1.0"
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 |