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 was turned off and on again, the iptables nat rule
doing hairpinning wasn't properly removed. This fix makes sure that nat
rule is removed whenever the bridge is torn down or hairpinning is
disabled (through setting userland-proxy to true).

Fixes moby#44721.
  • Loading branch information
akerouanton committed Jan 11, 2023
1 parent eaa7b49 commit f986369
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 f986369

Please sign in to comment.