utils: k8s.io/utils/net Index | Examples | Files

package net

import "k8s.io/utils/net"

Index

Examples

Package Files

ipnet.go net.go port.go

Variables

var ListenPortOpener listenPortOpener

ListenPortOpener opens ports by calling bind() and listen().

func AddIPOffset Uses

func AddIPOffset(base *big.Int, offset int) net.IP

AddIPOffset adds the provided integer offset to a base big.Int representing a net.IP NOTE: If you started with a v4 address and overflow it, you get a v6 result.

func BigForIP Uses

func BigForIP(ip net.IP) *big.Int

BigForIP creates a big.Int based on the provided net.IP

func GetIndexedIP Uses

func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error)

GetIndexedIP returns a net.IP that is subnet.IP + index in the contiguous IP space.

func IsDualStackCIDRStrings Uses

func IsDualStackCIDRStrings(cidrs []string) (bool, error)

IsDualStackCIDRStrings returns if - all are valid cidrs - at least one cidr from each family (v4 or v6)

func IsDualStackCIDRs Uses

func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error)

IsDualStackCIDRs returns if - all are valid cidrs - at least one cidr from each family (v4 or v6)

func IsDualStackIPStrings Uses

func IsDualStackIPStrings(ips []string) (bool, error)

IsDualStackIPStrings returns if - all are valid ips - at least one ip from each family (v4 or v6)

func IsDualStackIPs Uses

func IsDualStackIPs(ips []net.IP) (bool, error)

IsDualStackIPs returns if a slice of ips is: - all are valid ips - at least one ip from each family (v4 or v6)

func IsIPv6 Uses

func IsIPv6(netIP net.IP) bool

IsIPv6 returns if netIP is IPv6.

func IsIPv6CIDR Uses

func IsIPv6CIDR(cidr *net.IPNet) bool

IsIPv6CIDR returns if a cidr is ipv6

func IsIPv6CIDRString Uses

func IsIPv6CIDRString(cidr string) bool

IsIPv6CIDRString returns if cidr is IPv6. This assumes cidr is a valid CIDR.

func IsIPv6String Uses

func IsIPv6String(ip string) bool

IsIPv6String returns if ip is IPv6.

func ParseCIDRs Uses

func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error)

ParseCIDRs parses a list of cidrs and return error if any is invalid. order is maintained

func ParsePort Uses

func ParsePort(port string, allowZero bool) (int, error)

ParsePort parses a string representing an IP port. If the string is not a valid port number, this returns an error.

func RangeSize Uses

func RangeSize(subnet *net.IPNet) int64

RangeSize returns the size of a range in valid addresses. returns the size of the subnet (or math.MaxInt64 if the range size would overflow int64)

type Closeable Uses

type Closeable interface {
    Close() error
}

Closeable closes an opened LocalPort.

type IPFamily Uses

type IPFamily string

IPFamily refers to a specific family if not empty, i.e. "4" or "6".

const (
    IPv4 IPFamily = "4"
    IPv6          = "6"
)

Constants for valid IPFamilys:

type IPNetSet Uses

type IPNetSet map[string]*net.IPNet

IPNetSet maps string to net.IPNet.

func ParseIPNets Uses

func ParseIPNets(specs ...string) (IPNetSet, error)

ParseIPNets parses string slice to IPNetSet.

func (IPNetSet) Delete Uses

func (s IPNetSet) Delete(items ...*net.IPNet)

Delete removes all items from the set.

func (IPNetSet) Difference Uses

func (s IPNetSet) Difference(s2 IPNetSet) IPNetSet

Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}

func (IPNetSet) Equal Uses

func (s IPNetSet) Equal(s2 IPNetSet) bool

Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)

func (IPNetSet) Has Uses

func (s IPNetSet) Has(item *net.IPNet) bool

Has returns true if and only if item is contained in the set.

func (IPNetSet) HasAll Uses

func (s IPNetSet) HasAll(items ...*net.IPNet) bool

HasAll returns true if and only if all items are contained in the set.

func (IPNetSet) Insert Uses

func (s IPNetSet) Insert(items ...*net.IPNet)

Insert adds items to the set.

func (IPNetSet) IsSuperset Uses

func (s IPNetSet) IsSuperset(s2 IPNetSet) bool

IsSuperset returns true if and only if s1 is a superset of s2.

func (IPNetSet) Len Uses

func (s IPNetSet) Len() int

Len returns the size of the set.

func (IPNetSet) StringSlice Uses

func (s IPNetSet) StringSlice() []string

StringSlice returns a []string with the String representation of each element in the set. Order is undefined.

type IPSet Uses

type IPSet map[string]net.IP

IPSet maps string to net.IP

func ParseIPSet Uses

func ParseIPSet(items ...string) (IPSet, error)

ParseIPSet parses string slice to IPSet

func (IPSet) Delete Uses

func (s IPSet) Delete(items ...net.IP)

Delete removes all items from the set.

func (IPSet) Difference Uses

func (s IPSet) Difference(s2 IPSet) IPSet

Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}

func (IPSet) Equal Uses

func (s IPSet) Equal(s2 IPSet) bool

Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)

func (IPSet) Has Uses

func (s IPSet) Has(item net.IP) bool

Has returns true if and only if item is contained in the set.

func (IPSet) HasAll Uses

func (s IPSet) HasAll(items ...net.IP) bool

HasAll returns true if and only if all items are contained in the set.

func (IPSet) Insert Uses

func (s IPSet) Insert(items ...net.IP)

Insert adds items to the set.

func (IPSet) IsSuperset Uses

func (s IPSet) IsSuperset(s2 IPSet) bool

IsSuperset returns true if and only if s1 is a superset of s2.

func (IPSet) Len Uses

func (s IPSet) Len() int

Len returns the size of the set.

func (IPSet) StringSlice Uses

func (s IPSet) StringSlice() []string

StringSlice returns a []string with the String representation of each element in the set. Order is undefined.

type LocalPort Uses

type LocalPort struct {
    // Description is an arbitrary string.
    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
    // If IPFamily is not empty, the port binds only to addresses of this
    // family.
    // IF empty along with IP, bind to local addresses of any family.
    IPFamily IPFamily
    // Port is the port number.
    // A value of 0 causes a port to be automatically chosen.
    Port int
    // Protocol is the protocol, e.g. TCP
    Protocol Protocol
}

LocalPort represents an IP address and port pair along with a protocol and potentially a specific IP family. A LocalPort can be opened and subsequently closed.

Code:

lp, err := NewLocalPort(
    "TCP port",
    "",
    IPv4,
    443,
    TCP,
)
if err != nil {
    panic(err)
}
port, err := ListenPortOpener.OpenLocalPort(lp)
if err != nil {
    panic(err)
}
port.Close()

func NewLocalPort Uses

func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protocol) (*LocalPort, error)

NewLocalPort returns a LocalPort instance and ensures IPFamily and IP are consistent and that the given protocol is valid.

func (*LocalPort) String Uses

func (lp *LocalPort) String() string

type PortOpener Uses

type PortOpener interface {
    OpenLocalPort(lp *LocalPort) (Closeable, error)
}

PortOpener can open a LocalPort and allows later closing it.

type Protocol Uses

type Protocol string

Protocol is a network protocol support by LocalPort.

const (
    TCP Protocol = "TCP"
    UDP Protocol = "UDP"
)

Constants for valid protocols:

Package net imports 7 packages (graph) and is imported by 241 packages. Updated 2020-03-22. Refresh now. Tools for package owners.