libn: fix resolver restore w/ chatty 'iptables -C'
Resolver.setupIPTable() checks whether it needs to flush or create the
user chains used for NATing container DNS requests by testing for the
existence of the rules which jump to said user chains. Unfortunately it
does so using the IPTable.RawCombinedOutputNative() method, which
returns a non-nil error if the iptables command returns any output even
if the command exits with a zero status code. While that is fine with
iptables-legacy as it prints no output if the rule exists, iptables-nft
v1.8.7 prints some information about the rule. Consequently,
Resolver.setupIPTable() would incorrectly think that the rule does not
exist during container restore and attempt to create it. This happened
work work by coincidence before 8f5a9a741b
because the failure to create the already-existing table would be
ignored and the new NAT rules would be inserted before the stale rules
left in the table from when the container was last started/restored. Now
that failing to create the table is treated as a fatal error, the
incompatibility with iptables-nft is no longer hidden.
Switch to using IPTable.ExistsNative() to test for the existence of the
jump rules as it correctly only checks the iptables command's exit
status without regard for whether it outputs anything.
Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
2cd23ffeec
commit
1178319313
1 changed files with 2 additions and 4 deletions
|
@ -37,8 +37,7 @@ func (r *Resolver) setupIPTable() error {
|
||||||
iptable := iptables.GetIptable(iptables.IPv4)
|
iptable := iptables.GetIptable(iptables.IPv4)
|
||||||
|
|
||||||
// insert outputChain and postroutingchain
|
// insert outputChain and postroutingchain
|
||||||
err := iptable.RawCombinedOutputNative("-t", "nat", "-C", "OUTPUT", "-d", resolverIP, "-j", outputChain)
|
if iptable.ExistsNative("nat", "OUTPUT", "-d", resolverIP, "-j", outputChain) {
|
||||||
if err == nil {
|
|
||||||
if err := iptable.RawCombinedOutputNative("-t", "nat", "-F", outputChain); err != nil {
|
if err := iptable.RawCombinedOutputNative("-t", "nat", "-F", outputChain); err != nil {
|
||||||
setupErr = err
|
setupErr = err
|
||||||
return
|
return
|
||||||
|
@ -54,8 +53,7 @@ func (r *Resolver) setupIPTable() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = iptable.RawCombinedOutputNative("-t", "nat", "-C", "POSTROUTING", "-d", resolverIP, "-j", postroutingChain)
|
if iptable.ExistsNative("nat", "POSTROUTING", "-d", resolverIP, "-j", postroutingChain) {
|
||||||
if err == nil {
|
|
||||||
if err := iptable.RawCombinedOutputNative("-t", "nat", "-F", postroutingChain); err != nil {
|
if err := iptable.RawCombinedOutputNative("-t", "nat", "-F", postroutingChain); err != nil {
|
||||||
setupErr = err
|
setupErr = err
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue