run hack/update-netparse-cve.sh

This commit is contained in:
Antonio Ojea
2021-08-20 01:16:14 +02:00
parent e9ddac5d85
commit 0cd75e8fec
159 changed files with 1071 additions and 988 deletions

View File

@@ -86,7 +86,7 @@ import (
utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
"k8s.io/kubernetes/pkg/util/oom"
"k8s.io/utils/exec"
utilsnet "k8s.io/utils/net"
netutils "k8s.io/utils/net"
utilpointer "k8s.io/utils/pointer"
)
@@ -836,13 +836,13 @@ func (s *ProxyServer) CleanupAndExit() error {
// 2. the primary IP from the Node object, if set
// 3. if no IP is found it defaults to 127.0.0.1 and IPv4
func detectNodeIP(client clientset.Interface, hostname, bindAddress string) net.IP {
nodeIP := net.ParseIP(bindAddress)
nodeIP := netutils.ParseIPSloppy(bindAddress)
if nodeIP.IsUnspecified() {
nodeIP = utilnode.GetNodeIP(client, hostname)
}
if nodeIP == nil {
klog.V(0).Infof("can't determine this node's IP, assuming 127.0.0.1; if this is incorrect, please set the --bind-address flag")
nodeIP = net.ParseIP("127.0.0.1")
nodeIP = netutils.ParseIPSloppy("127.0.0.1")
}
return nodeIP
}
@@ -853,8 +853,8 @@ func detectNodeIP(client clientset.Interface, hostname, bindAddress string) net.
func nodeIPTuple(bindAddress string) [2]net.IP {
nodes := [2]net.IP{net.IPv4zero, net.IPv6zero}
adr := net.ParseIP(bindAddress)
if utilsnet.IsIPv6(adr) {
adr := netutils.ParseIPSloppy(bindAddress)
if netutils.IsIPv6(adr) {
nodes[1] = adr
} else {
nodes[0] = adr

View File

@@ -24,7 +24,6 @@ import (
"context"
"errors"
"fmt"
"net"
goruntime "runtime"
"strings"
"time"
@@ -65,7 +64,7 @@ import (
utilnode "k8s.io/kubernetes/pkg/util/node"
utilsysctl "k8s.io/kubernetes/pkg/util/sysctl"
"k8s.io/utils/exec"
utilsnet "k8s.io/utils/net"
netutils "k8s.io/utils/net"
"k8s.io/klog/v2"
)
@@ -177,7 +176,7 @@ func newProxyServer(
klog.V(2).InfoS("DetectLocalMode", "LocalMode", string(detectLocalMode))
primaryProtocol := utiliptables.ProtocolIPv4
if utilsnet.IsIPv6(nodeIP) {
if netutils.IsIPv6(nodeIP) {
primaryProtocol = utiliptables.ProtocolIPv6
}
iptInterface = utiliptables.New(execer, primaryProtocol)
@@ -350,7 +349,7 @@ func newProxyServer(
// TODO this has side effects that should only happen when Run() is invoked.
proxier, err = userspace.NewProxier(
userspace.NewLoadBalancerRR(),
net.ParseIP(config.BindAddress),
netutils.ParseIPSloppy(config.BindAddress),
iptInterface,
execer,
*utilnet.ParsePortRangeOrDie(config.PortRange),
@@ -504,7 +503,7 @@ func getDualStackLocalDetectorTuple(mode proxyconfigapi.LocalMode, config *proxy
}
// localDetectors, like ipt, need to be of the order [IPv4, IPv6], but PodCIDRs is setup so that PodCIDRs[0] == PodCIDR.
// so have to handle the case where PodCIDR can be IPv6 and set that to localDetectors[1]
if utilsnet.IsIPv6CIDRString(nodeInfo.Spec.PodCIDR) {
if netutils.IsIPv6CIDRString(nodeInfo.Spec.PodCIDR) {
localDetectors[1], err = proxyutiliptables.NewDetectLocalByCIDR(nodeInfo.Spec.PodCIDR, ipt[1])
if err != nil {
return localDetectors, err
@@ -538,7 +537,7 @@ func cidrTuple(cidrList string) [2]string {
foundIPv6 := false
for _, cidr := range strings.Split(cidrList, ",") {
if utilsnet.IsIPv6CIDRString(cidr) && !foundIPv6 {
if netutils.IsIPv6CIDRString(cidr) && !foundIPv6 {
cidrs[1] = cidr
foundIPv6 = true
} else if !foundIPv4 {

View File

@@ -26,6 +26,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
netutils "k8s.io/utils/net"
clientsetfake "k8s.io/client-go/kubernetes/fake"
@@ -232,21 +233,21 @@ func Test_detectNodeIP(t *testing.T) {
nodeInfo: makeNodeWithAddresses("", "", ""),
hostname: "fakeHost",
bindAddress: "10.0.0.1",
expectedIP: net.ParseIP("10.0.0.1"),
expectedIP: netutils.ParseIPSloppy("10.0.0.1"),
},
{
name: "Bind address IPv6 unicast address and no Node object",
nodeInfo: makeNodeWithAddresses("", "", ""),
hostname: "fakeHost",
bindAddress: "fd00:4321::2",
expectedIP: net.ParseIP("fd00:4321::2"),
expectedIP: netutils.ParseIPSloppy("fd00:4321::2"),
},
{
name: "No Valid IP found",
nodeInfo: makeNodeWithAddresses("", "", ""),
hostname: "fakeHost",
bindAddress: "",
expectedIP: net.ParseIP("127.0.0.1"),
expectedIP: netutils.ParseIPSloppy("127.0.0.1"),
},
// Disabled because the GetNodeIP method has a backoff retry mechanism
// and the test takes more than 30 seconds
@@ -256,63 +257,63 @@ func Test_detectNodeIP(t *testing.T) {
// nodeInfo: makeNodeWithAddresses("", "", ""),
// hostname: "fakeHost",
// bindAddress: "0.0.0.0",
// expectedIP: net.ParseIP("127.0.0.1"),
// expectedIP: net.IP{127,0,0,1),
// },
{
name: "Bind address 0.0.0.0 and node with IPv4 InternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "192.168.1.1", "90.90.90.90"),
hostname: "fakeHost",
bindAddress: "0.0.0.0",
expectedIP: net.ParseIP("192.168.1.1"),
expectedIP: netutils.ParseIPSloppy("192.168.1.1"),
},
{
name: "Bind address :: and node with IPv4 InternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "192.168.1.1", "90.90.90.90"),
hostname: "fakeHost",
bindAddress: "::",
expectedIP: net.ParseIP("192.168.1.1"),
expectedIP: netutils.ParseIPSloppy("192.168.1.1"),
},
{
name: "Bind address 0.0.0.0 and node with IPv6 InternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "fd00:1234::1", "2001:db8::2"),
hostname: "fakeHost",
bindAddress: "0.0.0.0",
expectedIP: net.ParseIP("fd00:1234::1"),
expectedIP: netutils.ParseIPSloppy("fd00:1234::1"),
},
{
name: "Bind address :: and node with IPv6 InternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "fd00:1234::1", "2001:db8::2"),
hostname: "fakeHost",
bindAddress: "::",
expectedIP: net.ParseIP("fd00:1234::1"),
expectedIP: netutils.ParseIPSloppy("fd00:1234::1"),
},
{
name: "Bind address 0.0.0.0 and node with only IPv4 ExternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "", "90.90.90.90"),
hostname: "fakeHost",
bindAddress: "0.0.0.0",
expectedIP: net.ParseIP("90.90.90.90"),
expectedIP: netutils.ParseIPSloppy("90.90.90.90"),
},
{
name: "Bind address :: and node with only IPv4 ExternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "", "90.90.90.90"),
hostname: "fakeHost",
bindAddress: "::",
expectedIP: net.ParseIP("90.90.90.90"),
expectedIP: netutils.ParseIPSloppy("90.90.90.90"),
},
{
name: "Bind address 0.0.0.0 and node with only IPv6 ExternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "", "2001:db8::2"),
hostname: "fakeHost",
bindAddress: "0.0.0.0",
expectedIP: net.ParseIP("2001:db8::2"),
expectedIP: netutils.ParseIPSloppy("2001:db8::2"),
},
{
name: "Bind address :: and node with only IPv6 ExternalIP set",
nodeInfo: makeNodeWithAddresses("fakeHost", "", "2001:db8::2"),
hostname: "fakeHost",
bindAddress: "::",
expectedIP: net.ParseIP("2001:db8::2"),
expectedIP: netutils.ParseIPSloppy("2001:db8::2"),
},
}
for _, c := range cases {

View File

@@ -23,7 +23,6 @@ package app
import (
"errors"
"fmt"
"net"
goruntime "runtime"
// Enable pprof HTTP handlers.
@@ -45,6 +44,7 @@ import (
utilnetsh "k8s.io/kubernetes/pkg/util/netsh"
utilnode "k8s.io/kubernetes/pkg/util/node"
"k8s.io/utils/exec"
netutils "k8s.io/utils/net"
)
// NewProxyServer returns a new ProxyServer.
@@ -148,7 +148,7 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
proxier, err = winuserspace.NewProxier(
winuserspace.NewLoadBalancerRR(),
net.ParseIP(config.BindAddress),
netutils.ParseIPSloppy(config.BindAddress),
netshInterface,
*utilnet.ParsePortRangeOrDie(config.PortRange),
// TODO @pires replace below with default values, if applicable