Skip to content

Commit

Permalink
Merge pull request #46214 from thaJeztah/24.0_backport_allow-all-ipv6…
Browse files Browse the repository at this point in the history
…-icc

[24.0 backport] libnet/d/bridge: Allow IPv6 ICC from any IP address
  • Loading branch information
neersighted committed Aug 15, 2023
2 parents 215c6e7 + b7d1e98 commit f1cc576
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions libnetwork/drivers/bridge/setup_ip_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,21 @@ func removeIPChains(version iptables.IPVersion) {
}

func setupInternalNetworkRules(bridgeIface string, addr *net.IPNet, icc, insert bool) error {
var (
inDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{"-i", bridgeIface, "!", "-d", addr.String(), "-j", "DROP"}}
outDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{"-o", bridgeIface, "!", "-s", addr.String(), "-j", "DROP"}}
)

version := iptables.IPv4

if addr.IP.To4() == nil {
var version iptables.IPVersion
var inDropRule, outDropRule iptRule

if addr.IP.To4() != nil {
version = iptables.IPv4
inDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{
"-i", bridgeIface, "!", "-d", addr.String(), "-j", "DROP"}}
outDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{
"-o", bridgeIface, "!", "-s", addr.String(), "-j", "DROP"}}
} else {
version = iptables.IPv6
inDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{
"-i", bridgeIface, "!", "-o", bridgeIface, "!", "-d", addr.String(), "-j", "DROP"}}
outDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{
"!", "-i", bridgeIface, "-o", bridgeIface, "!", "-s", addr.String(), "-j", "DROP"}}
}

if err := programChainRule(version, inDropRule, "DROP INCOMING", insert); err != nil {
Expand All @@ -414,6 +420,7 @@ func setupInternalNetworkRules(bridgeIface string, addr *net.IPNet, icc, insert
if err := programChainRule(version, outDropRule, "DROP OUTGOING", insert); err != nil {
return err
}

// Set Inter Container Communication.
return setIcc(version, bridgeIface, icc, insert)
}
Expand Down

0 comments on commit f1cc576

Please sign in to comment.