forward

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite

func Rewrite(buf []byte, l3 int, adj *Adjacency) int

Rewrite turns the packet in buf into the one to send: the TTL goes down by one with the checksum adjusted to match, and the Ethernet header is replaced by the adjacency's. The packet's IPv4 header starts at l3, and buf is the whole frame, so there is room for the header to grow. It returns the length to send, which is the Ethernet header plus the IPv4 total length: what was padding on the way in is not forwarded, and what is too short on the way out is padded again.

Types

type Adjacency

type Adjacency struct {
	L2    [ethHeaderLen + vlanTagLen]byte
	L2Len uint8
}

Adjacency is what a route resolves to: the Ethernet header, with an optional 802.1Q tag, that goes on every packet sent through it. Adjacency 0 is reserved to mean no route.

func NewAdjacency

func NewAdjacency(dst, src [6]byte, vlan uint16) Adjacency

NewAdjacency pre-forms the egress header: destination, source, an 802.1Q tag if vlan is not 0, and the IPv4 ethertype.

type ErrorCode

type ErrorCode uint8

ErrorCode is why a packet was not forwarded.

const (
	ErrNone ErrorCode = iota
	ErrShort
	ErrNotIPv4
	ErrBadVersion
	ErrBadLength
	ErrTTL
	ErrBadChecksum
	ErrNoRoute
	ErrTxFull
	NumErrors
)

func Parse

func Parse(pkt []byte, l3OK bool) (l3 int, dst uint32, code ErrorCode)

Parse finds the IPv4 header in a frame, checks it the way ip4-input does, and returns its offset and the destination address. Untagged, tagged and double-tagged frames are all accepted; nothing here assumes how long the Ethernet header is.

func (ErrorCode) String

func (e ErrorCode) String() string

type V4Fib

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

V4Fib is one IPv4 forwarding table.

func NewV4Fib

func NewV4Fib() *V4Fib

func (*V4Fib) Insert

func (f *V4Fib) Insert(prefix uint32, plen uint8, adj uint32)

Insert installs prefix/plen -> adj. adj must not be 0, which means no route.

func (*V4Fib) Lookup

func (f *V4Fib) Lookup(dst uint32) uint32

Lookup is the longest-prefix match: one to three dependent loads. It returns an adjacency index, or 0 when there is no route.

func (*V4Fib) Routes

func (f *V4Fib) Routes() int

Routes is how many routes were inserted.

Jump to

Keyboard shortcuts

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