networkutils

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

func FilterBatchErrors added in v1.0.7

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

func GetOwnIPs

func GetOwnIPs() []net.IP

func GetOwnNetworkInterfaces

func GetOwnNetworkInterfaces() []string

func IpToNet

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

func ParseBatchError added in v1.0.7

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

func Resolve added in v1.0.4

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

func ToReader added in v1.0.1

func ToReader(strs []string) io.Reader

Types

type BatchError added in v1.0.7

type BatchError struct {
	Msg      string
	Lineno   int
	Filename string
}

func (*BatchError) Error added in v1.0.7

func (t *BatchError) Error() string

type BatchErrors added in v1.0.7

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

func (*BatchErrors) Error added in v1.0.7

func (t *BatchErrors) Error() string

type BlackholeOpts

type BlackholeOpts struct {
	Filter
}

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 added in v1.0.4

type CommandDigRunner struct {
}

func (*CommandDigRunner) Run added in v1.0.4

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 added in v1.0.4

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

type Family

type Family string

type Filter

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

type HostnameResolver added in v1.0.4

type HostnameResolver struct {
	Dig DigRunner
}

func (*HostnameResolver) Resolve added in v1.0.4

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

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
}

func NewNetWithPortRanges

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

func (NetWithPortRange) Equal added in v1.0.5

func (nwp NetWithPortRange) Equal(o 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) String

func (p *PortRange) String() string

Jump to

Keyboard shortcuts

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