network

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 21 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ModeAdd    Mode   = "add"
	ModeDelete Mode   = "del"
	FamilyV4   Family = "inet"
	FamilyV6   Family = "inet6"
)

Variables

View Source
var (
	NetAnyIpv4 = net.IPNet{IP: net.IPv4zero, Mask: net.CIDRMask(0, 32)}
	NetAnyIpv6 = net.IPNet{IP: net.IPv6zero, Mask: net.CIDRMask(0, 128)}
	NetAny     = []net.IPNet{NetAnyIpv4, NetAnyIpv6}
)
View Source
var (
	PortRangeAny = PortRange{From: 1, To: 65534}
)

Functions

func Apply

func Apply(ctx context.Context, r runc.Runc, sidecar SidecarOpts, opts Opts) error

func FilterBatchErrors

func FilterBatchErrors(err error, mode Mode, cmds []string) error

func GetOwnIPs

func GetOwnIPs() []net.IP

func GetOwnNetworkInterfaces

func GetOwnNetworkInterfaces() []string

func HasCiliumIpRoutes added in v1.2.10

func HasCiliumIpRoutes(ctx context.Context, r runc.Runc, sidecar SidecarOpts) (bool, error)

func IpToNet

func IpToNet(ip net.IP) *net.IPNet

func IpsToNets added in v1.2.0

func IpsToNets(ips []net.IP) []net.IPNet

func ListNonLoopbackInterfaceNames added in v1.2.8

func ListNonLoopbackInterfaceNames(ctx context.Context, r runc.Runc, sidecar SidecarOpts) ([]string, error)

func ParseBatchError

func ParseBatchError(cmd []string, r io.Reader) error

func ParseCIDR added in v1.2.0

func ParseCIDR(s string) (*net.IPNet, error)

func ParseCIDRs added in v1.2.0

func ParseCIDRs(raw []string) ([]net.IPNet, []string)

func Resolve

func Resolve(ctx context.Context, hostnames ...string) ([]net.IP, error)

func Revert

func Revert(ctx context.Context, r runc.Runc, sidecar SidecarOpts, opts Opts) error

func ToReader

func ToReader(strs []string) io.Reader

Types

type AddrInfo added in v1.2.8

type AddrInfo struct {
	Family    string `json:"family"`
	Local     string `json:"local"`
	PrefixLen uint   `json:"prefixlen"`
	Scope     string `json:"scope"`
	Label     string `json:"label"`
	Broadcast string `json:"broadcast"`
}

type BatchError

type BatchError struct {
	Msg      string
	Lineno   int
	Filename string
}

func (*BatchError) Error

func (t *BatchError) Error() string

type BatchErrors

type BatchErrors struct {
	Cmd    []string
	Errors []BatchError
}

func (*BatchErrors) Error

func (t *BatchErrors) Error() string

type BlackholeOpts

type BlackholeOpts struct {
	Filter
	IpProto IpProto
}

func (*BlackholeOpts) IpCommands

func (o *BlackholeOpts) IpCommands(family Family, mode Mode) ([]string, error)

func (*BlackholeOpts) String

func (o *BlackholeOpts) String() string

func (*BlackholeOpts) TcCommands

func (o *BlackholeOpts) TcCommands(_ Mode) ([]string, error)

type CommandDigRunner

type CommandDigRunner struct {
}

func (*CommandDigRunner) Run

func (c *CommandDigRunner) Run(ctx context.Context, arg []string, stdin io.Reader) ([]byte, error)

type CorruptPackagesOpts

type CorruptPackagesOpts struct {
	Filter
	Corruption uint
	Interfaces []string
}

func (*CorruptPackagesOpts) IpCommands

func (o *CorruptPackagesOpts) IpCommands(_ Family, _ Mode) ([]string, error)

func (*CorruptPackagesOpts) String

func (o *CorruptPackagesOpts) String() string

func (*CorruptPackagesOpts) TcCommands

func (o *CorruptPackagesOpts) TcCommands(mode Mode) ([]string, error)

type DelayOpts

type DelayOpts struct {
	Filter
	Delay      time.Duration
	Jitter     time.Duration
	Interfaces []string
}

func (*DelayOpts) IpCommands

func (o *DelayOpts) IpCommands(_ Family, _ Mode) ([]string, error)

func (*DelayOpts) String

func (o *DelayOpts) String() string

func (*DelayOpts) TcCommands

func (o *DelayOpts) TcCommands(mode Mode) ([]string, error)

type DigRunner

type DigRunner interface {
	Run(ctx context.Context, arg []string, stdin io.Reader) ([]byte, error)
}

type ErrTooManyTcCommands added in v1.2.8

type ErrTooManyTcCommands struct {
	Count int
}

func (*ErrTooManyTcCommands) Error added in v1.2.8

func (e *ErrTooManyTcCommands) Error() string

type ExtraMount

type ExtraMount struct {
	Source string `json:"source"`
	Path   string `json:"path"`
}

type Family

type Family string

type Filter

type Filter struct {
	Include []NetWithPortRange
	Exclude []NetWithPortRange
}

type HostnameResolver

