diff --git a/libnetwork/drivers/bridge/port_mapping.go b/libnetwork/drivers/bridge/port_mapping.go index f55905372c..5e4fb42846 100644 --- a/libnetwork/drivers/bridge/port_mapping.go +++ b/libnetwork/drivers/bridge/port_mapping.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "net" - "strings" "github.com/docker/libnetwork/types" "github.com/ishidawataru/sctp" @@ -151,7 +150,7 @@ func (n *bridgeNetwork) releasePort(bnd types.PortBinding) error { portmapper := n.portMapper - if strings.ContainsAny(host.String(), "]") == true { + if bnd.HostIP.To4() == nil { portmapper = n.portMapperV6 } diff --git a/libnetwork/drivers/bridge/setup_ip_tables.go b/libnetwork/drivers/bridge/setup_ip_tables.go index 59f6def9d5..0dbc844805 100644 --- a/libnetwork/drivers/bridge/setup_ip_tables.go +++ b/libnetwork/drivers/bridge/setup_ip_tables.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "net" - "strings" "github.com/docker/libnetwork/iptables" "github.com/sirupsen/logrus" @@ -226,7 +225,7 @@ type iptRule struct { args []string } -func setupIPTablesInternal(hostIP net.IP, bridgeIface string, addr net.Addr, icc, ipmasq, hairpin, enable bool) error { +func setupIPTablesInternal(hostIP net.IP, bridgeIface string, addr *net.IPNet, icc, ipmasq, hairpin, enable bool) error { var ( address = addr.String() @@ -251,7 +250,7 @@ func setupIPTablesInternal(hostIP net.IP, bridgeIface string, addr net.Addr, icc ipVersion := iptables.IPv4 - if strings.Contains(address, ":") { + if addr.IP.To4() == nil { ipVersion = iptables.IPv6 } @@ -422,7 +421,7 @@ func removeIPChains(version iptables.IPVersion) { } } -func setupInternalNetworkRules(bridgeIface string, addr net.Addr, icc, insert bool) error { +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"}} @@ -430,7 +429,7 @@ func setupInternalNetworkRules(bridgeIface string, addr net.Addr, icc, insert bo version := iptables.IPv4 - if strings.Contains(addr.String(), ":") { + if addr.IP.To4() == nil { version = iptables.IPv6 }