diff --git a/libnetwork/iptables/iptables.go b/libnetwork/iptables/iptables.go index a29cddb0f4..ce681f0ca6 100644 --- a/libnetwork/iptables/iptables.go +++ b/libnetwork/iptables/iptables.go @@ -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