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

View File

@ -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
}

View File

@ -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
}