netlab

package
v0.0.0-...-cd4c4ab Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface struct {
	Name string
	// contains filtered or unexported fields
}

Interface is a network interface that puts a machine onto a network via a link. To attach an interface to a node, use node.Attach(). To link two interfaces together, use if.Link(other).

func (*Interface) IP

func (f *Interface) IP() netip.Addr

func (*Interface) IsUp

func (f *Interface) IsUp() bool
func (f *Interface) Link(toif *Interface) error

func (*Interface) Recv

func (f *Interface) Recv() chan []byte

Recv receives a block of bytes from the interface.

func (*Interface) Send

func (f *Interface) Send(ctx context.Context, buf []byte)

Send sends a block of bytes to the interface.

type Link struct {
	// contains filtered or unexported fields
}

Link binds two interfaces together.

type Network

type Network struct {
	Name   string
	Prefix netip.Prefix
	// contains filtered or unexported fields
}

Network is a set of interfaces (bound together by links). Currently, its role is to dynamically allocate IP addresses for interfaces.

type Node

type Node struct {
	// Name contains the name of the node in the network
	Name string

	Interfaces []*Interface

	HandleIngress       PacketHandler
	HandleLocalDelivery PacketHandler
	HandleEgress        PacketHandler
}

Node represents a node in one or more networks. Depending on how it manages traffic, it may be a router, switch, or perhaps a PC.

When a packet arrives on an attached interface,

func (*Node) Attach

func (n *Node) Attach(ifname string, net *Network) *Interface

Attach attaches an interface to a node, granting it an IP (and MAC?) address. To link two interfaces together, use if.Link(other).

type NodePacket

type NodePacket struct {
	// Packet contains a decoded Packet.
	// Layers of the packet can be manipulated (e.g. in the case of NAT), but be
	// wary of modification order.
	Packet packet.Packet

	// SourceIF points to the source interface.
	SourceIF *Interface

	// DestIF points to the destination interface.
	// If DestIF is nil at the end of ingress, then HandleLocalDelivery() is
	// called.
	DestIF *Interface
}

NodePacket describes a packet flowing through a node's routing system. It is roughly equivalent to sk_buffer in Linux.

type PacketHandler

type PacketHandler func(p *NodePacket) Verdict

PacketHandler is called on ingress, local delivery, and egress.

type Verdict

type Verdict uint8
const (
	// VerdictAccept continues packet iteration
	VerdictAccept Verdict = 0

	// VerdictDrop drops the packet immediately.
	VerdictDrop Verdict = 1

	// VerdictRepeat restarts packet iteration.
	// It is useful for when the packet contents have changed in some way.
	VerdictRepeat Verdict = 2
)

Jump to

Keyboard shortcuts

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