gont

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 36 Imported by: 3

Documentation

Index

Constants

View Source
const (
	WithQdiscNetem = (1 << iota)
	WithQdiscTbf   = (1 << iota)
)

Variables

View Source
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),
	}
)
View Source
var (
	IPv4loopback = net.IPv4(127, 0, 0, 1)
)
View Source
var (
	Names = []string{}/* 120 elements not displayed */

)

Functions

func CheckCaps

func CheckCaps() error

CheckCaps checks if the current process has the required privileges to run Gont

func Exec

func Exec(network, node string, args []string) error

func GenerateNetworkName

func GenerateNetworkName() string

func GetRandomName

func GetRandomName() string

func Identify

func Identify() (string, string, error)

Identify returns the network and node name if the current process is running in a network netspace created by Gont

func NetworkNames added in v0.2.0

func NetworkNames() []string

func NodeNames added in v0.2.0

func NodeNames(network string) []string

func TeardownAllNetworks added in v0.1.0

func TeardownAllNetworks() error

func TeardownNetwork added in v0.1.0

func TeardownNetwork(name string) error

func TestConnectivity

func TestConnectivity(hosts ...*Host) error

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
	ExistingNamespace       string
	ExistingDockerContainer string
	LogToDebug              bool
	// contains filtered or unexported fields
}

func (*BaseNode) AddDefaultRoute added in v0.2.0

func (n *BaseNode) AddDefaultRoute(gw net.IP) error

AddDefaultRoute adds a default route for this node by providing a default gateway.

func (*BaseNode) AddInterface added in v0.2.0

func (n *BaseNode) AddInterface(i *Interface)

AddInterface adds an interface to the list of configured interfaces

func (*BaseNode) AddRoute

func (n *BaseNode) AddRoute(r *nl.Route) error

AddRoute adds a route to the node.

func (*BaseNode) Close added in v1.2.0

func (n *BaseNode) Close() error

func (*BaseNode) Command

func (n *BaseNode) Command(name string, args ...string) *exec.Cmd

func (*BaseNode) ConfigureInterface added in v0.2.0

func (n *BaseNode) ConfigureInterface(i *Interface) error

func (*BaseNode) EnableForwarding

func (n *BaseNode) EnableForwarding() error

EnableForwarding enables forwarding for both IPv4 and IPv6 protocols in the kernel for all interfaces

func (*BaseNode) Interface added in v0.2.0

func (n *BaseNode) Interface(name string) *Interface

func (*BaseNode) LinkAddAddress added in v0.1.0

func (n *BaseNode) LinkAddAddress(name string, addr net.IPNet) error

LinkAddAddress adds a network layer address to a link identified by its name.

func (*BaseNode) Name

func (n *BaseNode) Name() string

func (*BaseNode) NetNSHandle added in v0.2.0

func (n *BaseNode) NetNSHandle() netns.NsHandle

func (*BaseNode) NetlinkHandle added in v0.2.0

func (n *BaseNode) NetlinkHandle() *nl.Handle

func (*BaseNode) Network

func (n *BaseNode) Network() *Network

Network returns the network to which this node belongs

func (*BaseNode) NftConn added in v0.3.0

func (n *BaseNode) NftConn() *nft.Conn

func (*BaseNode) Run

func (n *BaseNode) Run(cmd string, args ...any) ([]byte, *exec.Cmd, error)

func (*BaseNode) RunGo added in v0.2.0

func (n *BaseNode) RunGo(script string, args ...any) ([]byte, *exec.Cmd, error)

func (*BaseNode) Start added in v0.1.0

func (n *BaseNode) Start(cmd string, args ...any) (io.Reader, io.Reader, *exec.Cmd, error)

func (*BaseNode) StartGo added in v0.2.0

func (n *BaseNode) StartGo(script string, args ...any) (io.Reader, io.Reader, *exec.Cmd, error)

func (*BaseNode) String added in v0.2.0

func (n *BaseNode) String() string

func (*BaseNode) Teardown

func (n *BaseNode) Teardown() error

func (*BaseNode) WriteProcFS

func (n *BaseNode) WriteProcFS(path, value string) error

WriteProcFS write a value to a path within the ProcFS by entering the namespace of this node.

