Skip to content

Commit c3cc26a

Browse files
authored
fix: Fix the issue of abnormal iptables persistence loading (#11066)
1 parent dda83b6 commit c3cc26a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/1Panel-dev/1Panel/agent/app/service"
88
"github.com/1Panel-dev/1Panel/agent/global"
99
"github.com/1Panel-dev/1Panel/agent/utils/firewall"
10+
firewallClient "github.com/1Panel-dev/1Panel/agent/utils/firewall/client"
1011
"github.com/1Panel-dev/1Panel/agent/utils/firewall/client/iptables"
1112
)
1213

@@ -29,6 +30,10 @@ func Init() {
2930
global.LOG.Errorf("load postrouting rules from file failed, err: %v", err)
3031
return
3132
}
33+
if err := firewallClient.EnableIptablesForward(); err != nil {
34+
global.LOG.Errorf("enable iptables forward failed, err: %v", err)
35+
return
36+
}
3237
global.LOG.Infof("loaded iptables rules for forward from file successfully")
3338
}
3439
if clientName == "ufw" {

agent/utils/firewall/client/iptables/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545

4646
func RunWithStd(tab, rule string) (string, error) {
4747
cmdMgr := cmd.NewCommandMgr(cmd.WithIgnoreExist1(), cmd.WithTimeout(20*time.Second))
48-
stdout, err := cmdMgr.RunWithStdoutBashCf("%s iptables -t %s %s", cmd.SudoHandleCmd(), tab, rule)
48+
stdout, err := cmdMgr.RunWithStdoutBashCf("%s iptables -w -t %s %s", cmd.SudoHandleCmd(), tab, rule)
4949
if err != nil {
5050
global.LOG.Errorf("iptables command failed [table=%s, rule=%s]: %v", tab, rule, err)
5151
return stdout, err

agent/utils/firewall/client/iptables/persistence.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ func SaveRulesToFile(tab, chain, fileName string) error {
6060
}
6161

6262
func LoadRulesFromFile(tab, chain, fileName string) error {
63-
rulesFile := path.Join(global.Dir.FirewallDir, fileName)
64-
if _, err := os.Stat(rulesFile); os.IsNotExist(err) {
65-
return nil
66-
}
67-
6863
if err := AddChain(tab, chain); err != nil {
6964
global.LOG.Errorf("create chain %s failed: %v", chain, err)
7065
return err
7166
}
67+
rulesFile := path.Join(global.Dir.FirewallDir, fileName)
68+
if _, err := os.Stat(rulesFile); os.IsNotExist(err) {
69+
return nil
70+
}
7271
data, err := os.ReadFile(rulesFile)
7372
if err != nil {
7473
global.LOG.Errorf("read rules from file %s failed, err: %v", rulesFile, err)

frontend/src/views/host/firewall/advance/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<template #main>
1818
<div class="app-warn">
1919
<div class="flex flex-col gap-2 items-center justify-center w-full sm:flex-row">
20-
<span>{{ $t('firewall.advancedControlNotAvailable', [firewallName]) }}</span>
20+
<span>{{ $t('firewall.advancedControlNotAvailable', [fireName]) }}</span>
2121
</div>
2222
<div>
2323
<img src="@/assets/images/no_app.svg" />
@@ -160,7 +160,6 @@ const loading = ref();
160160
const selects = ref<any>([]);
161161
const selectedChain = ref('1PANEL_INPUT');
162162
const defaultStrategy = ref('ACCEPT');
163-
const firewallName = ref('');
164163
165164
const maskShow = ref(true);
166165
const isActive = ref(false);

0 commit comments

Comments
 (0)