...

Package net

import "k8s.io/utils/net"
Overview
Index
Examples
Subdirectories

Overview ▾

Index ▾

Variables
func AddIPOffset(base *big.Int, offset int) net.IP
func BigForIP(ip net.IP) *big.Int
func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error)
func IsDualStackCIDRStrings(cidrs []string) (bool, error)
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error)
func IsDualStackIPStrings(ips []string) (bool, error)
func IsDualStackIPs(ips []net.IP) (bool, error)
func IsIPv4(netIP net.IP) bool
func IsIPv4CIDR(cidr *net.IPNet) bool
func IsIPv4CIDRString(cidr string) bool
func IsIPv4String(ip string) bool
func IsIPv6(netIP net.IP) bool
func IsIPv6CIDR(cidr *net.IPNet) bool
func IsIPv6CIDRString(cidr string) bool
func IsIPv6String(ip string) bool
func MultiListen(ctx context.Context, network string, addrs ...string) (net.Listener, error)
func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error)
func ParsePort(port string, allowZero bool) (int, error)
func RangeSize(subnet *net.IPNet) int64
type Closeable
type IPFamily
    func IPFamilyOf(ip net.IP) IPFamily
    func IPFamilyOfCIDR(cidr *net.IPNet) IPFamily
    func IPFamilyOfCIDRString(cidr string) IPFamily
    func IPFamilyOfString(ip string) IPFamily
type IPNetSet
    func ParseIPNets(specs ...string) (IPNetSet, error)
    func (s IPNetSet) Delete(items ...*net.IPNet)
    func (s IPNetSet) Difference(s2 IPNetSet) IPNetSet
    func (s IPNetSet) Equal(s2 IPNetSet) bool
    func (s IPNetSet) Has(item *net.IPNet) bool
    func (s IPNetSet) HasAll(items ...*net.IPNet) bool
    func (s IPNetSet) Insert(items ...*net.IPNet)
    func (s IPNetSet) IsSuperset(s2 IPNetSet) bool
    func (s IPNetSet) Len() int
    func (s IPNetSet) StringSlice() []string
type IPSet
    func ParseIPSet(items ...string) (IPSet, error)
    func (s IPSet) Delete(items ...net.IP)
    func (s IPSet) Difference(s2 IPSet) IPSet
    func (s IPSet) Equal(s2 IPSet) bool
    func (s IPSet) Has(item net.IP) bool
    func (s IPSet) HasAll(items ...net.IP) bool
    func (s IPSet) Insert(items ...net.IP)
    func (s IPSet) IsSuperset(s2 IPSet) bool
    func (s IPSet) Len() int
    func (s IPSet) StringSlice() []string
type LocalPort
    func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protocol) (*LocalPort, error)
    func (lp *LocalPort) String() string
type PortOpener
type Protocol

Examples

LocalPort

Package files

ipfamily.go ipnet.go multi_listen.go net.go parse.go port.go

Variables

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

var ListenPortOpener listenPortOpener

ParseCIDRSloppy is identical to Go's standard net.ParseCIDR, except that it allows leading '0' characters on numbers. Go used to allow this and then changed the behavior in 1.17. We're choosing to keep it for compat with potential stored values.

var ParseCIDRSloppy = forkednet.ParseCIDR

ParseIPSloppy is identical to Go's standard net.ParseIP, except that it allows leading '0' characters on numbers. Go used to allow this and then changed the behavior in 1.17. We're choosing to keep it for compat with potential stored values.

var ParseIPSloppy = forkednet.ParseIP

func AddIPOffset

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

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

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

func GetIndexedIP

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

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

IsDualStackCIDRStrings returns if - all elements of cidrs can be parsed as CIDRs - at least one CIDR from each family (v4 and v6) is present

func IsDualStackCIDRs

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

IsDualStackCIDRs returns true if: - all elements of cidrs are non-nil - at least one CIDR from each family (v4 and v6) is present

func IsDualStackIPStrings

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

IsDualStackIPStrings returns true if: - all elements of ips can be parsed as IPs - at least one IP from each family (v4 and v6) is present

func IsDualStackIPs

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

IsDualStackIPs returns true if: - all elements of ips are valid - at least one IP from each family (v4 and v6) is present

func IsIPv4

func IsIPv4(netIP net.IP) bool

IsIPv4 returns true if netIP is IPv4 (and false if it is IPv6, nil, or invalid).

func IsIPv4CIDR

func IsIPv4CIDR(cidr *net.IPNet) bool

IsIPv4CIDR returns true if cidr is a valid IPv4 CIDR. It returns false if cidr is nil or an IPv6 CIDR. Its behavior is not defined if cidr is invalid.

func IsIPv4CIDRString

func IsIPv4CIDRString(cidr string) bool

