Skip to content

Commit

Permalink
libnetwork: Remove iptables nat rule when hairpin is disabled
Browse files Browse the repository at this point in the history
When userland-proxy is turned off and on again, the iptables nat rule
doing hairpinning isn't properly removed. This fix makes sure this nat
rule is removed whenever the bridge is torn down or hairpinning is
disabled (through setting userland-proxy to true).

Unlike for ip masquerading and ICC, the `programChainRule()` call
setting up the "MASQ LOCAL HOST" rule has to be called unconditionally
because the hairpin parameter isn't restored from the driver store, but
always comes from the driver config.

Fixes moby#44721.
  • Loading branch information
akerouanton committed Jan 11, 2023
1 parent eaa7b49 commit 5f46fda
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions libnetwork/drivers/bridge/setup_ip_tables.go
Expand Up @@ -244,11 +244,10 @@ func setupIPTablesInternal(hostIP net.IP, bridgeIface string, addr *net.IPNet, i
}
}

// In hairpin mode, masquerade traffic from localhost
if hairpin {
if err := programChainRule(ipVersion, hpNatRule, "MASQ LOCAL HOST", enable); err != nil {
return err
}
// In hairpin mode, masquerade traffic from localhost. If hairpin is disabled or if we're tearing down
// that bridge, make sure the iptables rule isn't lying around.
if err := programChainRule(ipVersion, hpNatRule, "MASQ LOCAL HOST", enable && hairpin); err != nil {
return err
}

// Set Inter Container Communication.
Expand Down

0 comments on commit 5f46fda

Please sign in to comment.