Skip to content

Commit 5b7f238

Browse files
committed
use batched wg rule removal
1 parent d930a34 commit 5b7f238

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

api/wg_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def restart_wg():
4343
return False
4444
if resp.status_code == 200:
4545
logging.info('[WG]: WG interface restarted')
46-
remove_predowns()
47-
fwd_predown_rules()
46+
# remove_predowns()
47+
# fwd_predown_rules()
4848
os.system(f'cp {wgconf} {wgconf}.bak')
4949
return True
5050
else:
@@ -211,7 +211,7 @@ def rule_gen(rule,ad):
211211
{protocol} -d {peer} --dport {port} -j ACCEPT\n'
212212
preroute_rule = f'{prefix} = iptables -{ad} PREROUTING \
213213
-t nat -p {protocol} -i eth0 --dport {port} -j DNAT --to-destination \
214-
{peer}:{port}\n'
214+
{peer}:{port}\n -m comment --comment "fwded"\n'
215215
if rule == 'fwd':
216216
return fwd_rule
217217
elif rule == 'pre':

wg/restart.sh

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
# iptables --line-numbers --list
23
echo "Restarting WG interface..."
4+
# Look for all rules that have the 'fwded' comment
5+
FWD_RULES=$(iptables --line-number -nL FORWARD|grep fwded|awk '{print $1}'|tac)
36
wg-quick down wg0
7+
# Delete them (background)
8+
for rul in $FWD_RULES; do iptables -D FORWARD $rul; done
9+
sleep 0.1
410
wg-quick up wg0

0 commit comments

Comments
 (0)