ip

package
v2.5.7-rc.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitPacket

func InitPacket(pkg Packet, ipPayloadLen int, src, dst net.IP)

func L4Checksum

func L4Checksum(ipHdr Header, checksumPosition, l4Proto int)

L4Checksum computes a checksum for a layer 4 TCP or UDP header using a pseudo header created from the given IP header and assigns that checksum to the two bytes starting at checksumPosition.

The checksumPosition is the offset into the IP payload for the checksum for the given level-4 protocol which should be ipproto.TCP or ipproto.UDP.

It is assumed that the ipHdr represents an un-fragmented packet with a complete L4 payload.

func NextID

func NextID() int

Types

type AddrKey added in v2.4.7

type AddrKey string

AddrKey is an immutable form of an L4 address (ip and port), suitable as a map key.

func MakeAddrKey added in v2.4.7

func MakeAddrKey(ip net.IP, port uint16) AddrKey

func (AddrKey) IP added in v2.4.7

func (a AddrKey) IP() net.IP

func (AddrKey) Port added in v2.4.7

func (a AddrKey) Port() uint16

func (AddrKey) String added in v2.4.7

func (a AddrKey) String() string
type Header interface {
	// Initialize ensures that the header has the correct version and that all other bytes are zero
	Initialize()

	// Version returns ipv4.Version or ipv6.Version
	Version() int

	// Destination returns the destination IP
	Destination() net.IP

	// Source returns the source IP
	Source() net.IP

	// 	HeaderLength() is the length of this header
	HeaderLen() int

	// PayloadLen is the length of the payload
	PayloadLen() int

	// L4Protocol is the protocol of the layer-4 header.
	L4Protocol() int

	// Packet returns the full packet that this header is backed by.
	Packet() []byte

	// Payload returns the payload of the packet that this header is backed by.
	Payload() []byte

	// PseudoHeader returns the pseudo header used when computing the checksum for a layer-4 header.
	// All fields must be filled in before requesting this header.
	PseudoHeader(l4Proto int) []byte

	// SetTTL sets the hop limit
	SetTTL(id int)

	// SetSource sets the packet source IP address
	SetSource(ip net.IP)

	// SetDestination sets the packet destination IP address
	SetDestination(ip net.IP)

	// SetL4Protocol sets the layer 4 protocol (a.k.a. the next-layer protocol)
	SetL4Protocol(int)

	// SetPayloadLen sets the length of the payload
	SetPayloadLen(int)

	// SetChecksum computes the checksum for this header. No further modifications must be made once this is called.
	// This method is a no-op for ipv6.
	SetChecksum()
}

A Header provides a common interface for the V4Header and the V6Header

func ParseHeader

func ParseHeader(b []byte) (Header, error)

ParseHeader returns a v4 or v6 header backed by the given argument. The type of header is determined by looking at the top 4 bits of the first byte which must match ipv4.Version or ipv6.Version

type Packet

type Packet interface {
	IPHeader() Header
	Data() *buffer.Data
	Release()
	SetDataAndIPHeader(*buffer.Data, Header)
}

type V4Header

type V4Header []byte

func (V4Header) Checksum

func (h V4Header) Checksum() int

func (V4Header) ConcatFragments

func (h V4Header) ConcatFragments(data *buffer.Data, fragsMap map[uint16][]*buffer.Data) *buffer.Data

func (V4Header) DSCP

func (h V4Header) DSCP() int

func (V4Header) Destination

func (h V4Header) Destination() net.IP

func (V4Header) ECN

func (h V4Header) ECN() int

func (V4Header) Flags

func (h V4Header) Flags() ipv4.HeaderFlags

func (V4Header) FragmentOffset

func (h V4Header) FragmentOffset() int

func (V4Header) HeaderLen

func (h V4Header) HeaderLen() int

func (V4Header) ID

func (h V4Header) ID() uint16

func (V4Header) Initialize

func (h V4Header) Initialize()

func (V4Header) L4Protocol

func (h V4Header) L4Protocol() int

func (V4Header) Options

func (h V4Header) Options() ([]V4Option, error)

func (V4Header) Packet

func (h V4Header) Packet() []byte

func (V4Header) Payload

func (h V4Header) Payload() []byte

func (V4Header) PayloadLen

func (h V4Header) PayloadLen() int

func (V4Header) PseudoHeader

func (h V4Header) PseudoHeader(l4Proto int) []byte

func (V4Header) SetChecksum

func (h V4Header) SetChecksum()

func (V4Header) SetDestination

func (h V4Header) SetDestination(ip net.IP)

func (V4Header) SetFlags

func (h V4Header) SetFlags(flags ipv4.HeaderFlags)

func (V4Header) SetFragmentOffset

func (h V4Header) SetFragmentOffset(fragOff int)

func (V4Header) SetHeaderLen

func (h V4Header) SetHeaderLen(hl int)

func (V4Header) SetID

func (h V4Header) SetID(id int)

func (V4Header) SetL4Protocol

func (h V4Header) SetL4Protocol(proto int)

func (V4Header) SetPayloadLen

func (h V4Header) SetPayloadLen(len int)

func (V4Header) SetSource

func (h V4Header) SetSource(ip net.IP)

func (V4Header) SetTTL

func (h V4Header) SetTTL(hops int)

func (V4Header) Source

func (h V4Header) Source() net.IP

func (V4Header) TTL

func (h V4Header) TTL() int

func (V4Header) Version

func (h V4Header) Version() int

type V4Option

type V4Option []byte

func (V4Option) Class

func (o V4Option) Class() int

func (V4Option) Copied

func (o V4Option) Copied() bool

func (V4Option) Data

func (o V4Option) Data() []byte

func (V4Option) Len

func (o V4Option) Len() int

func (V4Option) Number

func (o V4Option) Number() int

type V6Header

type V6Header []byte

func (V6Header) Destination

func (h V6Header) Destination() net.IP

func (V6Header) FlowLabel

func (h V6Header) FlowLabel() int

func (V6Header) HeaderLen

func (h V6Header) HeaderLen() int

func (V6Header) HopLimit

func (h V6Header) HopLimit() int

func (V6Header) Initialize

func (h V6Header) Initialize()

func (V6Header) L4Protocol

func (h V6Header) L4Protocol() int

func (V6Header) NextHeader

func (h V6Header) NextHeader() int

func (V6Header) Packet

func (h V6Header) Packet() []byte

func (V6Header) Payload

func (h V6Header) Payload() []byte

func (V6Header) PayloadLen

func (h V6Header) PayloadLen() int

func (V6Header) ProcessFragments

func (h V6Header) ProcessFragments(data *buffer.Data, fragsMap map[uint16][]*buffer.Data) *buffer.Data

func (V6Header) PseudoHeader

func (h V6Header) PseudoHeader(l4Proto int) []byte

func (V6Header) SetChecksum

func (h V6Header) SetChecksum()

func (V6Header) SetDestination

func (h V6Header) SetDestination(ip net.IP)

func (V6Header) SetL4Protocol

func (h V6Header) SetL4Protocol(proto int)

func (V6Header) SetPayloadLen

func (h V6Header) SetPayloadLen(tl int)

func (V6Header) SetSource

func (h V6Header) SetSource(ip net.IP)

func (V6Header) SetTTL

func (h V6Header) SetTTL(hops int)

func (V6Header) Source

func (h V6Header) Source() net.IP

func (V6Header) TrafficClass

func (h V6Header) TrafficClass() int

func (V6Header) Version

func (h V6Header) Version() int

type Writer

type Writer interface {
	Write(context.Context, Packet) error
}

Jump to

Keyboard shortcuts

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