type HostnameResolver struct {
	Dig DigRunner
}

func (*HostnameResolver) Resolve

func (h *HostnameResolver) Resolve(ctx context.Context, hostnames ...string) ([]net.IP, error)

type Interface

type Interface struct {
	Index    uint       `json:"ifindex"`
	Name     string     `json:"ifname"`
	LinkType string     `json:"link_type"`
	Flags    []string   `json:"flags"`
	AddrInfo []AddrInfo `json:"addr_info"`
}

func ListInterfaces

func ListInterfaces(ctx context.Context, r runc.Runc, sidecar SidecarOpts) ([]Interface, error)

func (*Interface) HasFlag

func (i *Interface) HasFlag(f string) bool

type IpProto

type IpProto string
const IpProtoTcp IpProto = "tcp"
const IpProtoUdp IpProto = "udp"

type LimitBandwidthOpts

type LimitBandwidthOpts struct {
	Filter
	Bandwidth  string
	Interfaces []string
}

func (*LimitBandwidthOpts) IpCommands

func (o *LimitBandwidthOpts) IpCommands(_ Family, _ Mode) ([]string, error)

func (*LimitBandwidthOpts) String

func (o *LimitBandwidthOpts) String() string

func (*LimitBandwidthOpts) TcCommands

func (o *LimitBandwidthOpts) TcCommands(mode Mode) ([]string, error)

type Mode

type Mode string

type NetWithPortRange

type NetWithPortRange struct {
	Net       net.IPNet
	PortRange PortRange
	Comment   string
}

func ComputeExcludesForOwnIpAndPorts added in v1.2.8

func ComputeExcludesForOwnIpAndPorts(port, healthPort uint16) []NetWithPortRange

func CondenseNetWithPortRange added in v1.2.9

func CondenseNetWithPortRange(nwps []NetWithPortRange, limit int) []NetWithPortRange

CondenseNetWithPortRange condenses a list of NetWithPortRange The way this algorithm works: 1. Sort the nwp list ascending by BaseIP and port 2. For each nwp in the list create a new nwp with the next neighbor if port-ranges are compatible 3. From the new list choose the nwp with the longest prefix length, remove all nwp witch are included in the chosen and add the chosen nwp to the result list 4. Repeat 3. until either the list is shorter than limit or no more compatible nwp are found

func NewNetWithPortRanges

func NewNetWithPortRanges(nets []net.IPNet, portRanges ...PortRange) []NetWithPortRange

func (NetWithPortRange) Compare added in v1.2.9

func (nwp NetWithPortRange) Compare(b NetWithPortRange) int

func (NetWithPortRange) Contains added in v1.2.8

func (nwp NetWithPortRange) Contains(other NetWithPortRange) bool

Contains checks if the given NetWithPortRange is contained in the current NetWithPortRange

func (NetWithPortRange) Overlap added in v1.2.8

func (nwp NetWithPortRange) Overlap(other NetWithPortRange) bool

func (NetWithPortRange) String

func (nwp NetWithPortRange) String() string

type Opts

type Opts interface {
	IpCommands(family Family, mode Mode) ([]string, error)
	TcCommands(mode Mode) ([]string, error)
	String() string
}

type PackageLossOpts

type PackageLossOpts struct {
	Filter
	Loss       uint
	Interfaces []string
}

func (*PackageLossOpts) IpCommands

func (o *PackageLossOpts) IpCommands(_ Family, _ Mode) ([]string, error)

func (*PackageLossOpts) String

func (o *PackageLossOpts) String() string

func (*PackageLossOpts) TcCommands

func (o *PackageLossOpts) TcCommands(mode Mode) ([]string, error)

type PortRange

type PortRange struct {
	From uint16
	To   uint16
}

func ParsePortRange

func ParsePortRange(raw string) (PortRange, error)

func (*PortRange) Contains added in v1.2.8

func (p *PortRange) Contains(port uint16) bool

func (*PortRange) IsNeighbor added in v1.2.9

func (p *PortRange) IsNeighbor(other PortRange) bool

func (*PortRange) Merge added in v1.2.9

func (p *PortRange) Merge(other PortRange) PortRange

func (*PortRange) Overlap added in v1.2.8

func (p *PortRange) Overlap(other PortRange) bool

func (*PortRange) String

func (p *PortRange) String() string

type Route added in v1.2.10

type Route struct {
	Dst      string   `json:"dst"`
	Gateway  string   `json:"gateway"`
	Dev      string   `json:"dev"`
	Flags    []string `json:"flags"`
	Protocol string   `json:"protocol"`
	Prefsrc  string   `json:"prefsrc"`
	Scope    string   `json:"scope"`
}

type RuncDigRunner

type RuncDigRunner struct {
	Runc    runc.Runc
	Sidecar SidecarOpts
}

func (*RuncDigRunner) Run

func (r *RuncDigRunner) Run(ctx context.Context, arg []string, stdin io.Reader) ([]byte, error)

type SidecarOpts

type SidecarOpts struct {
	TargetProcess runc.LinuxProcessInfo
	IdSuffix      string
}

Jump to

Keyboard shortcuts

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