From 74d5abdfe2728614a08fbdf6f7a6c3e8cdb8b12c Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 19 Sep 2023 00:09:41 +0200 Subject: [PATCH] Use a less generic nftables table name --- .../src/wireguard-nat-nftables.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/wireguard-nat-nftables/src/wireguard-nat-nftables.py b/pkgs/wireguard-nat-nftables/src/wireguard-nat-nftables.py index 3bc8e96..c72869d 100644 --- a/pkgs/wireguard-nat-nftables/src/wireguard-nat-nftables.py +++ b/pkgs/wireguard-nat-nftables/src/wireguard-nat-nftables.py @@ -20,9 +20,9 @@ def main(): nft.set_handle_output(True) # add nat table rules for dnat and snat masquerade - nft.cmd("add table nat") - nft.cmd("add chain nat prerouting { type nat hook prerouting priority -100; }") - nft.cmd("add chain nat postrouting { type nat hook postrouting priority 100; }") + nft.cmd("add table wireguard-nat") + nft.cmd("add chain wireguard-nat prerouting { type nat hook prerouting priority -100; }") + nft.cmd("add chain wireguard-nat postrouting { type nat hook postrouting priority 100; }") # load current nftables rules rc, output, error = nft.cmd("list ruleset") @@ -34,14 +34,14 @@ def main(): for item in nftables_output["nftables"]: if ("rule" in item and item["rule"]["family"] == "ip" - and item["rule"]["table"] == "nat" + and item["rule"]["table"] == "wireguard-nat" and item["rule"]["chain"] == "postrouting" and "masquerade" in item["rule"]["expr"][0] ): add_masquerade = False break if add_masquerade: - nft.cmd("add rule nat postrouting masquerade") + nft.cmd("add rule wireguard-nat postrouting masquerade") while True: # list WireGuard peer endpoint addresses of WireGuard VPN connection @@ -67,12 +67,12 @@ def main(): # update existing nftable dnat rules, if the remote IP mismatches for item in nftables_output["nftables"]: - if "rule" in item and item["rule"]["family"] == "ip" and item["rule"]["table"] == "nat" and item["rule"]["chain"] == "prerouting": + if "rule" in item and item["rule"]["family"] == "ip" and item["rule"]["table"] == "wireguard-nat" and item["rule"]["chain"] == "prerouting": handle = item["rule"]["handle"] ip = item["rule"]["expr"][2]["dnat"]["addr"] port = item["rule"]["expr"][1]["match"]["right"] if not ip == port_ip_mapping[port]: - rc, output, error = nft.cmd("replace rule nat prerouting handle {} iif {} udp dport {} dnat to {}".format(handle, interface, port, port_ip_mapping[port])) + rc, output, error = nft.cmd("replace rule wireguard-nat prerouting handle {} iif {} udp dport {} dnat to {}".format(handle, interface, port, port_ip_mapping[port])) if error: eprint(error) else: @@ -81,7 +81,7 @@ def main(): # loop through all remaining ports and add needed dnat rules for port in port_ip_mapping: - rc, output, error = nft.cmd("add rule nat prerouting iif {} udp dport {} dnat to {}".format(interface, port, port_ip_mapping[port])) + rc, output, error = nft.cmd("add rule wireguard-nat prerouting iif {} udp dport {} dnat to {}".format(interface, port, port_ip_mapping[port])) if error: print(error, file=sys.stderr) else: