Skip to content
Merged
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
11 changes: 11 additions & 0 deletions center/plugin/nftable/backend/nftable/nftable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,12 +2253,14 @@ func parseRuleLine(line string) ([]RuleParseResult, error) {
} else {
ruleType = model.RuleDefault
}
srcIp := extractSrcIP(line)

ri := model.RuleItem{
Type: ruleType,
Rate: rate,
Count: count,
Action: action,
SrcIP: srcIp,
}

results := []RuleParseResult{}
Expand Down Expand Up @@ -2339,6 +2341,15 @@ func extractAction(line string) string {
return ""
}

func extractSrcIP(line string) string {
re := regexp.MustCompile(`ip saddr ((?:\d{1,3}\.){3}\d{1,3}(?:/\d{1,2})?)`)
match := re.FindStringSubmatch(line)
if len(match) > 1 {
return match[1]
}
return ""
}

func (s *NFTable) setPortRules(hostID uint, req model.SetPortRule) error {
// 获取 /etc/nftables.conf 内容
confContent, err := s.fileContent(hostID, "/etc/nftables.conf")
Expand Down