github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/network/filter.go (about) 1 package network 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/garden" 7 "code.cloudfoundry.org/garden-linux/network/iptables" 8 ) 9 10 //go:generate counterfeiter . Filter 11 12 type Filter interface { 13 Setup(logPrefix string) error 14 TearDown() 15 NetOut(garden.NetOutRule) error 16 } 17 18 type filter struct { 19 chain iptables.Chain 20 } 21 22 func NewFilter(instanceChain iptables.Chain) Filter { 23 return &filter{instanceChain} 24 } 25 26 func (fltr *filter) Setup(logPrefix string) error { 27 if err := fltr.chain.Setup(logPrefix); err != nil { 28 return fmt.Errorf("network: log chain setup: %v", err) 29 } 30 return nil 31 } 32 33 func (fltr *filter) TearDown() { 34 fltr.chain.TearDown() 35 } 36 37 func (fltr *filter) NetOut(r garden.NetOutRule) error { 38 return fltr.chain.PrependFilterRule(r) 39 }