github.com/chenbh/concourse/v6@v6.4.2/worker/runtime/iptables/iptables.go (about)

     1  package iptables
     2  
     3  import (
     4  	goiptables "github.com/coreos/go-iptables/iptables"
     5  )
     6  
     7  //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . Iptables
     8  
     9  type Iptables interface {
    10  	CreateChainOrFlushIfExists(table string, chain string) error
    11  	AppendRule(table string, chain string, rulespec ...string) error
    12  }
    13  
    14  type iptables struct {
    15  	goipt *goiptables.IPTables
    16  }
    17  
    18  var _ Iptables = (*iptables)(nil)
    19  
    20  func New() (Iptables, error) {
    21  	g, err := goiptables.New()
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	ipt := iptables{
    27  		goipt: g,
    28  	}
    29  
    30  	return &ipt, nil
    31  }
    32  
    33  func (ipt *iptables) CreateChainOrFlushIfExists(table string, chain string) error {
    34  	err := ipt.goipt.ClearChain(table, chain)
    35  	return err
    36  }
    37  
    38  func (ipt *iptables) AppendRule(table string, chain string, rulespec ...string) error {
    39  	err := ipt.goipt.Append(table, chain, rulespec...)
    40  	return err
    41  }