github.com/TeaOSLab/EdgeNode@v1.3.8/internal/firewalls/nftables/rule.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  //go:build linux
     3  
     4  package nftables
     5  
     6  import (
     7  	nft "github.com/google/nftables"
     8  	"github.com/google/nftables/expr"
     9  )
    10  
    11  type Rule struct {
    12  	rawRule *nft.Rule
    13  }
    14  
    15  func NewRule(rawRule *nft.Rule) *Rule {
    16  	return &Rule{
    17  		rawRule: rawRule,
    18  	}
    19  }
    20  
    21  func (this *Rule) Raw() *nft.Rule {
    22  	return this.rawRule
    23  }
    24  
    25  func (this *Rule) LookupSetName() string {
    26  	for _, e := range this.rawRule.Exprs {
    27  		exp, ok := e.(*expr.Lookup)
    28  		if ok {
    29  			return exp.SetName
    30  		}
    31  	}
    32  	return ""
    33  }
    34  
    35  func (this *Rule) VerDict() expr.VerdictKind {
    36  	for _, e := range this.rawRule.Exprs {
    37  		exp, ok := e.(*expr.Verdict)
    38  		if ok {
    39  			return exp.Kind
    40  		}
    41  	}
    42  
    43  	return -100
    44  }
    45  
    46  func (this *Rule) Handle() uint64 {
    47  	return this.rawRule.Handle
    48  }
    49  
    50  func (this *Rule) UserData() []byte {
    51  	return this.rawRule.UserData
    52  }