mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 00:06:35 +08:00
实现基础的DDoS防护
This commit is contained in:
51
internal/firewalls/nftables/rule.go
Normal file
51
internal/firewalls/nftables/rule.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package nftables
|
||||
|
||||
import (
|
||||
nft "github.com/google/nftables"
|
||||
"github.com/google/nftables/expr"
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
rawRule *nft.Rule
|
||||
}
|
||||
|
||||
func NewRule(rawRule *nft.Rule) *Rule {
|
||||
return &Rule{
|
||||
rawRule: rawRule,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Rule) Raw() *nft.Rule {
|
||||
return this.rawRule
|
||||
}
|
||||
|
||||
func (this *Rule) LookupSetName() string {
|
||||
for _, e := range this.rawRule.Exprs {
|
||||
exp, ok := e.(*expr.Lookup)
|
||||
if ok {
|
||||
return exp.SetName
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this *Rule) VerDict() expr.VerdictKind {
|
||||
for _, e := range this.rawRule.Exprs {
|
||||
exp, ok := e.(*expr.Verdict)
|
||||
if ok {
|
||||
return exp.Kind
|
||||
}
|
||||
}
|
||||
|
||||
return -100
|
||||
}
|
||||
|
||||
func (this *Rule) Handle() uint64 {
|
||||
return this.rawRule.Handle
|
||||
}
|
||||
|
||||
func (this *Rule) UserData() []byte {
|
||||
return this.rawRule.UserData
|
||||
}
|
||||
Reference in New Issue
Block a user