util

package
v0.0.0-...-9f71e64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IPv4ZeroCIDR is the CIDR block for the whole IPv4 address space
	IPv4ZeroCIDR = "0.0.0.0/0"

	// IPv6ZeroCIDR is the CIDR block for the whole IPv6 address space
	IPv6ZeroCIDR = "::/0"
)

Variables

View Source
var (
	// ErrAddressNotAllowed indicates the address is not allowed
	ErrAddressNotAllowed = errors.New("address not allowed")

	// ErrNoAddresses indicates there are no addresses for the hostname
	ErrNoAddresses = errors.New("No addresses for hostname")
)

Functions

func CanUseWinKernelProxier

func CanUseWinKernelProxier(kcompat KernelCompatTester) (bool, error)

CanUseWinKernelProxier returns true if we should use the Kernel Proxier instead of the "classic" userspace Proxier. This is determined by checking the windows kernel version and for the existence of kernel features.

func ConjureMac

func ConjureMac(macPrefix string, ip net.IP) string

Uses mac prefix and IPv4 address to return a mac address This ensures mac addresses are unique for proper load balancing There is a possibility of MAC collisions but this Mac address is used for remote windowsEndpoint only and not sent on the wire.

func CountBytesLines

func CountBytesLines(b []byte) int

CountBytesLines counts the number of lines in a bytes slice

func Enum

func Enum(p v1.Protocol) uint16

func ExternalPolicyLocal

func ExternalPolicyLocal(service *localv1.Service) bool

ExternalPolicyLocal checks if service has ETP = Local.

func GetClusterIPByFamily

func GetClusterIPByFamily(ipFamily v1.IPFamily, service *localv1.Service) string

GetClusterIPByFamily returns a service clusterip by family

func GetLocalAddrSet

func GetLocalAddrSet() netutils.IPSet

GetLocalAddrSet return a local IPSet. If failed to get local addr, will assume no local ips.

func GetLocalAddrs

func GetLocalAddrs() ([]net.IP, error)

GetLocalAddrs returns a list of all network addresses on the local system

func GetNodeAddresses

func GetNodeAddresses(cidrs []string, nw NetworkInterfacer) (sets.String, error)

GetNodeAddresses return all matched node IP addresses based on given cidr slice. Some callers, e.g. IPVS proxier, need concrete IPs, not ranges, which is why this exists. NetworkInterfacer is injected for test purpose. We expect the cidrs passed in is already validated. Given an empty input `[]`, it will return `0.0.0.0/0` and `::/0` directly. If multiple cidrs is given, it will return the minimal IP sets, e.g. given input `[1.2.0.0/16, 0.0.0.0/0]`, it will only return `0.0.0.0/0`. NOTE: GetNodeAddresses only accepts CIDRs, if you want concrete IPs, e.g. 1.2.3.4, then the input should be 1.2.3.4/32.

func IPPart

func IPPart(s string) string

IPPart returns just the IP part of an IP or IP:port or endpoint string. If the IP part is an IPv6 address enclosed in brackets (e.g. "[fd00:1::5]:9999"), then the brackets are stripped as well.

func InternalPolicyLocal

func InternalPolicyLocal(service *localv1.Service) bool

InternalPolicyLocal checks if service has ITP = Local.

func IsZeroCIDR

func IsZeroCIDR(cidr string) bool

IsZeroCIDR checks whether the input CIDR string is either the IPv4 or IPv6 zero CIDR

func LogAndEmitIncorrectIPVersionEvent

func LogAndEmitIncorrectIPVersionEvent(recorder events.EventRecorder, fieldName, fieldValue, svcNamespace, svcName string, svcUID types.UID)

LogAndEmitIncorrectIPVersionEvent logs and emits incorrect IP version event.

func MapCIDRsByIPFamily

func MapCIDRsByIPFamily(cidrStrings []string) map[v1.IPFamily][]string

MapCIDRsByIPFamily maps a slice of IPs to their respective IP families (v4 or v6)

func MapIPsByIPFamily

func MapIPsByIPFamily(ips *localv1.IPSet) map[v1.IPFamily][]string

MapIPsByIPFamily maps a slice of IPs to their respective IP families (v4 or v6)

func OtherIPFamily

func OtherIPFamily(ipFamily v1.IPFamily) v1.IPFamily

OtherIPFamily returns the other ip family

func PortPart

func PortPart(s string) (int, error)

PortPart returns just the port part of an endpoint string.

func RevertPorts

func RevertPorts(replacementPortsMap, originalPortsMap map[netutils.LocalPort]netutils.Closeable)

RevertPorts is closing ports in replacementPortsMap but not in originalPortsMap. In other words, it only closes the ports opened in this sync.

func WriteBytesLine

func WriteBytesLine(buf *bytes.Buffer, bytes []byte)

WriteBytesLine write bytes to buffer, terminate with newline

func WriteLine

func WriteLine(buf *bytes.Buffer, words ...string)

WriteLine join all words with spaces, terminate with newline and write to buff.

func WriteRuleLine

func WriteRuleLine(buf *bytes.Buffer, chainName string, words ...string)

WriteRuleLine prepends the strings "-A" and chainName to the buffer and calls WriteLine to join all the words into the buffer and terminate with newline.

Types

type ExternalIPInfo

type ExternalIPInfo struct {
	IP    string
	HnsID string
}

type KernelCompatTester

type KernelCompatTester interface {
	IsCompatible() error
}

KernelCompatTester tests whether the required kernel capabilities are present to run the windows kernel proxier.

type LoadBalancerIngressInfo

type LoadBalancerIngressInfo struct {
	IP    string
	HnsID string
}

type NetworkInterfacer

type NetworkInterfacer interface {
	InterfaceAddrs() ([]net.Addr, error)
}

NetworkInterfacer defines an interface for several net library functions. Production code will forward to net library functions, and unit tests will override the methods for testing purposes.

type RealNetwork

type RealNetwork struct{}

RealNetwork implements the NetworkInterfacer interface for production code, just wrapping the underlying net library function calls.

func (RealNetwork) InterfaceAddrs

func (RealNetwork) InterfaceAddrs() ([]net.Addr, error)

InterfaceAddrs wraps net.InterfaceAddrs(), it's a part of NetworkInterfacer interface.

type WindowsKernelCompatTester

type WindowsKernelCompatTester struct{}

func (WindowsKernelCompatTester) IsCompatible

func (lkct WindowsKernelCompatTester) IsCompatible() error

IsCompatible returns true if winkernel can support this mode of proxy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL