Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for tproxy #41

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions resources/test/json/tproxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"nftables": [
{
"metainfo": {
"version": "1.0.9",
"release_name": "Old Doc Yak #3",
"json_schema_version": 1
}
},
{
"table": {
"family": "inet",
"name": "filter",
"handle": 1
}
},
{
"chain": {
"family": "inet",
"table": "filter",
"name": "tproxy_ipv4",
"handle": 1
}
},
{
"chain": {
"family": "inet",
"table": "filter",
"name": "tproxy_ipv6",
"handle": 2
}
},
{
"rule": {
"family": "inet",
"table": "filter",
"chain": "tproxy_ipv4",
"handle": 3,
"expr": [
{
"match": {
"op": "==",
"left": {
"meta": {
"key": "l4proto"
}
},
"right": "tcp"
}
},
{
"tproxy": {
"family": "ip",
"addr": "127.0.0.1",
"port": 12345
}
}
]
}
},
{
"rule": {
"family": "inet",
"table": "filter",
"chain": "tproxy_ipv4",
"handle": 4,
"expr": [
{
"match": {
"op": "==",
"left": {
"meta": {
"key": "l4proto"
}
},
"right": "tcp"
}
},
{
"tproxy": {
"family": "ip",
"port": 12345
}
}
]
}
},
{
"rule": {
"family": "inet",
"table": "filter",
"chain": "tproxy_ipv6",
"handle": 5,
"expr": [
{
"match": {
"op": "==",
"left": {
"meta": {
"key": "l4proto"
}
},
"right": "tcp"
}
},
{
"tproxy": {
"family": "ip6",
"addr": "::1",
"port": 12345
}
}
]
}
},
{
"rule": {
"family": "inet",
"table": "filter",
"chain": "tproxy_ipv6",
"handle": 6,
"expr": [
{
"match": {
"op": "==",
"left": {
"meta": {
"key": "l4proto"
}
},
"right": "tcp"
}
},
{
"tproxy": {
"family": "ip6",
"port": 12345
}
}
]
}
}
]
}
16 changes: 16 additions & 0 deletions resources/test/nft/tproxy.nft
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/sbin/nft -f

flush ruleset

table inet filter {

chain tproxy_ipv4 {
meta l4proto tcp tproxy ip to 127.0.0.1:12345
meta l4proto tcp tproxy ip to :12345
}

chain tproxy_ipv6 {
meta l4proto tcp tproxy ip6 to [::1]:12345
meta l4proto tcp tproxy ip6 to :12345
}
}
12 changes: 12 additions & 0 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub enum Statement {
/// This represents an xt statement from xtables compat interface.
/// Sadly, at this point, it is not possible to provide any further information about its content.
XT(Option<serde_json::Value>),

TProxy(TProxy),
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -420,6 +422,16 @@ pub struct CTCount {
pub inv: Option<bool>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub struct TProxy {
#[serde(skip_serializing_if = "Option::is_none")]
pub family: Option<String>,
pub port: u16,
#[serde(skip_serializing_if = "Option::is_none")]
pub addr: Option<String>,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
/// Represents an operator for `Match`.
pub enum Operator {
Expand Down