MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / existsRule

Method existsRule

internal/firewalls/ddos_protection.go:423–444  ·  view source on GitHub ↗

根据参数检查规则是否存在

(rules []*nftables.Rule, attrs []string)

Source from the content-addressed store, hash-verified

421
422// 根据参数检查规则是否存在
423func (this *DDoSProtectionManager) existsRule(rules []*nftables.Rule, attrs []string) (exists bool) {
424 if len(attrs) == 0 {
425 return false
426 }
427 for _, oldRule := range rules {
428 var pieces = this.decodeUserData(oldRule.UserData())
429 if len(attrs) != len(pieces) {
430 continue
431 }
432 var isSame = true
433 for index, piece := range pieces {
434 if strings.TrimSpace(piece) != attrs[index] {
435 isSame = false
436 break
437 }
438 }
439 if isSame {
440 return true
441 }
442 }
443 return false
444}
445
446// 获取规则中的端口号
447func (this *DDoSProtectionManager) getTCPPorts(rules []*nftables.Rule) []int32 {

Callers 1

addTCPRulesMethod · 0.95

Calls 2

decodeUserDataMethod · 0.95
UserDataMethod · 0.80

Tested by

no test coverage detected