aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-04-14 18:24:35 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-04-14 18:24:35 +0200
commit97ab20783440a77aa38a57c9a104d98b6d570088 (patch)
tree348ede076d240899ed06da308129b788c525d49c
parent06ffff50f724f98b3d56d03bb037ec3f58258be2 (diff)
voip port forwarding
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml2
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs32
4 files changed, 38 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index de2cf03..88ec098 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -402,8 +402,8 @@ dependencies = [
[[package]]
name = "rustables"
-version = "0.9.0"
-source = "git+https://github.com/rsdsl/rustables.git#674db7775393f9ae800c936f920977d0fa5ef4b7"
+version = "0.10.1"
+source = "git+https://github.com/rsdsl/rustables.git#8f8eb7c1c6870e38fd1dcc694c8b74dbc0ef95dd"
dependencies = [
"bindgen",
"bitflags",
@@ -419,7 +419,7 @@ dependencies = [
[[package]]
name = "rustables-macros"
version = "0.1.1"
-source = "git+https://github.com/rsdsl/rustables.git#674db7775393f9ae800c936f920977d0fa5ef4b7"
+source = "git+https://github.com/rsdsl/rustables.git#8f8eb7c1c6870e38fd1dcc694c8b74dbc0ef95dd"
dependencies = [
"once_cell",
"proc-macro-error",
diff --git a/Cargo.toml b/Cargo.toml
index 7a84890..8f8c9f8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,5 +7,5 @@ edition = "2021"
[dependencies]
failure = "0.1.8"
-rustables = { git = "https://github.com/rsdsl/rustables.git", version = "0.9.0" }
+rustables = { git = "https://github.com/rsdsl/rustables.git", version = "0.10.1" }
thiserror = "1.0"
diff --git a/src/error.rs b/src/error.rs
index 1987292..b525e47 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -2,6 +2,8 @@ use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
+ #[error("parse ip address: {0}")]
+ AddrParse(#[from] std::net::AddrParseError),
#[error("rustables builder: {0}")]
RustablesBuilder(#[from] rustables::error::BuilderError),
#[error("rustables query: {0}")]
diff --git a/src/main.rs b/src/main.rs
index 0eda5b1..003f480 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,10 @@ fn nat() -> Result<()> {
let nat = Table::new(ProtocolFamily::Ipv4).with_name("nat");
batch.add(&nat, MsgType::Add);
+ // +-------------------+
+ // | POSTROUTING chain |
+ // +-------------------+
+
let mut postrouting = Chain::new(&nat).with_name("POSTROUTING");
postrouting.set_type(ChainType::Nat);
@@ -22,6 +26,34 @@ fn nat() -> Result<()> {
let rule = Rule::new(&postrouting)?.oface("rsppp0")?.masquerade();
batch.add(&rule, MsgType::Add);
+ // +------------------+
+ // | PREROUTING chain |
+ // +------------------+
+
+ let mut prerouting = Chain::new(&nat).with_name("PREROUTING");
+
+ prerouting.set_type(ChainType::Nat);
+ prerouting.set_hook(Hook::new(HookClass::PreRouting, -100));
+ prerouting.set_policy(ChainPolicy::Accept);
+
+ batch.add(&prerouting, MsgType::Add);
+
+ for port in 5060..=5080 {
+ let dnat_sip = Rule::new(&prerouting)?
+ .iface("rsppp0")?
+ .dport(port, Protocol::UDP)
+ .dnat("10.128.40.252".parse()?, None);
+ batch.add(&dnat_sip, MsgType::Add);
+ }
+
+ for port in 16384..=16482 {
+ let dnat_rtp = Rule::new(&prerouting)?
+ .iface("rsppp0")?
+ .dport(port, Protocol::UDP)
+ .dnat("10.128.40.252".parse()?, None);
+ batch.add(&dnat_rtp, MsgType::Add);
+ }
+
batch.send()?;
Ok(())
}