Documentation ¶
Index ¶
- Constants
- Variables
- func CheckCaps() error
- func Exec(network, node string, args []string) error
- func GenerateNetworkName() string
- func GetRandomName() string
- func Identify() (string, string, error)
- func NetworkNames() []string
- func NodeNames(network string) []string
- func SerializePacket(t *trace.Event) (data []byte, ci gopacket.CaptureInfo, err error)
- func TeardownAllNetworks() error
- func TeardownNetwork(network string) error
- func TeardownNode(network, node 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 Callback
- type Capture
- type CaptureCallbackFunc
- type CaptureFilterInterfaceFunc
- type CaptureFilterPacketFunc
- type CaptureOption
- type CapturePacket
- type Cmd
- type CmdOption
- type Debugger
- 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) (*ping.Statistics, error)
- func (h *Host) PingWithNetwork(o *Host, net string) (*ping.Statistics, error)
- func (h *Host) PingWithOptions(o *Host, net string, count int, timeout time.Duration, intv time.Duration, ...) (*ping.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) (*Host, error)
- func (n *Network) AddHostNAT(name string, opts ...Option) (*NAT, 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) (*BaseNode, 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) GenerateConfigFiles() error
- func (n *Network) GenerateHostsFile() error
- func (n *Network) GenerateIProute2Files() error
- func (n *Network) Hosts() []*Host
- func (n *Network) KeyLogPipe(secretsType uint32) (*os.File, error)
- 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 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 IPv4loopback = net.IPv4(127, 0, 0, 1) //nolint:gochecknoglobals
IPv4loopback is the IPv4 loopback address (127.0.0.1)
var Names = []string{}/* 120 elements not displayed */
Names is a list of well known persons in information theory / networking From: https://en.wikipedia.org/wiki/List_of_Internet_pioneers and https://www.internethalloffame.org/inductees/all
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 GetRandomName ¶
func GetRandomName() string
func Identify ¶
Identify returns the network and node name if the current process is running in a network netspace created by Gont
func NetworkNames ¶
func NetworkNames() []string
func SerializePacket ¶
func TeardownAllNetworks ¶
func TeardownAllNetworks() error
func TeardownNetwork ¶
func TeardownNode ¶
func TestConnectivity ¶
TestConnectivity performs ICMP ping tests between all pairs of nodes in the network
Types ¶
type BaseNode ¶
type BaseNode struct { *Namespace BasePath string Interfaces []*Interface // Options ConfiguredInterfaces []*Interface Tracer *Tracer Debugger *Debugger ExistingNamespace string ExistingDockerContainer 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 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
func (CapturePacket) Time ¶
func (p CapturePacket) Time() time.Time
type Cmd ¶
type Cmd struct { *exec.Cmd // Options Tracer *Tracer Debugger *Debugger RedirectToLog bool DisableASLR bool Context context.Context 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 DeviceGroup ¶
type DeviceGroup uint32
const ( DeviceGroupDefault DeviceGroup = 0 DeviceGroupSouthBound DeviceGroup = 1000 + iota DeviceGroupNorthBound )
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 NewNamespace ¶
type Network ¶
type Network struct { Name string HostNode *Host VarPath string TmpPath string // Options Persistent bool NSPrefix string Captures []*Capture Debugger *Debugger Tracer *Tracer RedirectToLog bool // contains filtered or unexported fields }
func NewNetwork ¶
func NewNetwork(name string, opts ...NetworkOption) (*Network, error)
func (*Network) AddHostNAT ¶
func (*Network) ForEachHost ¶
func (*Network) GenerateConfigFiles ¶
func (*Network) GenerateHostsFile ¶
GenerateHostsFile writes the addresses and host names of all nodes into a file located at /run/gont/<network>/files/etc/hosts
Processes started via BaseNode.Run or BaseNode.Start, will see this file bind mounted at /etc/hosts
func (*Network) GenerateIProute2Files ¶
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 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) 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
- cmd.go
- debug_others.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
Directories ¶
Path | Synopsis |
---|---|
Package options contains all the general options for configuring the general objects like hosts, switches, routers and interfaces
|
Package options contains all the general options for configuring the general objects like hosts, switches, routers and interfaces |
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 |