Skip to content

Commit

Permalink
Merge pull request #72 from aojea/fix_isnotexist_bug
Browse files Browse the repository at this point in the history
fix comparison precedence order in the IsNotExist() method
  • Loading branch information
Luca Bruno authored Dec 16, 2019
2 parents c0ec0e7 + 2a66665 commit f901d6c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ func (e *Error) Error() string {

// IsNotExist returns true if the error is due to the chain or rule not existing
func (e *Error) IsNotExist() bool {
return e.ExitStatus() == 1 &&
strings.Contains(e.msg, fmt.Sprintf("%s: Bad rule (does a matching rule exist in that chain?).\n", getIptablesCommand(e.proto))) ||
strings.Contains(e.msg, fmt.Sprintf("%s: No chain/target/match by that name.\n", getIptablesCommand(e.proto)))
if e.ExitStatus() != 1 {
return false
}
cmdIptables := getIptablesCommand(e.proto)
msgNoRuleExist := fmt.Sprintf("%s: Bad rule (does a matching rule exist in that chain?).\n", cmdIptables)
msgNoChainExist := fmt.Sprintf("%s: No chain/target/match by that name.\n", cmdIptables)
return strings.Contains(e.msg, msgNoRuleExist) || strings.Contains(e.msg, msgNoChainExist)
}

// Protocol to differentiate between IPv4 and IPv6
Expand Down

0 comments on commit f901d6c

Please sign in to comment.