github.com/TeaOSLab/EdgeNode@v1.3.8/internal/firewalls/nftables/set_batch.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  )
     9  
    10  type SetBatch struct {
    11  	conn   *Conn
    12  	rawSet *nft.Set
    13  }
    14  
    15  func (this *SetBatch) AddElement(key []byte, options *ElementOptions) error {
    16  	var rawElement = nft.SetElement{
    17  		Key: key,
    18  	}
    19  	if options != nil {
    20  		rawElement.Timeout = options.Timeout
    21  	}
    22  	return this.conn.Raw().SetAddElements(this.rawSet, []nft.SetElement{
    23  		rawElement,
    24  	})
    25  }
    26  
    27  func (this *SetBatch) DeleteElement(key []byte) error {
    28  	return this.conn.Raw().SetDeleteElements(this.rawSet, []nft.SetElement{
    29  		{
    30  			Key: key,
    31  		},
    32  	})
    33  }
    34  
    35  func (this *SetBatch) Commit() error {
    36  	return this.conn.Commit()
    37  }