Documentation ¶
Index ¶
- Constants
- Variables
- func CheckCaps() error
- func Exec(network, node string, args []string) error
- func GenerateNetworkName() string
- func Identify() (string, string, error)
- func NetworkCGroups() []string
- func NetworkNames() []string
- func NodeNames(network string) []string
- func RandomName() string
- func RandomNames(yield func(string) bool)
- func SerializePacket(t *trace.Event) (data []byte, ci gopacket.CaptureInfo, err error)
- func TeardownNetwork(ctx context.Context, c *dbus.Conn, network string) error
- func TeardownNode(ctx context.Context, c *dbus.Conn, network, node string) error
- func TeardownStaleCgroups(ctx context.Context, c *dbus.Conn) ([]string, error)
- func TestConnectivity(hosts ...*Host) error
- func Unshare(network, node string) error
- type BaseNode
- func (n *BaseNode) AddDefaultRoute(gw net.IP) error
- func (n *BaseNode) AddInterface(i *Interface)
- func (n *BaseNode) AddRoute(r *nl.Route) error
- func (n *BaseNode) BuildGo(fileOrPkg string, args ...any) (*os.File, error)
- func (n *BaseNode) Close() error
- func (n *BaseNode) Command(name string, args ...any) *Cmd
- func (n *BaseNode) ConfigureInterface(i *Interface) error
- func (n *BaseNode) EnableForwarding() error
- func (n *BaseNode) Interface(name string) *Interface
- func (n *BaseNode) Name() string
- func (n *BaseNode) NetNSHandle() netns.NsHandle
- func (n *BaseNode) NetlinkHandle() *nl.Handle
- func (n *BaseNode) Network() *Network
- func (n *BaseNode) NftConn() *nft.Conn
- func (n *BaseNode) Run(cmd string, args ...any) (*Cmd, error)
- func (n *BaseNode) RunGo(fileOrPkg string, args ...any) (*Cmd, error)
- func (n *BaseNode) Start(cmd string, args ...any) (*Cmd, error)
- func (n *BaseNode) StartGo(fileOrPkg string, args ...any) (*Cmd, error)
- func (n *BaseNode) String() string
- func (n *BaseNode) Teardown() error
- func (n *BaseNode) WriteProcFS(path, value string) error
- type BaseNodeOption
- type BridgeOption
- type CGroup
- type CGroupOption
- type Callback
- type Capture
- type CaptureCallbackFunc
- type CaptureFilterInterfaceFunc
- type CaptureFilterPacketFunc
- type CaptureOption
- type CapturePacket
- type Cmd
- type CmdOption
- type Debugger
- type DebuggerOption
- type DeviceGroup
- type ExecCmdOption
- type Filter
- type FilterHook
- type FilterRule
- type GoBuildFlags
- type GoBuildFlagsOption
- type Host
- func (h *Host) ApplyInterface(i *Interface)
- func (h *Host) ConfigureInterface(i *Interface) error
- func (h *Host) ConfigureLinks() error
- func (h *Host) LookupAddress(n string) *net.IPAddr
- func (h *Host) Ping(o *Host) (*probing.Statistics, error)
- func (h *Host) PingWithNetwork(o *Host, net string) (*probing.Statistics, error)
- func (h *Host) PingWithOptions(o *Host, net string, count int, timeout time.Duration, intv time.Duration, ...) (*probing.Statistics, error)
- func (h *Host) Traceroute(o *Host, opts ...any) error
- type HostOption
- type Interface
- func (i *Interface) AddAddress(a *net.IPNet) error
- func (i *Interface) ApplyBaseNode(n *BaseNode)
- func (i *Interface) Close() error
- func (i *Interface) DeleteAddress(a *net.IPNet) error
- func (i Interface) IsLoopback() bool
- func (i *Interface) SetDown() error
- func (i *Interface) SetUp() error
- func (i Interface) String() string
- type InterfaceOption
- type LinkOption
- type NAT
- type NATOption
- type Namespace
- type Network
- func (n *Network) AddHost(name string, opts ...Option) (h *Host, err error)
- func (n *Network) AddLink(l, r *Interface, opts ...Option) error
- func (n *Network) AddNAT(name string, opts ...Option) (*NAT, error)
- func (n *Network) AddNode(name string, opts ...Option) (node *BaseNode, err error)
- func (n *Network) AddRouter(name string, opts ...Option) (*Router, error)
- func (n *Network) AddSwitch(name string, opts ...Option) (*Switch, error)
- func (n *Network) Close() error
- func (n *Network) ForEachHost(cb func(h *Host))
- func (n *Network) Hosts() []*Host
- func (n *Network) KeyLogPipe(secretsType uint32) (*os.File, error)
- func (n *Network) MustClose()
- func (n *Network) Nodes() []Node
- func (n *Network) Register(m Node)
- func (n *Network) Routers() []*Router
- func (n *Network) String() string
- func (n *Network) Switches() []*Switch
- func (n *Network) Teardown() error
- func (n *Network) WriteHostsFile(f io.Writer) error
- type NetworkOption
- type Node
- type Option
- type Router
- type RouterOption
- type Switch
- type SwitchOption
- type TraceOption
- type Tracepoint
- type TracepointOption
- type Tracer
- type VethOption
Constants ¶
const ( LinkTypeUser0 = 147 LinkTypeTrace = LinkTypeUser0 )
const ( WithQdiscNetem = (1 << iota) WithQdiscTbf = (1 << iota) )
const CGoPCAP = true
Variables ¶
var ( DefaultIPv4Mask = net.IPNet{ IP: net.IPv4zero, Mask: net.CIDRMask(0, net.IPv4len*8), } DefaultIPv6Mask = net.IPNet{ IP: net.IPv6zero, Mask: net.CIDRMask(0, net.IPv6len*8), } )
var DefaultPreserveEnvVars = []string{
"PATH",
}
var ErrInvalidName = errors.New("invalid name")
var ErrNameReserved = errors.New("name 'host' is reserved")
var GlobalOptions []Option //nolint:gochecknoglobals
var IPv4loopback = net.IPv4(127, 0, 0, 1) //nolint:gochecknoglobals
IPv4loopback is the IPv4 loopback address (127.0.0.1)
var Names = []string{}/* 226 elements not displayed */
Names is a list of well known persons in information theory / networking From:
Functions ¶
func CheckCaps ¶
func CheckCaps() error
CheckCaps checks if the current process has the required privileges to run Gont
func GenerateNetworkName ¶
func GenerateNetworkName() string
func Identify ¶
Identify returns the network and node name if the current process is running in a network netspace created by Gont
func NetworkCGroups ¶ added in v2.10.0
func NetworkCGroups() []string
func NetworkNames ¶
func NetworkNames() []string
func RandomName ¶ added in v2.10.0
func RandomName() string
func RandomNames ¶ added in v2.10.0
func SerializePacket ¶
func TeardownNetwork ¶
func TeardownNode ¶
func TeardownStaleCgroups ¶ added in v2.10.0
TeardownStaleCgroups deletes all stale CGroup slices for which no corresponding Gont network exists.
func TestConnectivity ¶
TestConnectivity performs ICMP ping tests between all pairs of nodes in the network
Types ¶
type BaseNode ¶
type BaseNode struct { *Namespace *CGroup VarPath string Interfaces []*Interface // Options ConfiguredInterfaces []*Interface Tracer *Tracer Debugger *Debugger ExistingNetworkNamespace string ExistingDockerContainer string Slice string RedirectToLog bool EmptyDirs []string Captures []*Capture // contains filtered or unexported fields }
func (*BaseNode) AddDefaultRoute ¶
AddDefaultRoute adds a default route for this node by providing a default gateway.
func (*BaseNode) AddInterface ¶
AddInterface adds an interface to the list of configured interfaces
func (*BaseNode) ConfigureInterface ¶
func (*BaseNode) EnableForwarding ¶
EnableForwarding enables forwarding for both IPv4 and IPv6 protocols in the kernel for all interfaces
func (*BaseNode) NetNSHandle ¶
func (*BaseNode) NetlinkHandle ¶
func (*BaseNode) WriteProcFS ¶
WriteProcFS write a value to a path within the ProcFS by entering the namespace of this node.
type BaseNodeOption ¶
type BaseNodeOption interface {
ApplyBaseNode(n *BaseNode)
}
type BridgeOption ¶
type CGroup ¶ added in v2.10.0
type CGroup struct { Name string Type string Properties []dbus.Property // contains filtered or unexported fields }
func (*CGroup) Freeze ¶ added in v2.10.0
Freeze suspends execution of all processes in the control group.
func (*CGroup) SetProperties ¶ added in v2.10.0
func (g *CGroup) SetProperties(opts ...CGroupOption) error
SetProperties sets transient systemd CGroup properties of the unit. See: https://systemd.io/TRANSIENT-SETTINGS/
type CGroupOption ¶ added in v2.10.0
type CGroupOption interface {
ApplyCGroup(s *CGroup)
}
type Capture ¶
type Capture struct { // Options SnapshotLength int Promiscuous bool Comment string Timeout time.Duration LogKeys bool FlushEach uint64 // Filter options FilterInterface CaptureFilterInterfaceFunc FilterPackets CaptureFilterPacketFunc FilterExpression string FilterInstructions []bpf.Instruction // Output options Files []*os.File Filenames []string Channels []chan CapturePacket Callbacks []CaptureCallbackFunc Pipenames []string ListenAddrs []string // contains filtered or unexported fields }
func NewCapture ¶
func NewCapture(opts ...CaptureOption) *Capture
func (*Capture) ApplyBaseNode ¶
func (*Capture) ApplyInterface ¶
func (*Capture) ApplyNetwork ¶
func (*Capture) ApplyTracer ¶
type CaptureCallbackFunc ¶
type CaptureCallbackFunc func(pkt CapturePacket)
type CaptureFilterPacketFunc ¶
type CaptureFilterPacketFunc func(p *CapturePacket) bool
type CaptureOption ¶
type CaptureOption interface {
ApplyCapture(n *Capture)
}
type CapturePacket ¶
type CapturePacket struct { gopacket.CaptureInfo Data []byte Interface *captureInterface }
func (CapturePacket) Decode ¶
func (p CapturePacket) Decode(dOpts gopacket.DecodeOptions) gopacket.Packet
type Cmd ¶
type Cmd struct { *CGroup *exec.Cmd // Options Tracer *Tracer Debugger *Debugger RedirectToLog bool DisableASLR bool Context context.Context PreserveEnvVars []string Slice string Scope string CGroupOptions []Option StdoutWriters []io.Writer StderrWriters []io.Writer // contains filtered or unexported fields }
func (*Cmd) CombinedOutput ¶
CombinedOutput runs the command and returns its combined standard output and standard error.
func (*Cmd) StderrPipe ¶
func (c *Cmd) StderrPipe() (io.ReadCloser, error)
func (*Cmd) StdoutPipe ¶
func (c *Cmd) StdoutPipe() (io.ReadCloser, error)
type Debugger ¶
type Debugger struct { // Options BreakOnEntry bool DetachOnExit bool Tracepoints []Tracepoint Tracers []*Tracer ListenAddr string DebugInfoDirectories []string // contains filtered or unexported fields }
func NewDebugger ¶
func NewDebugger(opts ...DebuggerOption) *Debugger
func (*Debugger) ApplyBaseNode ¶
func (*Debugger) ApplyNetwork ¶
func (*Debugger) WriteVSCodeConfigs ¶
WriteVSCodeConfigs generates Visual Studio Code Launch and Task configuration files (tasks.json, launch.json) in the given workspace directory. The launch configuration is dynamically generated from the current active Delve debugger instances If an empty dir is passed, we attempt to find the workspace directory by searching for a parent directory which contains either a .vscode, go.mod or .git
type DebuggerOption ¶
type DebuggerOption interface {
ApplyDebugger(*Debugger)
}
type DeviceGroup ¶
type DeviceGroup uint32
const ( DeviceGroupDefault DeviceGroup = 0 DeviceGroupSouthBound DeviceGroup = 1000 DeviceGroupNorthBound DeviceGroup = 1001 )
type ExecCmdOption ¶
type Filter ¶
type FilterHook ¶
type FilterHook int
const ( FilterInput FilterHook = iota FilterOutput FilterForward )
type FilterRule ¶
type FilterRule struct { Exprs []expr.Any Hook FilterHook }
func (FilterRule) ApplyHost ¶
func (fr FilterRule) ApplyHost(h *Host)
type GoBuildFlags ¶
type GoBuildFlags []string
type GoBuildFlagsOption ¶
type GoBuildFlagsOption interface {
ApplyGoBuildFlags(*GoBuildFlags)
}
type Host ¶
type Host struct { *BaseNode Filter *Filter // Options FilterRules []*FilterRule Routes []*nl.Route }
func (*Host) ConfigureInterface ¶
func (*Host) ConfigureLinks ¶
ConfigureLinks adds links to other nodes which have been configured by functional options
func (*Host) PingWithNetwork ¶
func (*Host) PingWithOptions ¶
type HostOption ¶
type HostOption interface {
ApplyHost(h *Host)
}
type Interface ¶
type Interface struct { Name string Node Node Link nl.Link Flags int // Options Netem nl.NetemQdiscAttrs Tbf nl.Tbf EnableDAD bool LinkAttrs nl.LinkAttrs Addresses []net.IPNet Captures []*Capture }
func NewInterface ¶
func (*Interface) ApplyBaseNode ¶
func (Interface) IsLoopback ¶
type InterfaceOption ¶
type InterfaceOption interface {
ApplyInterface(n *Interface)
}
type LinkOption ¶
type NAT ¶
type NAT struct { *Router Table *nft.Table Input *nft.Chain Forward *nft.Chain PostRouting *nft.Chain // Options Persistent bool Random bool FullyRandom bool SourcePortMin int SourcePortMax int }
func (*NAT) ApplyInterface ¶
type Namespace ¶
func HostNamespace ¶ added in v2.10.0
HostNamespace creates
func NewNamespace ¶
NewNamespace creates a new named network namespace.
func (*Namespace) Enter ¶
Enter locks the current Goroutine to an OS thread by calling runtime.LockOSThread(). and afterwards attaches the calling Goroutines thread to the namespace. The returned function should be called to move the thread back to the original namespace and unlock the Goroutine from the OS thread.
func (*Namespace) IsHost ¶ added in v2.10.0
IsHost returns true if the namespace is representing the hosts default network namespace.
type Network ¶
type Network struct { *CGroup Name string VarPath string TmpPath string // For storing temporart Go build artifacts (see RunGo()) // Options Persistent bool Captures []*Capture Debugger *Debugger Tracer *Tracer RedirectToLog bool Slice string // contains filtered or unexported fields }
func (*Network) ForEachHost ¶
type NetworkOption ¶
type NetworkOption interface {
ApplyNetwork(n *Network)
}
type RouterOption ¶
type RouterOption interface {
ApplyRouter(r *Router)
}
type Switch ¶
type Switch struct {
*BaseNode
}
Switch is an abstraction for a Linux virtual bridge
func (*Switch) ApplyInterface ¶
func (*Switch) ConfigureInterface ¶
ConfigureInterface attaches an existing interface to a bridge interface
type SwitchOption ¶
type SwitchOption interface {
ApplySwitch(sw *Switch)
}
type TraceOption ¶
type TraceOption interface {
ApplyTracer(t *Tracer)
}
type Tracepoint ¶
type Tracepoint struct { // Options api.Breakpoint Location string Message string }
func NewTracepoint ¶
func NewTracepoint(opts ...TracepointOption) Tracepoint
func (Tracepoint) ApplyDebugger ¶
func (tp Tracepoint) ApplyDebugger(d *Debugger)
func (*Tracepoint) IsWatchpoint ¶
func (tp *Tracepoint) IsWatchpoint() bool
type TracepointOption ¶
type TracepointOption interface {
ApplyTracepoint(*Tracepoint)
}
type Tracer ¶
type Tracer struct { // Output options Files []*os.File Filenames []string Channels []chan trace.Event Callbacks []trace.EventCallback Captures []*Capture // contains filtered or unexported fields }
func NewTracer ¶
func NewTracer(opts ...TraceOption) *Tracer
func (*Tracer) ApplyBaseNode ¶
func (*Tracer) ApplyDebugger ¶
func (*Tracer) ApplyNetwork ¶
type VethOption ¶
Source Files ¶
- base_node.go
- base_node_run.go
- capture.go
- capture_interface.go
- capture_listener.go
- capture_packet.go
- capture_pcap.go
- capture_trace.go
- cgroup.go
- cmd.go
- debug.go
- debug_instance.go
- debug_instance_breakpoint.go
- debug_msg.go
- debug_tracepoint.go
- debug_vscode.go
- exec.go
- gont.go
- groups.go
- host.go
- host_filter.go
- host_ping.go
- interface.go
- link.go
- names.go
- namespace.go
- nat.go
- network.go
- network_files.go
- node.go
- route.go
- router.go
- switch.go
- teardown.go
- trace.go
- trace_debug.go
Directories ¶
Path | Synopsis |
---|---|
capture
Package capture contains the options to configure to packet capturing
|
Package capture contains the options to configure to packet capturing |
filters
Package filters contains the options for configuring NFTables filtering
|
Package filters contains the options for configuring NFTables filtering |
tc
Package tc contains the options for configuring per-interface Traffic Control (TC) queuing disciplines
|
Package tc contains the options for configuring per-interface Traffic Control (TC) queuing disciplines |