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

improvements to reduce iptables downtime #1338

Merged
merged 2 commits into from
Aug 25, 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
8 changes: 8 additions & 0 deletions plugins/interface/intf_base_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,12 @@ class InterfaceBasePlugin extends Plugin {
}
}

async resetConnmark() {
// reset first bit of connmark to make packets of established connections go through iptables filter again
await exec(`sudo conntrack -U -m 0x00000000/0x80000000`).catch((err) => {});
await exec(`sudo conntrack -U -f ipv6 -m 0x00000000/0x80000000`).catch((err) => {});
}

async updateRouteForDNS() {
// TODO: there is no IPv6 DNS currently
const dns = await this.getDNSNameservers();
Expand Down Expand Up @@ -892,6 +898,8 @@ class InterfaceBasePlugin extends Plugin {

await this.changeRoutingTables();

await this.resetConnmark();

if (this.isWAN()) {
this._wanStatus = {};
this._wanConnState = this._wanConnState || { ready: true, successCount: OFF_ON_THRESHOLD - 1, failureCount: 0 };
Expand Down
6 changes: 5 additions & 1 deletion scripts/prepare_network_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ sudo ip -6 r flush table static

# ------ initialize ip rules
# do not touch ip rules created by Firewalla
# intermediate state of ip rule initializaton may result in wrong routing decision and wrongly accepts a packet that should be blocked, so temporarily suspend packet forward
sudo iptables -w -C FR_FORWARD -m comment --comment "forward temp suspend" -j DROP &> /dev/null || sudo iptables -w -I FR_FORWARD -m comment --comment "forward temp suspend" -j DROP
rules_to_remove=`ip rule list | grep -v -e "^\(5000\|6000\|10000\):" | cut -d: -f2-`;
while IFS= read -r line; do
sudo ip rule del $line
Expand All @@ -396,7 +398,9 @@ sudo ip rule add pref 32767 from all lookup default
sudo ip rule add pref 500 from all iif lo lookup global_local
sudo ip rule add pref 4001 from all lookup static
"
sudo iptables -w -D FR_FORWARD -m comment --comment "forward temp suspend" -j DROP

sudo ip6tables -w -C FR_FORWARD -m comment --comment "forward temp suspend" -j DROP &> /dev/null || sudo ip6tables -w -I FR_FORWARD -m comment --comment "forward temp suspend" -j DROP
rules_to_remove=`ip -6 rule list | grep -v -e "^\(5000\|6000\|10000\):" | cut -d: -f2-`;
while IFS= read -r line; do
sudo ip -6 rule del $line
Expand All @@ -409,4 +413,4 @@ sudo ip -6 rule add pref 32767 from all lookup default
sudo ip -6 rule add pref 500 from all iif lo lookup global_local
sudo ip -6 rule add pref 4001 from all lookup static
"

sudo ip6tables -w -D FR_FORWARD -m comment --comment "forward temp suspend" -j DROP
Loading