Documentation ¶
Overview ¶
Package vnet provides a virtual (as opposed to mocked) implementation of the abstracted UDP networking stack. Multiple virtual hosts can be created with network linkages between them to simulate packet flows.
Index ¶
- type BaseInterface
- type Host
- func (h *Host) AddPhy(name string) *PhysicalInterface
- func (h *Host) AddSocket(a *net.UDPAddr) *Socket
- func (h *Host) AddTun(name string) *Tunnel
- func (h *Host) Close()
- func (h *Host) DelInterface(name string) Interface
- func (h *Host) DelSocket(s *Socket)
- func (h *Host) InboundPacket(p *Packet) bool
- func (h *Host) Interface(name string) Interface
- func (h *Host) Name() string
- func (h *Host) OutboundPacket(p *Packet) bool
- func (h *Host) Wrap() networking.Environment
- type Interface
- type Network
- type Packet
- type PhysicalInterface
- type Socket
- type SocketOwner
- type TunPeer
- type Tunnel
- func (t *Tunnel) AddPeer(name string, publicKey wgtypes.Key, endpoint *net.UDPAddr, addrs []net.IPNet) *TunPeer
- func (t *Tunnel) AsWgDevice() *wgtypes.Device
- func (t *Tunnel) DelPeer(id string)
- func (t *Tunnel) DetachFromNetwork()
- func (t *Tunnel) GenerateKeys() (privateKey, publicKey wgtypes.Key)
- func (t *Tunnel) Keys() (privateKey, publicKey wgtypes.Key)
- func (t *Tunnel) Listen(port int)
- func (t *Tunnel) OutboundPacket(p *Packet) bool
- func (t *Tunnel) Peers() map[string]*TunPeer
- func (t *Tunnel) PublicKey() wgtypes.Key
- func (t *Tunnel) UseKey(privateKey wgtypes.Key)
- func (t *Tunnel) Wrap() networking.Interface
- type World
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseInterface ¶
type BaseInterface struct {
// contains filtered or unexported fields
}
BaseInterface handles the common elements of both physical and tunnel Interfaces
func (*BaseInterface) AddAddr ¶
func (i *BaseInterface) AddAddr(a net.IPNet)
AddAddr adds an IP address to the interface on which it can receive packets and from which it can send them
func (*BaseInterface) AddSocket ¶
func (i *BaseInterface) AddSocket(a *net.UDPAddr) *Socket
AddSocket creates a new socket on the interface
func (*BaseInterface) Addrs ¶
func (i *BaseInterface) Addrs() []net.IPNet
Addrs fetches a list of the currently assigned addresses on the interface
func (*BaseInterface) DelSocket ¶
func (i *BaseInterface) DelSocket(s *Socket)
DelSocket unregisters a socket from the interface
func (*BaseInterface) InboundPacket ¶
func (i *BaseInterface) InboundPacket(p *Packet) bool
InboundPacket inspects the packet to see if its destination matches any address on the interface and any listening socket, and if so enqueues it for that listener
func (*BaseInterface) Name ¶
func (i *BaseInterface) Name() string
Name gets the host-local name of the interface
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
A Host represents a system in a World with some set (possibly empty) of Interfaces, which may be connected to Networks to send and receive packets.
func (*Host) AddPhy ¶
func (h *Host) AddPhy(name string) *PhysicalInterface
AddPhy adds a new interface to the Host with the given name, assigning it an id combining the host id with the name to ensure uniqueness
func (*Host) AddTun ¶
AddTun creates a new tunnel interface on the host, but does not connect it to any peers, nor open a listen port for it to receive packets
func (*Host) Close ¶
func (h *Host) Close()
Close disconnects all Interfaces from the network, but does not Close Sockets
func (*Host) DelInterface ¶
DelInterface unregisters an interface from the host and detaches it from any network
func (*Host) InboundPacket ¶
InboundPacket inspects the packet to see if its destination matches any host-level listening socket, and if so enqueues it for that listener
func (*Host) OutboundPacket ¶
OutboundPacket tries to send a packet on each interface registered on the host
func (*Host) Wrap ¶
func (h *Host) Wrap() networking.Environment
Wrap provides an Environment view of a Host
type Interface ¶
type Interface interface { SocketOwner Name() string DetachFromNetwork() Wrap() networking.Interface Addrs() []net.IPNet }
An Interface is any network interface, whether physical or virtual, attached to a Host, which can be used to send and receive Packets.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
A Network represents a connected region within which packets can pass among Interfaces
func (*Network) EnqueuePacket ¶
EnqueuePacket enqueues a packet to deliver to the network
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
A Packet represents a UDP packet traveling on the virtual network
type PhysicalInterface ¶
type PhysicalInterface struct { BaseInterface // contains filtered or unexported fields }
An PhysicalInterface represents a network interface on a Host that is part of some World. The interface may be attached and detached from various Networks in the World.
func (*PhysicalInterface) AttachToNetwork ¶
func (i *PhysicalInterface) AttachToNetwork(n *Network)
AttachToNetwork connects this interface to a given network, allowing it to send packets to other hosts on the network
func (*PhysicalInterface) DetachFromNetwork ¶
func (i *PhysicalInterface) DetachFromNetwork()
DetachFromNetwork disconnects the interface from its network, if any.
func (*PhysicalInterface) OutboundPacket ¶
func (i *PhysicalInterface) OutboundPacket(p *Packet) bool
OutboundPacket enqueues the packet to be sent out the interface into the network, if possible
func (*PhysicalInterface) Wrap ¶
func (i *PhysicalInterface) Wrap() networking.Interface
Wrap implements Interface
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
A Socket represents a listening UDP socket which can send and receive Packets
func (*Socket) Connect ¶
func (s *Socket) Connect() networking.UDPConn
Connect creates a SocketUDPConn wrapper for the Socket to treat it as a networking.UDPConn.
func (*Socket) InboundPacket ¶
InboundPacket enqueues a packet for the receive listener to process
func (*Socket) OutboundPacket ¶
OutboundPacket sends a packet out the socket's interface
type SocketOwner ¶
type SocketOwner interface { OutboundPacket(*Packet) bool AddSocket(a *net.UDPAddr) *Socket DelSocket(*Socket) }
A SocketOwner can send packets
type TunPeer ¶
type TunPeer struct {
// contains filtered or unexported fields
}
TunPeer represents a simplified version of a wireguard peer, with a remote endpoint and a list of IPNets within the tunnel
func (*TunPeer) LastReceive ¶
LastReceive gets the time of the last received packet, or zero if never
type Tunnel ¶
type Tunnel struct { BaseInterface // contains filtered or unexported fields }
A Tunnel represents a Wireguard interface, which encapsulates packets and sends them via some other interface
func (*Tunnel) AddPeer ¶
func (t *Tunnel) AddPeer(name string, publicKey wgtypes.Key, endpoint *net.UDPAddr, addrs []net.IPNet) *TunPeer
AddPeer defines a new valid peer for communicating over the tunnel
func (*Tunnel) AsWgDevice ¶
AsWgDevice creates a view of the current tunnel state as a wireguard wgtypes.Device
func (*Tunnel) DelPeer ¶
DelPeer deletes the peer with the given id (String() of its PublicKey) from the tunnel
func (*Tunnel) DetachFromNetwork ¶
func (t *Tunnel) DetachFromNetwork()
DetachFromNetwork implements Interface
func (*Tunnel) GenerateKeys ¶
GenerateKeys makes a new key pair for the tunnel and uses it, panicing if generation fails
func (*Tunnel) Listen ¶
Listen tells the tunnel to open a listening socket on the host on which it can receive encapsulated packets
func (*Tunnel) OutboundPacket ¶
OutboundPacket implements Interface
type World ¶
type World struct {
// contains filtered or unexported fields
}
A World represents a global set of networks, hosts, and their interfaces.
func NewWorld ¶
func NewWorld() *World
NewWorld initializes a new empty world to which hosts and networks can be added.
func (*World) CreateEmptyHost ¶
CreateEmptyHost creates a new Host within the world, with no interfaces
func (*World) CreateHost ¶
CreateHost creates a simple host within the world, with its 'lo' (localhost) interface pre-configured
func (*World) CreateNetwork ¶
CreateNetwork creates and attaches a new Network with the given id to the world