Skip to content

Commit

Permalink
Merge pull request #74 from rhafer/isnotexist_nft
Browse files Browse the repository at this point in the history
Fix IsNotExist for ip6tables in nft mode
  • Loading branch information
Luca Bruno authored Mar 20, 2020
2 parents f901d6c + 12696f5 commit 521ee6c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type Error struct {
exec.ExitError
cmd exec.Cmd
msg string
proto Protocol
exitStatus *int //for overriding
}

Expand All @@ -51,9 +50,8 @@ func (e *Error) IsNotExist() bool {
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)
msgNoRuleExist := "Bad rule (does a matching rule exist in that chain?).\n"
msgNoChainExist := "No chain/target/match by that name.\n"
return strings.Contains(e.msg, msgNoRuleExist) || strings.Contains(e.msg, msgNoChainExist)
}

Expand Down Expand Up @@ -452,7 +450,7 @@ func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
if err := cmd.Run(); err != nil {
switch e := err.(type) {
case *exec.ExitError:
return &Error{*e, cmd, stderr.String(), ipt.proto, nil}
return &Error{*e, cmd, stderr.String(), nil}
default:
return err
}
Expand Down

0 comments on commit 521ee6c

Please sign in to comment.