Merge pull request #107001 from mk46/unix_lib

replace syscall with sys/unix pkg in pkg/util/ipvs
This commit is contained in:
Kubernetes Prow Robot 2022-01-05 13:54:13 -08:00 committed by GitHub
commit 098b0e05d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 27 deletions

View File

@ -24,12 +24,12 @@ import (
"net"
"strings"
"sync"
"syscall"
"time"
"errors"
libipvs "github.com/moby/ipvs"
"golang.org/x/sys/unix"
"k8s.io/klog/v2"
)
@ -234,7 +234,7 @@ func toVirtualServer(svc *libipvs.Service) (*VirtualServer, error) {
vs.Flags = ServiceFlags(svc.Flags &^ uint32(FlagHashed))
if vs.Address == nil {
if svc.AddressFamily == syscall.AF_INET {
if svc.AddressFamily == unix.AF_INET {
vs.Address = net.IPv4zero
} else {
vs.Address = net.IPv6zero
@ -272,10 +272,10 @@ func toIPVSService(vs *VirtualServer) (*libipvs.Service, error) {
}
if ip4 := vs.Address.To4(); ip4 != nil {
ipvsSvc.AddressFamily = syscall.AF_INET
ipvsSvc.AddressFamily = unix.AF_INET
ipvsSvc.Netmask = 0xffffffff
} else {
ipvsSvc.AddressFamily = syscall.AF_INET6
ipvsSvc.AddressFamily = unix.AF_INET6
ipvsSvc.Netmask = 128
}
return ipvsSvc, nil
@ -297,11 +297,11 @@ func toIPVSDestination(rs *RealServer) (*libipvs.Destination, error) {
func stringToProtocol(protocol string) uint16 {
switch strings.ToLower(protocol) {
case "tcp":
return uint16(syscall.IPPROTO_TCP)
return uint16(unix.IPPROTO_TCP)
case "udp":
return uint16(syscall.IPPROTO_UDP)
return uint16(unix.IPPROTO_UDP)
case "sctp":
return uint16(syscall.IPPROTO_SCTP)
return uint16(unix.IPPROTO_SCTP)
}
return uint16(0)
}
@ -309,11 +309,11 @@ func stringToProtocol(protocol string) uint16 {
// protocolTypeToString returns the name for the given protocol.
func protocolToString(proto Protocol) string {
switch proto {
case syscall.IPPROTO_TCP:
case unix.IPPROTO_TCP:
return "TCP"
case syscall.IPPROTO_UDP:
case unix.IPPROTO_UDP:
return "UDP"
case syscall.IPPROTO_SCTP:
case unix.IPPROTO_SCTP:
return "SCTP"
}
return ""

View File

@ -22,12 +22,13 @@ package ipvs
import (
"fmt"
"reflect"
"syscall"
"testing"
netutils "k8s.io/utils/net"
libipvs "github.com/moby/ipvs"
"golang.org/x/sys/unix"
)
func Test_toVirtualServer(t *testing.T) {
@ -55,14 +56,14 @@ func Test_toVirtualServer(t *testing.T) {
},
{
libipvs.Service{
Protocol: syscall.IPPROTO_TCP,
Protocol: unix.IPPROTO_TCP,
Port: 80,
FWMark: 0,
SchedName: "",
Flags: uint32(FlagPersistent + FlagHashed),
Timeout: 0,
Netmask: 0xffffffff,
AddressFamily: syscall.AF_INET,
AddressFamily: unix.AF_INET,
Address: nil,
PEName: "",
},
@ -79,14 +80,14 @@ func Test_toVirtualServer(t *testing.T) {
},
{
libipvs.Service{
Protocol: syscall.IPPROTO_UDP,
Protocol: unix.IPPROTO_UDP,
Port: 33434,
FWMark: 0,
SchedName: "wlc",
Flags: uint32(0 + FlagHashed),
Timeout: 100,
Netmask: 128,
AddressFamily: syscall.AF_INET6,
AddressFamily: unix.AF_INET6,
Address: netutils.ParseIPSloppy("2012::beef"),
PEName: "",
},
@ -110,7 +111,7 @@ func Test_toVirtualServer(t *testing.T) {
Flags: uint32(0 + FlagHashed),
Timeout: 0,
Netmask: 0xffffffff,
AddressFamily: syscall.AF_INET,
AddressFamily: unix.AF_INET,
Address: netutils.ParseIPSloppy("1.2.3.4"),
PEName: "",
},
@ -134,7 +135,7 @@ func Test_toVirtualServer(t *testing.T) {
Flags: uint32(FlagPersistent + FlagHashed),
Timeout: 0,
Netmask: 128,
AddressFamily: syscall.AF_INET6,
AddressFamily: unix.AF_INET6,
Address: nil,
PEName: "",
},
@ -151,14 +152,14 @@ func Test_toVirtualServer(t *testing.T) {
},
{
libipvs.Service{
Protocol: syscall.IPPROTO_SCTP,
Protocol: unix.IPPROTO_SCTP,
Port: 80,
FWMark: 0,
SchedName: "",
Flags: uint32(FlagPersistent + FlagHashed),
Timeout: 0,
Netmask: 0xffffffff,
AddressFamily: syscall.AF_INET,
AddressFamily: unix.AF_INET,
Address: nil,
PEName: "",
},
@ -198,14 +199,14 @@ func Test_toIPVSService(t *testing.T) {
}{
{
libipvs.Service{
Protocol: syscall.IPPROTO_TCP,
Protocol: unix.IPPROTO_TCP,
Port: 80,
FWMark: 0,
SchedName: "",
Flags: 0,
Timeout: 0,
Netmask: 0xffffffff,
AddressFamily: syscall.AF_INET,
AddressFamily: unix.AF_INET,
Address: netutils.ParseIPSloppy("0.0.0.0"),
PEName: "",
},
@ -220,14 +221,14 @@ func Test_toIPVSService(t *testing.T) {
},
{
libipvs.Service{
Protocol: syscall.IPPROTO_UDP,
Protocol: unix.IPPROTO_UDP,
Port: 33434,
FWMark: 0,
SchedName: "wlc",
Flags: 1234,
Timeout: 100,
Netmask: 128,
AddressFamily: syscall.AF_INET6,
AddressFamily: unix.AF_INET6,
Address: netutils.ParseIPSloppy("2012::beef"),
PEName: "",
},
@ -249,7 +250,7 @@ func Test_toIPVSService(t *testing.T) {
Flags: 0,
Timeout: 0,
Netmask: 0xffffffff,
AddressFamily: syscall.AF_INET,
AddressFamily: unix.AF_INET,
Address: netutils.ParseIPSloppy("1.2.3.4"),
PEName: "",
},
@ -271,7 +272,7 @@ func Test_toIPVSService(t *testing.T) {
Flags: 0,
Timeout: 0,
Netmask: 128,
AddressFamily: syscall.AF_INET6,
AddressFamily: unix.AF_INET6,
Address: netutils.ParseIPSloppy("::0"),
PEName: "",
},
@ -388,7 +389,7 @@ func Test_stringToProtocol(t *testing.T) {
"TCP", "UDP", "ICMP", "SCTP",
}
expected := []uint16{
uint16(syscall.IPPROTO_TCP), uint16(syscall.IPPROTO_UDP), uint16(0), uint16(syscall.IPPROTO_SCTP),
uint16(unix.IPPROTO_TCP), uint16(unix.IPPROTO_UDP), uint16(0), uint16(unix.IPPROTO_SCTP),
}
for i := range tests {
got := stringToProtocol(tests[i])
@ -401,7 +402,7 @@ func Test_stringToProtocol(t *testing.T) {
func Test_protocolToString(t *testing.T) {
tests := []Protocol{
syscall.IPPROTO_TCP, syscall.IPPROTO_UDP, Protocol(0), syscall.IPPROTO_SCTP,
unix.IPPROTO_TCP, unix.IPPROTO_UDP, Protocol(0), unix.IPPROTO_SCTP,
}
expected := []string{
"TCP", "UDP", "", "SCTP",