type BridgeOption added in v0.1.0

type BridgeOption interface {
	Apply(b *nl.Bridge)
}

type Callback

type Callback func() error

type Capture added in v1.2.0

type Capture struct {
	CaptureLength int
	Promisc       bool
	Filter        CaptureFilterInterfaceFunc
	BPFilter      string
	Comment       string

	File     *os.File
	Filename string
	// contains filtered or unexported fields
}

func NewCapture added in v1.2.0

func NewCapture() *Capture

func (*Capture) Apply added in v1.2.0

func (c *Capture) Apply(i *Interface)

func (*Capture) Close added in v1.2.0

func (c *Capture) Close() error

func (*Capture) Flush added in v1.2.0

func (c *Capture) Flush() error

func (*Capture) Reader added in v1.2.0

func (c *Capture) Reader() (*pcapgo.NgReader, error)

func (*Capture) Start added in v1.2.0

func (c *Capture) Start(i *Interface) error

type CaptureFilterInterfaceFunc added in v1.2.0

type CaptureFilterInterfaceFunc func(i *Interface) bool

type CaptureOption added in v1.2.0

type CaptureOption interface {
	Apply(c *Capture)
}

type DeviceGroup

type DeviceGroup int
const (
	DeviceGroupDefault    DeviceGroup = 0
	DeviceGroupSouthBound DeviceGroup = 1000 + iota
	DeviceGroupNorthBound
)

type Filter added in v0.3.0

type Filter struct {
	Family nft.TableFamily
	Table  *nft.Table

	Input   *nft.Chain
	Output  *nft.Chain
	Forward *nft.Chain
	// contains filtered or unexported fields
}

func NewFilter added in v0.3.0

func NewFilter(c *nft.Conn) (*Filter, error)

func (*Filter) AddRule added in v0.3.0

func (f *Filter) AddRule(h FilterHook, exprs ...expr.Any)

func (*Filter) Flush added in v0.3.0

func (f *Filter) Flush() error

type FilterHook added in v0.3.0

type FilterHook int
const (
	FilterInput FilterHook = iota
	FilterOutput
	FilterForward
)

type FilterRule added in v0.3.0

type FilterRule struct {
	Exprs []expr.Any

	Hook FilterHook
}

func (FilterRule) Apply added in v0.3.0

func (fr FilterRule) Apply(h *Host)

type Host

type Host struct {
	*BaseNode

	Filter *Filter

	// Options
	FilterRules []*FilterRule
	Routes      []*nl.Route
	Forwarding  bool
}

func HostNode

func HostNode(n *Network) *Host

func (*Host) Apply

func (h *Host) Apply(i *Interface)

Options

func (*Host) ConfigureInterface

func (h *Host) ConfigureInterface(i *Interface) error
func (h *Host) ConfigureLinks() error

ConfigureLinks adds links to other nodes which have been configured by functional options

func (*Host) LookupAddress added in v0.1.0

func (h *Host) LookupAddress(n string) *net.IPAddr

func (*Host) Ping

func (h *Host) Ping(o *Host) (*ping.Statistics, error)

func (*Host) PingWithNetwork added in v0.1.0

func (h *Host) PingWithNetwork(o *Host, net string) (*ping.Statistics, error)

func (*Host) PingWithOptions added in v0.1.0

func (h *Host) PingWithOptions(o *Host, net string, count int, timeout time.Duration, intv time.Duration, output bool) (*ping.Statistics, error)

func (*Host) Traceroute

func (h *Host) Traceroute(o *Host, opts ...any) error

type HostOption

