Documentation ¶
Overview ¶
Package natlab lets us simulate different types of networks all in-memory without running VMs or requiring root, etc. Despite the name, it does more than just NATs. But NATs are the most interesting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface struct {
// contains filtered or unexported fields
}
type Machine ¶
type Machine struct { // Name is a pretty name for debugging and packet tracing. It need // not be globally unique. Name string // HandlePacket, if not nil, is a function that gets invoked for // every packet this Machine receives. Returns a verdict for how // the packet should continue to be handled (or not). // // This can be used to implement things like stateful firewalls // and NAT boxes. HandlePacket PacketHandler // contains filtered or unexported fields }
A Machine is a representation of an operating system's network stack. It has a network routing table and can have multiple attached networks. The zero value is valid, but lacks any networking capability until Attach is called.
func (*Machine) AddNetwork ¶
func (*Machine) Attach ¶
Attach adds an interface to a machine.
The first interface added to a Machine becomes that machine's default route.
func (*Machine) Inject ¶
Inject transmits p from src to dst, without the need for a local socket. It's useful for implementing e.g. NAT boxes that need to mangle IPs.
func (*Machine) ListenPacket ¶
func (m *Machine) ListenPacket(network, address string) (net.PacketConn, error)
type Network ¶
type Network struct { Name string Prefix4 netaddr.IPPrefix Prefix6 netaddr.IPPrefix // contains filtered or unexported fields }
func NewInternet ¶
func NewInternet() *Network
NewInternet returns a network that simulates the internet.
func (*Network) SetDefaultGateway ¶
type PacketHandler ¶
type PacketHandler func(p []byte, dst, src netaddr.IPPort) PacketVerdict
A PacketHandler is a function that can process packets.
type PacketVerdict ¶
type PacketVerdict int
A PacketVerdict is a decision of what to do with a packet.
const ( // Continue means the packet should be processed by the "local // sockets" logic of the Machine. Continue PacketVerdict = iota // Drop means the packet should not be handled further. Drop )
func (PacketVerdict) String ¶
func (v PacketVerdict) String() string