import "k8s.io/kubernetes/pkg/proxy/util"
endpoints.go network.go port.go utils.go
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" )
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") )
AppendPortIfNeeded appends the given port to IP address unless it is already in "ipv4:port" or "[ipv6]:port" format.
BuildPortsToEndpointsMap builds a map of portname -> all ip:ports for that portname. Explode Endpoints.Subsets[*] into this structure.
EnsureSysctl sets a kernel sysctl to a given numeric value.
GetClusterIPByFamily returns a service clusterip by family
GetLocalAddrs returns a list of all network addresses on the local system
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.
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.
IsAllowedHost checks if the given IP host address is in a network in the denied list.
IsProxyableHostname checks if the IP addresses for a given hostname are permitted to be proxied
IsProxyableIP checks if a given IP address is permitted to be proxied
IsZeroCIDR checks whether the input CIDR string is either the IPv4 or IPv6 zero CIDR
func LogAndEmitIncorrectIPVersionEvent(recorder record.EventRecorder, fieldName, fieldValue, svcNamespace, svcName string, svcUID types.UID)
LogAndEmitIncorrectIPVersionEvent logs and emits incorrect IP version event.
MapCIDRsByIPFamily maps a slice of IPs to their respective IP families (v4 or v6)
MapIPsByIPFamily maps a slice of IPs to their respective IP families (v4 or v6)
OtherIPFamily returns the other ip family
PortPart returns just the port part of an endpoint string.
RevertPorts is closing ports in replacementPortsMap but not in originalPortsMap. In other words, it only closes the ports opened in this sync.
ShouldSkipService checks if a given service should skip proxying
ShuffleStrings copies strings from the specified slice into a copy in random order. It returns a new slice.
ToCIDR returns a host address of the form <ip-address>/32 for IPv4 and <ip-address>/128 for IPv6
Closeable is an interface around closing a port.
DialContext is a dial function matching the signature of net.Dialer.DialContext.
func NewFilteredDialContext(wrapped DialContext, resolv Resolver, opts *FilteredDialOptions) DialContext
NewFilteredDialContext returns a DialContext function that filters connections based on a FilteredDialOptions.
type FilteredDialOptions struct { // DialHostIPDenylist restricts hosts from being dialed. DialHostCIDRDenylist []*net.IPNet // AllowLocalLoopback controls connections to local loopback hosts (as defined by // IsProxyableIP). AllowLocalLoopback bool }
FilteredDialOptions configures how a DialContext is wrapped by NewFilteredDialContext.
type LocalPort struct { // Description is the identity message of a given local port. Description string // IP is the IP address part of a given local port. // If this string is empty, the port binds to all local IP addresses. IP string // Port is the port part of a given local port. Port int // Protocol is the protocol part of a given local port. // The value is assumed to be lower-case. For example, "udp" not "UDP", "tcp" not "TCP". Protocol string }
LocalPort describes a port on specific IP address and protocol
type NetworkInterfacer interface { Addrs(intf *net.Interface) ([]net.Addr, error) Interfaces() ([]net.Interface, 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.
PortOpener is an interface around port opening/closing. Abstracted out for testing.
type RealNetwork struct{}
RealNetwork implements the NetworkInterfacer interface for production code, just wrapping the underlying net library function calls.
Addrs wraps net.Interface.Addrs(), it's a part of NetworkInterfacer interface.
func (RealNetwork) Interfaces() ([]net.Interface, error)
Interfaces wraps net.Interfaces(), it's a part of NetworkInterfacer interface.
Resolver is an interface for net.Resolver
Path | Synopsis |
---|---|
iptables | |
testing |
Package util imports 15 packages (graph) and is imported by 127 packages. Updated 2020-12-09. Refresh now. Tools for package owners.