Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: 防火墙允许操作 ipv6 #5564

Merged
merged 1 commit into from
Jun 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
6 changes: 4 additions & 2 deletions backend/utils/firewall/client/firewalld.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func (f *Firewall) ListPort() ([]FireInfo, error) {
continue
}
itemRule := f.loadInfo(rule)
if len(itemRule.Port) != 0 && itemRule.Family == "ipv4" {
itemRule.Family = ""
if (len(itemRule.Port) != 0 && itemRule.Family == "ipv4") || (itemRule.Family == "ipv6" && len(itemRule.Address) != 0) {
datas = append(datas, itemRule)
}
}
Expand Down Expand Up @@ -177,6 +176,9 @@ func (f *Firewall) RichRules(rule FireInfo, operation string) error {
return buserr.New(constant.ErrCmdIllegal)
}
ruleStr := "rule family=ipv4 "
if strings.Contains(rule.Address, ":") {
ruleStr = "rule family=ipv6 "
}
if len(rule.Address) != 0 {
ruleStr += fmt.Sprintf("source address=%s ", rule.Address)
}
Expand Down
8 changes: 6 additions & 2 deletions backend/utils/firewall/client/ufw.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,19 @@ func (f *Ufw) loadInfo(line string, fireType string) FireInfo {
if len(fields) < 4 {
return itemInfo
}
if fields[1] == "(v6)" {
if fields[1] == "(v6)" && fireType == "port" {
return itemInfo
}
if fields[0] == "Anywhere" && fireType != "port" {
itemInfo.Strategy = "drop"
if fields[1] == "ALLOW" {
itemInfo.Strategy = "accept"
}
itemInfo.Address = fields[3]
if fields[1] == "(v6)" {
itemInfo.Address = fields[4]
} else {
itemInfo.Address = fields[3]
}
return itemInfo
}
if strings.Contains(fields[0], "/") {
Expand Down
Loading
Loading