IsIPv4CIDRString returns true if cidr contains a single IPv4 CIDR and nothing else. It returns false if cidr is an empty string, an IPv6 CIDR, or anything else that is not a single valid IPv4 CIDR.

func IsIPv4String

func IsIPv4String(ip string) bool

IsIPv4String returns true if ip contains a single IPv4 address and nothing else. It returns false if ip is an empty string, an IPv6 address, or anything else that is not a single IPv4 address.

func IsIPv6

func IsIPv6(netIP net.IP) bool

IsIPv6 returns true if netIP is IPv6 (and false if it is IPv4, nil, or invalid).

func IsIPv6CIDR

func IsIPv6CIDR(cidr *net.IPNet) bool

IsIPv6CIDR returns true if a cidr is a valid IPv6 CIDR. It returns false if cidr is nil or an IPv4 CIDR. Its behavior is not defined if cidr is invalid.

func IsIPv6CIDRString

func IsIPv6CIDRString(cidr string) bool

IsIPv6CIDRString returns true if cidr contains a single IPv6 CIDR and nothing else. It returns false if cidr is an empty string, an IPv4 CIDR, or anything else that is not a single valid IPv6 CIDR.

func IsIPv6String

func IsIPv6String(ip string) bool

IsIPv6String returns true if ip contains a single IPv6 address and nothing else. It returns false if ip is an empty string, an IPv4 address, or anything else that is not a single IPv6 address.

func MultiListen

func MultiListen(ctx context.Context, network string, addrs ...string) (net.Listener, error)

MultiListen returns net.Listener which can listen on and accept connections for the given network on multiple addresses. Internally it uses stdlib to create sub-listener and multiplexes connection requests using go-routines. The network must be "tcp", "tcp4" or "tcp6". It follows the semantics of net.Listen that primarily means:

  1. If the host is an unspecified/zero IP address with "tcp" network, MultiListen listens on all available unicast and anycast IP addresses of the local system.
  2. Use "tcp4" or "tcp6" to exclusively listen on IPv4 or IPv6 family, respectively.
  3. The host can accept names (e.g, localhost) and it will create a listener for at most one of the host's IP.

func ParseCIDRs

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

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

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

Closeable closes an opened LocalPort.

type Closeable interface {
    Close() error
}

type IPFamily

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

type IPFamily string

Constants for valid IPFamilys:

const (
    IPFamilyUnknown IPFamily = ""

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

func IPFamilyOf

func IPFamilyOf(ip net.IP) IPFamily

IPFamilyOf returns the IP family of ip, or IPFamilyUnknown if it is invalid.

func IPFamilyOfCIDR

func IPFamilyOfCIDR(cidr *net.IPNet) IPFamily

IPFamilyOfCIDR returns the IP family of cidr.

func IPFamilyOfCIDRString

func IPFamilyOfCIDRString(cidr string) IPFamily

IPFamilyOfCIDRString returns the IP family of cidr.

func IPFamilyOfString

func IPFamilyOfString(ip string) IPFamily

IPFamilyOfString returns the IP family of ip, or IPFamilyUnknown if ip cannot be parsed as an IP.

type IPNetSet

IPNetSet maps string to net.IPNet.

type IPNetSet map[string]*net.IPNet

func ParseIPNets

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

ParseIPNets parses string slice to IPNetSet.

func (IPNetSet) Delete

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

Delete removes all items from the set.

func (IPNetSet) Difference

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

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

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

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

func (IPNetSet) HasAll

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

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

Insert adds items to the set.

func (IPNetSet) IsSuperset

func (s IPNetSet) IsSuperset(s2 IPNetSet) bool

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

func (IPNetSet) Len

func (s IPNetSet) Len() int

Len returns the size of the set.

func (IPNetSet) StringSlice

func (s IPNetSet) StringSlice() []string

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

type IPSet

IPSet maps string to net.IP

type IPSet map[string]net.IP

func ParseIPSet

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

ParseIPSet parses string slice to IPSet

func (IPSet) Delete

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

Delete removes all items from the set.

func (IPSet) Difference

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

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

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

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

func (IPSet) HasAll

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

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

Insert adds items to the set.

func (IPSet) IsSuperset

func (s IPSet) IsSuperset(s2 IPSet) bool

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

func (IPSet) Len

func (s IPSet) Len() int

Len returns the size of the set.

func (IPSet) StringSlice

func (s IPSet) StringSlice() []string

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

type LocalPort

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.

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
}

Example

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

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

func (lp *LocalPort) String() string

type PortOpener

PortOpener can open a LocalPort and allows later closing it.

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

type Protocol

Protocol is a network protocol support by LocalPort.

type Protocol string

Constants for valid protocols:

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

Subdirectories

Name Synopsis
..
ebtables Package ebtables allows to control the ebtables Linux-based bridging firewall.