Skip to content

Commit

Permalink
bridge, spoofcheck: only read the prerouting chain on CNI delete
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
  • Loading branch information
maiqueb committed Apr 19, 2023
1 parent 5e84484 commit 8b86929
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/link/spoofcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

type NftConfigurer interface {
Apply(*nft.Config) error
Read() (*nft.Config, error)
Read(filterCommands ...string) (*nft.Config, error)
}

type SpoofChecker struct {
Expand All @@ -45,8 +45,8 @@ func (dnc defaultNftConfigurer) Apply(cfg *nft.Config) error {
return nft.ApplyConfig(cfg)
}

func (dnc defaultNftConfigurer) Read() (*nft.Config, error) {
return nft.ReadConfig()
func (dnc defaultNftConfigurer) Read(filterCommands ...string) (*nft.Config, error) {
return nft.ReadConfig(filterCommands...)
}

func NewSpoofChecker(iface, macAddress, refID string) *SpoofChecker {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (sc *SpoofChecker) Setup() error {
// interface is removed.
func (sc *SpoofChecker) Teardown() error {
ifaceChain := sc.ifaceChain()
currentConfig, ifaceMatchRuleErr := sc.configurer.Read()
currentConfig, ifaceMatchRuleErr := sc.configurer.Read(listChainBridgeNatPrerouting()...)
if ifaceMatchRuleErr == nil {
expectedRuleToFind := sc.matchIfaceJumpToChainRule(preRoutingBaseChainName, ifaceChain.Name)
// It is safer to exclude the statement matching, avoiding cases where a current statement includes
Expand Down Expand Up @@ -241,3 +241,7 @@ func ruleComment(id string) string {
const refIDPrefix = "macspoofchk-"
return refIDPrefix + id
}

func listChainBridgeNatPrerouting() []string {
return []string{"chain", "bridge", "nat", preRoutingBaseChainName}
}
2 changes: 1 addition & 1 deletion pkg/link/spoofcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (a *configurerStub) Apply(c *nft.Config) error {
return nil
}

func (a *configurerStub) Read() (*nft.Config, error) {
func (a *configurerStub) Read(_ ...string) (*nft.Config, error) {
if a.failReadConfig {
return nil, fmt.Errorf(errorReadText)
}
Expand Down

0 comments on commit 8b86929

Please sign in to comment.