libnetwork/iptables: IPTable.exists(): return early on error
Also remove a redundant string cast for the Table value. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
829374337f
commit
04e54c6bb0
1 changed files with 7 additions and 7 deletions
|
@ -450,21 +450,21 @@ func (iptable IPTable) ExistsNative(table Table, chain string, rule ...string) b
|
|||
}
|
||||
|
||||
func (iptable IPTable) exists(native bool, table Table, chain string, rule ...string) bool {
|
||||
if err := initCheck(); err != nil {
|
||||
// The exists() signature does not allow us to return an error, but at least
|
||||
// we can skip the (likely invalid) exec invocation.
|
||||
return false
|
||||
}
|
||||
|
||||
f := iptable.Raw
|
||||
if native {
|
||||
f = iptable.raw
|
||||
}
|
||||
|
||||
if string(table) == "" {
|
||||
if table == "" {
|
||||
table = Filter
|
||||
}
|
||||
|
||||
if err := initCheck(); err != nil {
|
||||
// The exists() signature does not allow us to return an error, but at least
|
||||
// we can skip the (likely invalid) exec invocation.
|
||||
return false
|
||||
}
|
||||
|
||||
// if exit status is 0 then return true, the rule exists
|
||||
_, err := f(append([]string{"-t", string(table), "-C", chain}, rule...)...)
|
||||
return err == nil
|
||||
|
|
Loading…
Add table
Reference in a new issue