type HostOption interface {
	Option
	Apply(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 (*Interface) Apply

func (i *Interface) Apply(n *BaseNode)

func (*Interface) Configure

func (i *Interface) Configure() error

func (Interface) IsLoopback added in v0.2.0

func (i Interface) IsLoopback() bool

func (Interface) String

func (i Interface) String() string

type InterfaceOption

type InterfaceOption interface {
	Option
	Apply(i *Interface)
}

type LinkOption

type LinkOption interface {
	Option
	Apply(la *nl.LinkAttrs)
}

type NAT

type NAT struct {
	*Router
	// contains filtered or unexported fields
}

func (*NAT) Apply added in v0.2.0

func (n *NAT) Apply(i *Interface)

func (*NAT) ConfigureInterface added in v0.2.0

func (n *NAT) ConfigureInterface(i *Interface) error

type NATOption

type NATOption interface {
	Option
	Apply(n *NAT)
}

type Namespace

type Namespace struct {
	netns.NsHandle

	Name string
	// contains filtered or unexported fields
}

func NewNamespace

func NewNamespace(name string) (*Namespace, error)

func (*Namespace) Close

func (ns *Namespace) Close() error

func (*Namespace) Enter added in v0.1.0

func (ns *Namespace) Enter() (func(), error)

func (*Namespace) RunFunc

func (ns *Namespace) RunFunc(cb Callback) error

type Network

type Network struct {
	Name string

	Nodes     map[string]Node
	NodesLock sync.RWMutex

	HostNode *Host
	BasePath string

	// Options
	Persistent bool
	NSPrefix   string
	Captures   []*Capture
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork(name string, opts ...Option) (*Network, error)

func (*Network) AddHost

func (n *Network) AddHost(name string, opts ...Option) (*Host, error)

func (*Network) AddHostNAT

func (n *Network) AddHostNAT(name string, opts ...Option) (*NAT, error)
func (n *Network) AddLink(l, r *Interface, opts ...Option) error

func (*Network) AddNAT

func (n *Network) AddNAT(name string, opts ...Option) (*NAT, error)

func (*Network) AddNode

func (n *Network) AddNode(name string, opts ...Option) (*BaseNode, error)

func (*Network) AddRouter

func (n *Network) AddRouter(name string, opts ...Option) (*Router, error)

func (*Network) AddSwitch

func (n *Network) AddSwitch(name string, opts ...Option) (*Switch, error)

AddSwitch adds a new Linux virtual bridge in a dedicated namespace

func (*Network) Close

func (n *Network) Close() error

func (*Network) GenerateConfigFiles added in v0.2.0

func (n *Network) GenerateConfigFiles() error

func (*Network) GenerateHostsFile added in v0.2.0

func (n *Network) GenerateHostsFile() error

GenerateHostsFile writes the addresses and hostnames 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 added in v0.2.0

func (n *Network) GenerateIProute2Files() error

func (*Network) Hosts added in v0.1.0

func (n *Network) Hosts() []*Host

func (*Network) Register added in v0.2.0

func (n *Network) Register(m Node)

func (*Network) Routers added in v0.1.0

func (n *Network) Routers() []*Router

func (*Network) String added in v0.2.0

func (n *Network) String() string

func (*Network) Switches added in v0.1.0

func (n *Network) Switches() []*Switch

func (*Network) Teardown

func (n *Network) Teardown() error

type NetworkOption

type NetworkOption interface {
	Option
	Apply(n *Network)
}

type Node

type Node interface {
	Close() error
	Teardown() error

	// Getters
	Name() string
	String() string
	Network() *Network
	Interface(name string) *Interface
	NetNSHandle() netns.NsHandle
	NetlinkHandle() *nl.Handle

	RunFunc(cb Callback) error

	ConfigureInterface(i *Interface) error
}

type NodeOption

type NodeOption interface {
	Option
	Apply(b *BaseNode)
}

type Option

type Option any

type Options

type Options []Option

type Route added in v0.2.3

type Route struct {
	nl.Route
}

func (Route) Apply added in v0.2.3

func (r Route) Apply(h *Host)

type Router

type Router struct {
	*Host
}

func (*Router) Apply added in v0.2.0

func (h *Router) Apply(i *Interface)

type Switch

type Switch struct {
	*BaseNode
}

Switch is an abstraction for a Linux virtual bridge

func (*Switch) Apply

func (sw *Switch) Apply(i *Interface)

func (*Switch) ConfigureInterface added in v0.2.0

func (sw *Switch) ConfigureInterface(i *Interface) error

ConfigureInterface attaches an existing interface to a bridge interface

type SwitchOption

type SwitchOption interface {
	Option
	Apply(sw *Switch)
}

type VethOption

type VethOption interface {
	Option
	Apply(v *nl.Veth)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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