1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

replace string.Contains* with net.IP.To4() check

Signed-off-by: Benjamin Böhmke <benjamin@boehmke.net>
This commit is contained in:
Benjamin Böhmke 2020-07-20 19:53:43 +02:00
parent 3475f006b7
commit ec7df93731
2 changed files with 5 additions and 7 deletions
libnetwork/drivers/bridge

View file

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"strings"
"github.com/docker/libnetwork/types" "github.com/docker/libnetwork/types"
"github.com/ishidawataru/sctp" "github.com/ishidawataru/sctp"
@ -151,7 +150,7 @@ func (n *bridgeNetwork) releasePort(bnd types.PortBinding) error {
portmapper := n.portMapper portmapper := n.portMapper
if strings.ContainsAny(host.String(), "]") == true { if bnd.HostIP.To4() == nil {
portmapper = n.portMapperV6 portmapper = n.portMapperV6
} }

View file

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"strings"
"github.com/docker/libnetwork/iptables" "github.com/docker/libnetwork/iptables"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -226,7 +225,7 @@ type iptRule struct {
args []string 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 ( var (
address = addr.String() address = addr.String()
@ -251,7 +250,7 @@ func setupIPTablesInternal(hostIP net.IP, bridgeIface string, addr net.Addr, icc
ipVersion := iptables.IPv4 ipVersion := iptables.IPv4
if strings.Contains(address, ":") { if addr.IP.To4() == nil {
ipVersion = iptables.IPv6 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 ( var (
inDropRule = iptRule{table: iptables.Filter, chain: IsolationChain1, args: []string{"-i", bridgeIface, "!", "-d", addr.String(), "-j", "DROP"}} 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"}} 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 version := iptables.IPv4
if strings.Contains(addr.String(), ":") { if addr.IP.To4() == nil {
version = iptables.IPv6 version = iptables.IPv6
} }