header

package
v0.0.0-...-55fcc16 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2019 License: Apache-2.0 Imports: 8 Imported by: 161

Documentation

Overview

Package header provides the implementation of the encoding and decoding of network protocol headers.

Index

Constants

View Source
const (
	// ARPProtocolNumber is the ARP network protocol number.
	ARPProtocolNumber tcpip.NetworkProtocolNumber = 0x0806

	// ARPSize is the size of an IPv4-over-Ethernet ARP packet.
	ARPSize = 2 + 2 + 1 + 1 + 2 + 2*6 + 2*4
)
View Source
const (
	// EthernetMinimumSize is the minimum size of a valid ethernet frame.
	EthernetMinimumSize = 14

	// EthernetAddressSize is the size, in bytes, of an ethernet address.
	EthernetAddressSize = 6
)
View Source
const (
	// EthernetProtocolAll is a catch-all for all protocols carried inside
	// an ethernet frame. It is mainly used to create packet sockets that
	// capture all traffic.
	EthernetProtocolAll tcpip.NetworkProtocolNumber = 0x0003

	// EthernetProtocolPUP is the PARC Universial Packet protocol ethertype.
	EthernetProtocolPUP tcpip.NetworkProtocolNumber = 0x0200
)
View Source
const (
	// ICMPv4PayloadOffset defines the start of ICMP payload.
	ICMPv4PayloadOffset = 8

	// ICMPv4MinimumSize is the minimum size of a valid ICMP packet.
	ICMPv4MinimumSize = 8

	// ICMPv4ProtocolNumber is the ICMP transport protocol number.
	ICMPv4ProtocolNumber tcpip.TransportProtocolNumber = 1
)
View Source
const (
	ICMPv4PortUnreachable     = 3
	ICMPv4FragmentationNeeded = 4
)

Values for ICMP code as defined in RFC 792.

View Source
const (
	// ICMPv6HeaderSize is the size of the ICMPv6 header. That is, the
	// sum of the size of the ICMPv6 Type, Code and Checksum fields, as
	// per RFC 4443 section 2.1. After the ICMPv6 header, the ICMPv6
	// message body begins.
	ICMPv6HeaderSize = 4

	// ICMPv6MinimumSize is the minimum size of a valid ICMP packet.
	ICMPv6MinimumSize = 8

	// ICMPv6PayloadOffset is the offset of the payload in an
	// ICMP packet.
	ICMPv6PayloadOffset = 8

	// ICMPv6ProtocolNumber is the ICMP transport protocol number.
	ICMPv6ProtocolNumber tcpip.TransportProtocolNumber = 58

	// ICMPv6NeighborSolicitMinimumSize is the minimum size of a
	// neighbor solicitation packet.
	ICMPv6NeighborSolicitMinimumSize = ICMPv6HeaderSize + NDPNSMinimumSize

	// ICMPv6NeighborAdvertMinimumSize is the minimum size of a
	// neighbor advertisement packet.
	ICMPv6NeighborAdvertMinimumSize = ICMPv6HeaderSize + NDPNAMinimumSize

	// ICMPv6NeighborAdvertSize is size of a neighbor advertisement
	// including the NDP Target Link Layer option for an Ethernet
	// address.
	ICMPv6NeighborAdvertSize = ICMPv6HeaderSize + NDPNAMinimumSize + ndpTargetEthernetLinkLayerAddressSize

	// ICMPv6EchoMinimumSize is the minimum size of a valid ICMP echo packet.
	ICMPv6EchoMinimumSize = 8

	// ICMPv6DstUnreachableMinimumSize is the minimum size of a valid ICMP
	// destination unreachable packet.
	ICMPv6DstUnreachableMinimumSize = ICMPv6MinimumSize

	// ICMPv6PacketTooBigMinimumSize is the minimum size of a valid ICMP
	// packet-too-big packet.
	ICMPv6PacketTooBigMinimumSize = ICMPv6MinimumSize

	// NDPHopLimit is the expected IP hop limit value of 255 for received
	// NDP packets, as per RFC 4861 sections 4.1 - 4.5, 6.1.1, 6.1.2, 7.1.1,
	// 7.1.2 and 8.1. If the hop limit value is not 255, nodes MUST silently
	// drop the NDP packet. All outgoing NDP packets must use this value for
	// its IP hop limit field.
	NDPHopLimit = 255
)
View Source
const (
	// IPv4MinimumSize is the minimum size of a valid IPv4 packet.
	IPv4MinimumSize = 20

	// IPv4MaximumHeaderSize is the maximum size of an IPv4 header. Given
	// that there are only 4 bits to represents the header length in 32-bit
	// units, the header cannot exceed 15*4 = 60 bytes.
	IPv4MaximumHeaderSize = 60

	// MinIPFragmentPayloadSize is the minimum number of payload bytes that
	// the first fragment must carry when an IPv4 packet is fragmented.
	MinIPFragmentPayloadSize = 8

	// IPv4AddressSize is the size, in bytes, of an IPv4 address.
	IPv4AddressSize = 4

	// IPv4ProtocolNumber is IPv4's network protocol number.
	IPv4ProtocolNumber tcpip.NetworkProtocolNumber = 0x0800

	// IPv4Version is the version of the ipv4 protocol.
	IPv4Version = 4

	// IPv4Broadcast is the broadcast address of the IPv4 procotol.
	IPv4Broadcast tcpip.Address = "\xff\xff\xff\xff"

	// IPv4Any is the non-routable IPv4 "any" meta address.
	IPv4Any tcpip.Address = "\x00\x00\x00\x00"

	// IPv4MinimumProcessableDatagramSize is the minimum size of an IP
	// packet that every IPv4 capable host must be able to
	// process/reassemble.
	IPv4MinimumProcessableDatagramSize = 576
)
View Source
const (
	IPv4FlagMoreFragments = 1 << iota
	IPv4FlagDontFragment
)

Flags that may be set in an IPv4 packet.

View Source
const (
	// IPv6MinimumSize is the minimum size of a valid IPv6 packet.
	IPv6MinimumSize = 40

	// IPv6AddressSize is the size, in bytes, of an IPv6 address.
	IPv6AddressSize = 16

	// IPv6ProtocolNumber is IPv6's network protocol number.
	IPv6ProtocolNumber tcpip.NetworkProtocolNumber = 0x86dd

	// IPv6Version is the version of the ipv6 protocol.
	IPv6Version = 6

	// IPv6AllNodesMulticastAddress is a link-local multicast group that
	// all IPv6 nodes MUST join, as per RFC 4291, section 2.8. Packets
	// destined to this address will reach all nodes on a link.
	//
	// The address is ff02::1.
	IPv6AllNodesMulticastAddress tcpip.Address = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"

	// IPv6MinimumMTU is the minimum MTU required by IPv6, per RFC 2460,
	// section 5.
	IPv6MinimumMTU = 1280

	// IPv6Any is the non-routable IPv6 "any" meta address. It is also
	// known as the unspecified address.
	IPv6Any tcpip.Address = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
View Source
const (
	// IPv6FragmentHeader header is the number used to specify that the next
	// header is a fragment header, per RFC 2460.
	IPv6FragmentHeader = 44

	// IPv6FragmentHeaderSize is the size of the fragment header.
	IPv6FragmentHeaderSize = 8
)
View Source
const (
	// NDPTargetLinkLayerAddressOptionType is the type of the Target
	// Link-Layer Address option, as per RFC 4861 section 4.6.1.
	NDPTargetLinkLayerAddressOptionType = 2

	// NDPPrefixInformationType is the type of the Prefix Information
	// option, as per RFC 4861 section 4.6.2.
	NDPPrefixInformationType = 3
)
View Source
const (
	TCPSrcPortOffset   = 0
	TCPDstPortOffset   = 2
	TCPSeqNumOffset    = 4
	TCPAckNumOffset    = 8
	TCPDataOffset      = 12
	TCPFlagsOffset     = 13
	TCPWinSizeOffset   = 14
	TCPChecksumOffset  = 16
	TCPUrgentPtrOffset = 18
)

These constants are the offsets of the respective fields in the TCP header.

View Source
const (
	// MaxWndScale is maximum allowed window scaling, as described in
	// RFC 1323, section 2.3, page 11.
	MaxWndScale = 14

	// TCPMaxSACKBlocks is the maximum number of SACK blocks that can
	// be encoded in a TCP option field.
	TCPMaxSACKBlocks = 4
)
View Source
const (
	TCPFlagFin = 1 << iota
	TCPFlagSyn
	TCPFlagRst
	TCPFlagPsh
	TCPFlagAck
	TCPFlagUrg
)

Flags that may be set in a TCP segment.

View Source
const (
	TCPOptionEOL           = 0
	TCPOptionNOP           = 1
	TCPOptionMSS           = 2
	TCPOptionWS            = 3
	TCPOptionTS            = 8
	TCPOptionSACKPermitted = 4
	TCPOptionSACK          = 5
)

Options that may be present in a TCP segment.

View Source
const (
	// TCPMinimumSize is the minimum size of a valid TCP packet.
	TCPMinimumSize = 20

	// TCPOptionsMaximumSize is the maximum size of TCP options.
	TCPOptionsMaximumSize = 40

	// TCPHeaderMaximumSize is the maximum header size of a TCP packet.
	TCPHeaderMaximumSize = TCPMinimumSize + TCPOptionsMaximumSize

	// TCPProtocolNumber is TCP's transport protocol number.
	TCPProtocolNumber tcpip.TransportProtocolNumber = 6

	// TCPMinimumMSS is the minimum acceptable value for MSS. This is the
	// same as the value TCP_MIN_MSS defined net/tcp.h.
	TCPMinimumMSS = IPv4MaximumHeaderSize + TCPHeaderMaximumSize + MinIPFragmentPayloadSize - IPv4MinimumSize - TCPMinimumSize

	// TCPMaximumMSS is the maximum acceptable value for MSS.
	TCPMaximumMSS = 0xffff

	// TCPDefaultMSS is the MSS value that should be used if an MSS option
	// is not received from the peer. It's also the value returned by
	// TCP_MAXSEG option for a socket in an unconnected state.
	//
	// Per RFC 1122, page 85: "If an MSS option is not received at
	// connection setup, TCP MUST assume a default send MSS of 536."
	TCPDefaultMSS = 536
)
View Source
const (
	// UDPMinimumSize is the minimum size of a valid UDP packet.
	UDPMinimumSize = 8

	// UDPProtocolNumber is UDP's transport protocol number.
	UDPProtocolNumber tcpip.TransportProtocolNumber = 17
)
View Source
const (
	// GUEMinimumSize is the minimum size of a valid GUE packet.
	GUEMinimumSize = 4
)
View Source
const (
	ICMPv6PortUnreachable = 4
)

Values for ICMP code as defined in RFC 4443.

View Source
const (

	// IPv4TotalLenOffset is the offset of the total length field in the
	// IPv4 header.
	IPv4TotalLenOffset = 2
)
View Source
const (

	// IPv6PayloadLenOffset is the offset of the PayloadLength field in
	// IPv6 header.
	IPv6PayloadLenOffset = 4
)
View Source
const (
	// MaxIPPacketSize is the maximum supported IP packet size, excluding
	// jumbograms. The maximum IPv4 packet size is 64k-1 (total size must fit
	// in 16 bits). For IPv6, the payload max size (excluding jumbograms) is
	// 64k-1 (also needs to fit in 16 bits). So we use 64k - 1 + 2 * m, where
	// m is the minimum IPv6 header size; we leave room for some potential
	// IP options.
	MaxIPPacketSize = 0xffff + 2*IPv6MinimumSize
)
View Source
const (
	// NDPNAMinimumSize is the minimum size of a valid NDP Neighbor
	// Advertisement message (body of an ICMPv6 packet).
	NDPNAMinimumSize = 20
)
View Source
const (
	// NDPNSMinimumSize is the minimum size of a valid NDP Neighbor
	// Solicitation message (body of an ICMPv6 packet).
	NDPNSMinimumSize = 20
)
View Source
const (
	// NDPRAMinimumSize is the minimum size of a valid NDP Router
	// Advertisement message (body of an ICMPv6 packet).
	NDPRAMinimumSize = 12
)
View Source
const (
	// UDPMaximumPacketSize is the largest possible UDP packet.
	UDPMaximumPacketSize = 0xffff
)

Variables

View Source
var (
	ErrNDPOptBufExhausted  = errors.New("Buffer unexpectedly exhausted")
	ErrNDPOptZeroLength    = errors.New("NDP option has zero-valued Length field")
	ErrNDPOptMalformedBody = errors.New("NDP option has a malformed body")
)

Potential errors when iterating over an NDPOptions.

Ethertypes holds the protocol numbers describing the payload of an ethernet frame. These types aren't necessarily supported by netstack, but can be used to catch all traffic of a type via packet endpoints.

View Source
var IPv4EmptySubnet = func() tcpip.Subnet {
	subnet, err := tcpip.NewSubnet(IPv4Any, tcpip.AddressMask(IPv4Any))
	if err != nil {
		panic(err)
	}
	return subnet
}()

IPv4EmptySubnet is the empty IPv4 subnet.

View Source
var IPv6EmptySubnet = func() tcpip.Subnet {
	subnet, err := tcpip.NewSubnet(IPv6Any, tcpip.AddressMask(IPv6Any))
	if err != nil {
		panic(err)
	}
	return subnet
}()

IPv6EmptySubnet is the empty IPv6 subnet. It may also be known as the catch-all or wildcard subnet. That is, all IPv6 addresses are considered to be contained within this subnet.

View Source
var IPv6LinkLocalPrefix = tcpip.AddressWithPrefix{
	Address:   "\xfe\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
	PrefixLen: 64,
}

IPv6LinkLocalPrefix is the prefix for IPv6 link-local addresses, as defined by RFC 4291 section 2.5.6.

The prefix is fe80::/64

View Source
var (
	// NDPPrefixInformationInfiniteLifetime is a value that represents
	// infinity for the Valid and Preferred Lifetime fields in a NDP Prefix
	// Information option. Its value is (2^32 - 1)s = 4294967295s
	//
	// This is a variable instead of a constant so that tests can change
	// this value to a smaller value. It should only be modified by tests.
	NDPPrefixInformationInfiniteLifetime = time.Second * 4294967295
)

Functions

func AddTCPOptionPadding

func AddTCPOptionPadding(options []byte, offset int) int

AddTCPOptionPadding adds the required number of TCPOptionNOP to quad align the option buffer. It adds padding bytes after the offset specified and returns the number of padding bytes added. The passed in options slice must have space for the padding bytes.

func Checksum

func Checksum(buf []byte, initial uint16) uint16

Checksum calculates the checksum (as defined in RFC 1071) of the bytes in the given byte array.

The initial checksum must have been computed on an even number of bytes.

func ChecksumCombine

func ChecksumCombine(a, b uint16) uint16

ChecksumCombine combines the two uint16 to form their checksum. This is done by adding them and the carry.

Note that checksum a must have been computed on an even number of bytes.

func ChecksumVV

func ChecksumVV(vv buffer.VectorisedView, initial uint16) uint16

ChecksumVV calculates the checksum (as defined in RFC 1071) of the bytes in the given VectorizedView.

The initial checksum must have been computed on an even number of bytes.

func ChecksumVVWithOffset

func ChecksumVVWithOffset(vv buffer.VectorisedView, initial uint16, off int, size int) uint16

ChecksumVVWithOffset calculates the checksum (as defined in RFC 1071) of the bytes in the given VectorizedView.

The initial checksum must have been computed on an even number of bytes.

func EncodeMSSOption

func EncodeMSSOption(mss uint32, b []byte) int

EncodeMSSOption encodes the MSS TCP option with the provided MSS values in the supplied buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeNOP

func EncodeNOP(b []byte) int

EncodeNOP adds an explicit NOP to the option list.

func EncodeSACKBlocks

func EncodeSACKBlocks(sackBlocks []SACKBlock, b []byte) int

EncodeSACKBlocks encodes the provided SACK blocks as a TCP SACK option block in the provided slice. It tries to fit in as many blocks as possible based on number of bytes available in the provided buffer. It returns the number of bytes written to the provided buffer.

func EncodeSACKPermittedOption

func EncodeSACKPermittedOption(b []byte) int

EncodeSACKPermittedOption encodes a SACKPermitted option into the provided buffer. If the buffer is smaller than required it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeTSOption

func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int

EncodeTSOption encodes the provided tsVal and tsEcr values as a TCP timestamp option into the provided buffer. If the buffer is smaller than expected it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeWSOption

func EncodeWSOption(ws int, b []byte) int

EncodeWSOption encodes the WS TCP option with the WS value in the provided buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func ICMPv4Checksum

func ICMPv4Checksum(h ICMPv4, vv buffer.VectorisedView) uint16

ICMPv4Checksum calculates the ICMP checksum over the provided ICMP header, and payload.

func ICMPv6Checksum

func ICMPv6Checksum(h ICMPv6, src, dst tcpip.Address, vv buffer.VectorisedView) uint16

ICMPv6Checksum calculates the ICMP checksum over the provided ICMPv6 header, IPv6 src/dst addresses and the payload.

func IPVersion

func IPVersion(b []byte) int

IPVersion returns the version of IP used in the given packet. It returns -1 if the packet is not large enough to contain the version field.

func IsV4MappedAddress

func IsV4MappedAddress(addr tcpip.Address) bool

IsV4MappedAddress determines if the provided address is an IPv4 mapped address by checking if its prefix is 0:0:0:0:0:ffff::/96.

func IsV4MulticastAddress

func IsV4MulticastAddress(addr tcpip.Address) bool

IsV4MulticastAddress determines if the provided address is an IPv4 multicast address (range 224.0.0.0 to 239.255.255.255). The four most significant bits will be 1110 = 0xe0.

func IsV6LinkLocalAddress

func IsV6LinkLocalAddress(addr tcpip.Address) bool

IsV6LinkLocalAddress determines if the provided address is an IPv6 link-local address (fe80::/10).

func IsV6MulticastAddress

func IsV6MulticastAddress(addr tcpip.Address) bool

IsV6MulticastAddress determines if the provided address is an IPv6 multicast address (anything starting with FF).

func IsV6UnicastAddress

func IsV6UnicastAddress(addr tcpip.Address) bool

IsV6UnicastAddress determines if the provided address is a valid IPv6 unicast (and specified) address. That is, IsV6UnicastAddress returns true if addr contains IPv6AddressSize bytes, is not the unspecified address and is not a multicast address.

func IsValidUnicastEthernetAddress

func IsValidUnicastEthernetAddress(addr tcpip.LinkAddress) bool

IsValidUnicastEthernetAddress returns true if addr is a valid unicast ethernet address.

func LinkLocalAddr

func LinkLocalAddr(linkAddr tcpip.LinkAddress) tcpip.Address

LinkLocalAddr computes the default IPv6 link-local address from a link-layer (MAC) address.

func PseudoHeaderChecksum

func PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, srcAddr tcpip.Address, dstAddr tcpip.Address, totalLen uint16) uint16

PseudoHeaderChecksum calculates the pseudo-header checksum for the given destination protocol and network address. Pseudo-headers are needed by transport layers when calculating their own checksum.

func SolicitedNodeAddr

func SolicitedNodeAddr(addr tcpip.Address) tcpip.Address

SolicitedNodeAddr computes the solicited-node multicast address. This is used for NDP. Described in RFC 4291. The argument must be a full-length IPv6 address.

Types

type ARP

type ARP []byte

ARP is an ARP packet stored in a byte array as described in RFC 826.

func (ARP) HardwareAddressSender

func (a ARP) HardwareAddressSender() []byte

HardwareAddressSender is the link address of the sender. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) HardwareAddressTarget

func (a ARP) HardwareAddressTarget() []byte

HardwareAddressTarget is the link address of the target. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) IsValid

func (a ARP) IsValid() bool

IsValid reports whether this is an ARP packet for IPv4 over Ethernet.

func (ARP) Op

func (a ARP) Op() ARPOp

Op is the ARP opcode.

func (ARP) ProtocolAddressSender

func (a ARP) ProtocolAddressSender() []byte

ProtocolAddressSender is the protocol address of the sender. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) ProtocolAddressTarget

func (a ARP) ProtocolAddressTarget() []byte

ProtocolAddressTarget is the protocol address of the target. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) SetIPv4OverEthernet

func (a ARP) SetIPv4OverEthernet()

SetIPv4OverEthernet configures the ARP packet for IPv4-over-Ethernet.

func (ARP) SetOp

func (a ARP) SetOp(op ARPOp)

SetOp sets the ARP opcode.

type ARPOp

type ARPOp uint16

ARPOp is an ARP opcode.

const (
	ARPRequest ARPOp = 1
	ARPReply   ARPOp = 2
)

Typical ARP opcodes defined in RFC 826.

type Ethernet

type Ethernet []byte

Ethernet represents an ethernet frame header stored in a byte array.

func (Ethernet) DestinationAddress

func (b Ethernet) DestinationAddress() tcpip.LinkAddress

DestinationAddress returns the "MAC destination" field of the ethernet frame header.

func (Ethernet) Encode

func (b Ethernet) Encode(e *EthernetFields)

Encode encodes all the fields of the ethernet frame header.

func (Ethernet) SourceAddress

func (b Ethernet) SourceAddress() tcpip.LinkAddress

SourceAddress returns the "MAC source" field of the ethernet frame header.

func (Ethernet) Type

Type returns the "ethertype" field of the ethernet frame header.

type EthernetFields

type EthernetFields struct {
	// SrcAddr is the "MAC source" field of an ethernet frame header.
	SrcAddr tcpip.LinkAddress

	// DstAddr is the "MAC destination" field of an ethernet frame header.
	DstAddr tcpip.LinkAddress

	// Type is the "ethertype" field of an ethernet frame header.
	Type tcpip.NetworkProtocolNumber
}

EthernetFields contains the fields of an ethernet frame header. It is used to describe the fields of a frame that needs to be encoded.

type GUE

type GUE []byte

GUE represents a Generic UDP Encapsulation header stored in a byte array, the fields are described in https://tools.ietf.org/html/draft-ietf-nvo3-gue-01.

func (GUE) Encode

func (b GUE) Encode(i *GUEFields)

Encode encodes all the fields of the GUE header.

func (GUE) HeaderLength

func (b GUE) HeaderLength() uint8

HeaderLength returns the total length of the GUE header.

func (GUE) Protocol

func (b GUE) Protocol() uint8

Protocol returns the protocol field of the GUE header.

func (GUE) TypeAndControl

func (b GUE) TypeAndControl() uint8

TypeAndControl returns the GUE packet type (top 3 bits of the first byte, which includes the control bit).

type GUEFields

type GUEFields struct {
	// Type is the "type" field of the GUE header.
	Type uint8

	// Control is the "control" field of the GUE header.
	Control bool

	// HeaderLength is the "header length" field of the GUE header. It must
	// be at least 4 octets, and a multiple of 4 as well.
	HeaderLength uint8

	// Protocol is the "protocol" field of the GUE header. This is one of
	// the IPPROTO_* values.
	Protocol uint8
}

GUEFields contains the fields of a GUE packet. It is used to describe the fields of a packet that needs to be encoded.

type ICMPv4

type ICMPv4 []byte

ICMPv4 represents an ICMPv4 header stored in a byte array.

func (ICMPv4) Checksum

func (b ICMPv4) Checksum() uint16

Checksum is the ICMP checksum field.

func (ICMPv4) Code

func (b ICMPv4) Code() byte

Code is the ICMP code field. Its meaning depends on the value of Type.

func (ICMPv4) DestinationPort

func (ICMPv4) DestinationPort() uint16

DestinationPort implements Transport.DestinationPort.

func (ICMPv4) Ident

func (b ICMPv4) Ident() uint16

Ident retrieves the Ident field from an ICMPv4 message.

func (ICMPv4) MTU

func (b ICMPv4) MTU() uint16

MTU retrieves the MTU field from an ICMPv4 message.

func (ICMPv4) Payload

func (b ICMPv4) Payload() []byte

Payload implements Transport.Payload.

func (ICMPv4) Sequence

func (b ICMPv4) Sequence() uint16

Sequence retrieves the Sequence field from an ICMPv4 message.

func (ICMPv4) SetChecksum

func (b ICMPv4) SetChecksum(checksum uint16)

SetChecksum sets the ICMP checksum field.

func (ICMPv4) SetCode

func (b ICMPv4) SetCode(c byte)

SetCode sets the ICMP code field.

func (ICMPv4) SetDestinationPort

func (ICMPv4) SetDestinationPort(uint16)

SetDestinationPort implements Transport.SetDestinationPort.

func (ICMPv4) SetIdent

func (b ICMPv4) SetIdent(ident uint16)

SetIdent sets the Ident field from an ICMPv4 message.

func (ICMPv4) SetMTU

func (b ICMPv4) SetMTU(mtu uint16)

SetMTU sets the MTU field from an ICMPv4 message.

func (ICMPv4) SetSequence

func (b ICMPv4) SetSequence(sequence uint16)

SetSequence sets the Sequence field from an ICMPv4 message.

func (ICMPv4) SetSourcePort

func (ICMPv4) SetSourcePort(uint16)

SetSourcePort implements Transport.SetSourcePort.

func (ICMPv4) SetType

func (b ICMPv4) SetType(t ICMPv4Type)

SetType sets the ICMP type field.

func (ICMPv4) SourcePort

func (ICMPv4) SourcePort() uint16

SourcePort implements Transport.SourcePort.

func (ICMPv4) Type

func (b ICMPv4) Type() ICMPv4Type

Type is the ICMP type field.

type ICMPv4Type

type ICMPv4Type byte

ICMPv4Type is the ICMP type field described in RFC 792.

const (
	ICMPv4EchoReply      ICMPv4Type = 0
	ICMPv4DstUnreachable ICMPv4Type = 3
	ICMPv4SrcQuench      ICMPv4Type = 4
	ICMPv4Redirect       ICMPv4Type = 5
	ICMPv4Echo           ICMPv4Type = 8
	ICMPv4TimeExceeded   ICMPv4Type = 11
	ICMPv4ParamProblem   ICMPv4Type = 12
	ICMPv4Timestamp      ICMPv4Type = 13
	ICMPv4TimestampReply ICMPv4Type = 14
	ICMPv4InfoRequest    ICMPv4Type = 15
	ICMPv4InfoReply      ICMPv4Type = 16
)

Typical values of ICMPv4Type defined in RFC 792.

type ICMPv6

type ICMPv6 []byte

ICMPv6 represents an ICMPv6 header stored in a byte array.

func (ICMPv6) Checksum

func (b ICMPv6) Checksum() uint16

Checksum is the ICMP checksum field.

func (ICMPv6) Code

func (b ICMPv6) Code() byte

Code is the ICMP code field. Its meaning depends on the value of Type.

func (ICMPv6) DestinationPort

func (ICMPv6) DestinationPort() uint16

DestinationPort implements Transport.DestinationPort.

func (ICMPv6) Ident

func (b ICMPv6) Ident() uint16

Ident retrieves the Ident field from an ICMPv6 message.

func (ICMPv6) MTU

func (b ICMPv6) MTU() uint32

MTU retrieves the MTU field from an ICMPv6 message.

func (ICMPv6) NDPPayload

func (b ICMPv6) NDPPayload() []byte

NDPPayload returns the NDP payload buffer. That is, it returns the ICMPv6 packet's message body as defined by RFC 4443 section 2.1; the portion of the ICMPv6 buffer after the first ICMPv6HeaderSize bytes.

func (ICMPv6) Payload

func (b ICMPv6) Payload() []byte

Payload implements Transport.Payload.

func (ICMPv6) Sequence

func (b ICMPv6) Sequence() uint16

Sequence retrieves the Sequence field from an ICMPv6 message.

func (ICMPv6) SetChecksum

func (b ICMPv6) SetChecksum(checksum uint16)

SetChecksum sets the ICMP checksum field.

func (ICMPv6) SetCode

func (b ICMPv6) SetCode(c byte)

SetCode sets the ICMP code field.

func (ICMPv6) SetDestinationPort

func (ICMPv6) SetDestinationPort(uint16)

SetDestinationPort implements Transport.SetDestinationPort.

func (ICMPv6) SetIdent

func (b ICMPv6) SetIdent(ident uint16)

SetIdent sets the Ident field from an ICMPv6 message.

func (ICMPv6) SetMTU

func (b ICMPv6) SetMTU(mtu uint32)

SetMTU sets the MTU field from an ICMPv6 message.

func (ICMPv6) SetSequence

func (b ICMPv6) SetSequence(sequence uint16)

SetSequence sets the Sequence field from an ICMPv6 message.

func (ICMPv6) SetSourcePort

func (ICMPv6) SetSourcePort(uint16)

SetSourcePort implements Transport.SetSourcePort.

func (ICMPv6) SetType

func (b ICMPv6) SetType(t ICMPv6Type)

SetType sets the ICMP type field.

func (ICMPv6) SourcePort

func (ICMPv6) SourcePort() uint16

SourcePort implements Transport.SourcePort.

func (ICMPv6) Type

func (b ICMPv6) Type() ICMPv6Type

Type is the ICMP type field.

type ICMPv6Type

type ICMPv6Type byte

ICMPv6Type is the ICMP type field described in RFC 4443 and friends.

const (
	ICMPv6DstUnreachable ICMPv6Type = 1
	ICMPv6PacketTooBig   ICMPv6Type = 2
	ICMPv6TimeExceeded   ICMPv6Type = 3
	ICMPv6ParamProblem   ICMPv6Type = 4
	ICMPv6EchoRequest    ICMPv6Type = 128
	ICMPv6EchoReply      ICMPv6Type = 129

	ICMPv6RouterSolicit   ICMPv6Type = 133
	ICMPv6RouterAdvert    ICMPv6Type = 134
	ICMPv6NeighborSolicit ICMPv6Type = 135
	ICMPv6NeighborAdvert  ICMPv6Type = 136
	ICMPv6RedirectMsg     ICMPv6Type = 137
)

Typical values of ICMPv6Type defined in RFC 4443.

type IPv4

type IPv4 []byte

IPv4 represents an ipv4 header stored in a byte array. Most of the methods of IPv4 access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv4 before using other methods.

func (IPv4) CalculateChecksum

func (b IPv4) CalculateChecksum() uint16

CalculateChecksum calculates the checksum of the ipv4 header.

func (IPv4) Checksum

func (b IPv4) Checksum() uint16

Checksum returns the checksum field of the ipv4 header.

func (IPv4) DestinationAddress

func (b IPv4) DestinationAddress() tcpip.Address

DestinationAddress returns the "destination address" field of the ipv4 header.

func (IPv4) Encode

func (b IPv4) Encode(i *IPv4Fields)

Encode encodes all the fields of the ipv4 header.

func (IPv4) EncodePartial

func (b IPv4) EncodePartial(partialChecksum, totalLength uint16)

EncodePartial updates the total length and checksum fields of ipv4 header, taking in the partial checksum, which is the checksum of the header without the total length and checksum fields. It is useful in cases when similar packets are produced.

func (IPv4) Flags

func (b IPv4) Flags() uint8

Flags returns the "flags" field of the ipv4 header.

func (IPv4) FragmentOffset

func (b IPv4) FragmentOffset() uint16

FragmentOffset returns the "fragment offset" field of the ipv4 header.

func (IPv4) HeaderLength

func (b IPv4) HeaderLength() uint8

HeaderLength returns the value of the "header length" field of the ipv4 header.

func (IPv4) ID

func (b IPv4) ID() uint16

ID returns the value of the identifier field of the ipv4 header.

func (IPv4) IsValid

func (b IPv4) IsValid(pktSize int) bool

IsValid performs basic validation on the packet.

func (IPv4) Payload

func (b IPv4) Payload() []byte

Payload implements Network.Payload.

func (IPv4) PayloadLength

func (b IPv4) PayloadLength() uint16

PayloadLength returns the length of the payload portion of the ipv4 packet.

func (IPv4) Protocol

func (b IPv4) Protocol() uint8

Protocol returns the value of the protocol field of the ipv4 header.

func (IPv4) SetChecksum

func (b IPv4) SetChecksum(v uint16)

SetChecksum sets the checksum field of the ipv4 header.

func (IPv4) SetDestinationAddress

func (b IPv4) SetDestinationAddress(addr tcpip.Address)

SetDestinationAddress sets the "destination address" field of the ipv4 header.

func (IPv4) SetFlagsFragmentOffset

func (b IPv4) SetFlagsFragmentOffset(flags uint8, offset uint16)

SetFlagsFragmentOffset sets the "flags" and "fragment offset" fields of the ipv4 header.

func (IPv4) SetID

func (b IPv4) SetID(v uint16)

SetID sets the identification field.

func (IPv4) SetSourceAddress

func (b IPv4) SetSourceAddress(addr tcpip.Address)

SetSourceAddress sets the "source address" field of the ipv4 header.

func (IPv4) SetTOS

func (b IPv4) SetTOS(v uint8, _ uint32)

SetTOS sets the "type of service" field of the ipv4 header.

func (IPv4) SetTotalLength

func (b IPv4) SetTotalLength(totalLength uint16)

SetTotalLength sets the "total length" field of the ipv4 header.

func (IPv4) SourceAddress

func (b IPv4) SourceAddress() tcpip.Address

SourceAddress returns the "source address" field of the ipv4 header.

func (IPv4) TOS

func (b IPv4) TOS() (uint8, uint32)

TOS returns the "type of service" field of the ipv4 header.

func (IPv4) TTL

func (b IPv4) TTL() uint8

TTL returns the "TTL" field of the ipv4 header.

func (IPv4) TotalLength

func (b IPv4) TotalLength() uint16

TotalLength returns the "total length" field of the ipv4 header.

func (IPv4) TransportProtocol

func (b IPv4) TransportProtocol() tcpip.TransportProtocolNumber

TransportProtocol implements Network.TransportProtocol.

type IPv4Fields

type IPv4Fields struct {
	// IHL is the "internet header length" field of an IPv4 packet.
	IHL uint8

	// TOS is the "type of service" field of an IPv4 packet.
	TOS uint8

	// TotalLength is the "total length" field of an IPv4 packet.
	TotalLength uint16

	// ID is the "identification" field of an IPv4 packet.
	ID uint16

	// Flags is the "flags" field of an IPv4 packet.
	Flags uint8

	// FragmentOffset is the "fragment offset" field of an IPv4 packet.
	FragmentOffset uint16

	// TTL is the "time to live" field of an IPv4 packet.
	TTL uint8

	// Protocol is the "protocol" field of an IPv4 packet.
	Protocol uint8

	// Checksum is the "checksum" field of an IPv4 packet.
	Checksum uint16

	// SrcAddr is the "source ip address" of an IPv4 packet.
	SrcAddr tcpip.Address

	// DstAddr is the "destination ip address" of an IPv4 packet.
	DstAddr tcpip.Address
}

IPv4Fields contains the fields of an IPv4 packet. It is used to describe the fields of a packet that needs to be encoded.

type IPv6

type IPv6 []byte

IPv6 represents an ipv6 header stored in a byte array. Most of the methods of IPv6 access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv6 before using other methods.

func (IPv6) Checksum

func (IPv6) Checksum() uint16

Checksum implements Network.Checksum. Given that IPv6 doesn't have a checksum, it just returns 0.

func (IPv6) DestinationAddress

func (b IPv6) DestinationAddress() tcpip.Address

DestinationAddress returns the "destination address" field of the ipv6 header.

func (IPv6) Encode

func (b IPv6) Encode(i *IPv6Fields)

Encode encodes all the fields of the ipv6 header.

func (IPv6) HopLimit

func (b IPv6) HopLimit() uint8

HopLimit returns the value of the "hop limit" field of the ipv6 header.

func (IPv6) IsValid

func (b IPv6) IsValid(pktSize int) bool

IsValid performs basic validation on the packet.

func (IPv6) NextHeader

func (b IPv6) NextHeader() uint8

NextHeader returns the value of the "next header" field of the ipv6 header.

func (IPv6) Payload

func (b IPv6) Payload() []byte

Payload implements Network.Payload.

func (IPv6) PayloadLength

func (b IPv6) PayloadLength() uint16

PayloadLength returns the value of the "payload length" field of the ipv6 header.

func (IPv6) SetChecksum

func (IPv6) SetChecksum(uint16)

SetChecksum implements Network.SetChecksum. Given that IPv6 doesn't have a checksum, it is empty.

func (IPv6) SetDestinationAddress

func (b IPv6) SetDestinationAddress(addr tcpip.Address)

SetDestinationAddress sets the "destination address" field of the ipv6 header.

func (IPv6) SetNextHeader

func (b IPv6) SetNextHeader(v uint8)

SetNextHeader sets the value of the "next header" field of the ipv6 header.

func (IPv6) SetPayloadLength

func (b IPv6) SetPayloadLength(payloadLength uint16)

SetPayloadLength sets the "payload length" field of the ipv6 header.

func (IPv6) SetSourceAddress

func (b IPv6) SetSourceAddress(addr tcpip.Address)

SetSourceAddress sets the "source address" field of the ipv6 header.

func (IPv6) SetTOS

func (b IPv6) SetTOS(t uint8, l uint32)

SetTOS sets the "traffic class" and "flow label" fields of the ipv6 header.

func (IPv6) SourceAddress

func (b IPv6) SourceAddress() tcpip.Address

SourceAddress returns the "source address" field of the ipv6 header.

func (IPv6) TOS

func (b IPv6) TOS() (uint8, uint32)

TOS returns the "traffic class" and "flow label" fields of the ipv6 header.

func (IPv6) TransportProtocol

func (b IPv6) TransportProtocol() tcpip.TransportProtocolNumber

TransportProtocol implements Network.TransportProtocol.

type IPv6Fields

type IPv6Fields struct {
	// TrafficClass is the "traffic class" field of an IPv6 packet.
	TrafficClass uint8

	// FlowLabel is the "flow label" field of an IPv6 packet.
	FlowLabel uint32

	// PayloadLength is the "payload length" field of an IPv6 packet.
	PayloadLength uint16

	// NextHeader is the "next header" field of an IPv6 packet.
	NextHeader uint8

	// HopLimit is the "hop limit" field of an IPv6 packet.
	HopLimit uint8

	// SrcAddr is the "source ip address" of an IPv6 packet.
	SrcAddr tcpip.Address

	// DstAddr is the "destination ip address" of an IPv6 packet.
	DstAddr tcpip.Address
}

IPv6Fields contains the fields of an IPv6 packet. It is used to describe the fields of a packet that needs to be encoded.

type IPv6Fragment

type IPv6Fragment []byte

IPv6Fragment represents an ipv6 fragment header stored in a byte array. Most of the methods of IPv6Fragment access to the underlying slice without checking the boundaries and could panic because of 'index out of range'. Always call IsValid() to validate an instance of IPv6Fragment before using other methods.

func (IPv6Fragment) Checksum

func (b IPv6Fragment) Checksum() uint16

Checksum is not supported by IPv6Fragment.

func (IPv6Fragment) DestinationAddress

func (b IPv6Fragment) DestinationAddress() tcpip.Address

DestinationAddress is not supported by IPv6Fragment.

func (IPv6Fragment) Encode

func (b IPv6Fragment) Encode(i *IPv6FragmentFields)

Encode encodes all the fields of the ipv6 fragment.

func (IPv6Fragment) FragmentOffset

func (b IPv6Fragment) FragmentOffset() uint16

FragmentOffset returns the "fragment offset" field of the ipv6 fragment.

func (IPv6Fragment) ID

func (b IPv6Fragment) ID() uint32

ID returns the value of the identifier field of the ipv6 fragment.

func (IPv6Fragment) IsValid

func (b IPv6Fragment) IsValid() bool

IsValid performs basic validation on the fragment header.

func (IPv6Fragment) More

func (b IPv6Fragment) More() bool

More returns the "more" field of the ipv6 fragment.

func (IPv6Fragment) NextHeader

func (b IPv6Fragment) NextHeader() uint8

NextHeader returns the value of the "next header" field of the ipv6 fragment.

func (IPv6Fragment) Payload

func (b IPv6Fragment) Payload() []byte

Payload implements Network.Payload.

func (IPv6Fragment) SetChecksum

func (b IPv6Fragment) SetChecksum(uint16)

SetChecksum is not supported by IPv6Fragment.

func (IPv6Fragment) SetDestinationAddress

func (b IPv6Fragment) SetDestinationAddress(tcpip.Address)

SetDestinationAddress is not supported by IPv6Fragment.

func (IPv6Fragment) SetSourceAddress

func (b IPv6Fragment) SetSourceAddress(tcpip.Address)

SetSourceAddress is not supported by IPv6Fragment.

func (IPv6Fragment) SetTOS

func (b IPv6Fragment) SetTOS(t uint8, l uint32)

SetTOS is not supported by IPv6Fragment.

func (IPv6Fragment) SourceAddress

func (b IPv6Fragment) SourceAddress() tcpip.Address

SourceAddress is not supported by IPv6Fragment.

func (IPv6Fragment) TOS

func (b IPv6Fragment) TOS() (uint8, uint32)

TOS is not supported by IPv6Fragment.

func (IPv6Fragment) TransportProtocol

func (b IPv6Fragment) TransportProtocol() tcpip.TransportProtocolNumber

TransportProtocol implements Network.TransportProtocol.

type IPv6FragmentFields

type IPv6FragmentFields struct {
	// NextHeader is the "next header" field of an IPv6 fragment.
	NextHeader uint8

	// FragmentOffset is the "fragment offset" field of an IPv6 fragment.
	FragmentOffset uint16

	// M is the "more" field of an IPv6 fragment.
	M bool

	// Identification is the "identification" field of an IPv6 fragment.
	Identification uint32
}

IPv6FragmentFields contains the fields of an IPv6 fragment. It is used to describe the fields of a packet that needs to be encoded.

type NDPNeighborAdvert

type NDPNeighborAdvert []byte

NDPNeighborAdvert is an NDP Neighbor Advertisement message. It will only contain the body of an ICMPv6 packet.

See RFC 4861 section 4.4 for more details.

func (NDPNeighborAdvert) Options

func (b NDPNeighborAdvert) Options() NDPOptions

Options returns an NDPOptions of the the options body.

func (NDPNeighborAdvert) OverrideFlag

func (b NDPNeighborAdvert) OverrideFlag() bool

OverrideFlag returns the value of the Override Flag field.

func (NDPNeighborAdvert) RouterFlag

func (b NDPNeighborAdvert) RouterFlag() bool

RouterFlag returns the value of the Router Flag field.

func (NDPNeighborAdvert) SetOverrideFlag

func (b NDPNeighborAdvert) SetOverrideFlag(f bool)

SetOverrideFlag sets the value in the Override Flag field.

func (NDPNeighborAdvert) SetRouterFlag

func (b NDPNeighborAdvert) SetRouterFlag(f bool)

SetRouterFlag sets the value in the Router Flag field.

func (NDPNeighborAdvert) SetSolicitedFlag

func (b NDPNeighborAdvert) SetSolicitedFlag(f bool)

SetSolicitedFlag sets the value in the Solicited Flag field.

func (NDPNeighborAdvert) SetTargetAddress

func (b NDPNeighborAdvert) SetTargetAddress(addr tcpip.Address)

SetTargetAddress sets the value within the Target Address field.

func (NDPNeighborAdvert) SolicitedFlag

func (b NDPNeighborAdvert) SolicitedFlag() bool

SolicitedFlag returns the value of the Solicited Flag field.

func (NDPNeighborAdvert) TargetAddress

func (b NDPNeighborAdvert) TargetAddress() tcpip.Address

TargetAddress returns the value within the Target Address field.

type NDPNeighborSolicit

type NDPNeighborSolicit []byte

NDPNeighborSolicit is an NDP Neighbor Solicitation message. It will only contain the body of an ICMPv6 packet.

See RFC 4861 section 4.3 for more details.

func (NDPNeighborSolicit) Options

func (b NDPNeighborSolicit) Options() NDPOptions

Options returns an NDPOptions of the the options body.

func (NDPNeighborSolicit) SetTargetAddress

func (b NDPNeighborSolicit) SetTargetAddress(addr tcpip.Address)

SetTargetAddress sets the value within the Target Address field.

func (NDPNeighborSolicit) TargetAddress

func (b NDPNeighborSolicit) TargetAddress() tcpip.Address

TargetAddress returns the value within the Target Address field.

type NDPOption

type NDPOption interface {
	// Type returns the type of the receiver.
	Type() uint8

	// Length returns the length of the body of the receiver, in bytes.
	Length() int
	// contains filtered or unexported methods
}

NDPOption is the set of functions to be implemented by all NDP option types.

type NDPOptionIterator

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

NDPOptionIterator is an iterator of NDPOption.

Note, between when an NDPOptionIterator is obtained and last used, no changes to the NDPOptions may happen. Doing so may cause undefined and unexpected behaviour. It is fine to obtain an NDPOptionIterator, iterate over the first few NDPOption then modify the backing NDPOptions so long as the NDPOptionIterator obtained before modification is no longer used.

func (*NDPOptionIterator) Next

func (i *NDPOptionIterator) Next() (NDPOption, bool, error)

Next returns the next element in the backing NDPOptions, or true if we are done, or false if an error occured.

The return can be read as option, done, error. Note, option should only be used if done is false and error is nil.

type NDPOptions

type NDPOptions []byte

NDPOptions is a buffer of NDP options as defined by RFC 4861 section 4.6.

func (NDPOptions) Iter

func (b NDPOptions) Iter(check bool) (NDPOptionIterator, error)

Iter returns an iterator of NDPOption.

If check is true, Iter will do an integrity check on the options by iterating over it and returning an error if detected.

See NDPOptionIterator for more information.

func (NDPOptions) Serialize

func (b NDPOptions) Serialize(s NDPOptionsSerializer) int

Serialize serializes the provided list of NDP options into o.

Note, b must be of sufficient size to hold all the options in s. See NDPOptionsSerializer.Length for details on the getting the total size of a serialized NDPOptionsSerializer.

Serialize may panic if b is not of sufficient size to hold all the options in s.

type NDPOptionsSerializer

type NDPOptionsSerializer []NDPOption

NDPOptionsSerializer is a serializer for NDP options.

func (NDPOptionsSerializer) Length

func (b NDPOptionsSerializer) Length() int

Length returns the total number of bytes required to serialize.

type NDPPrefixInformation

type NDPPrefixInformation []byte

NDPPrefixInformation is the NDP Prefix Information option as defined by RFC 4861 section 4.6.2.

The length, in bytes, of a valid NDP Prefix Information option body MUST be ndpPrefixInformationLength bytes.

func (NDPPrefixInformation) AutonomousAddressConfigurationFlag

func (o NDPPrefixInformation) AutonomousAddressConfigurationFlag() bool

AutonomousAddressConfigurationFlag returns true if the prefix can be used for Stateless Address Auto-Configuration (as specified in RFC 4862).

func (NDPPrefixInformation) Length

func (o NDPPrefixInformation) Length() int

Length implements NDPOption.Length.

func (NDPPrefixInformation) OnLinkFlag

func (o NDPPrefixInformation) OnLinkFlag() bool

OnLinkFlag returns true of the prefix is considered on-link. On-link means that a forwarding node is not needed to send packets to other nodes on the same prefix.

Note, when this function returns false, no statement is made about the on-link property of a prefix. That is, if OnLinkFlag returns false, the caller MUST NOT conclude that the prefix is off-link and MUST NOT update any previously stored state for this prefix about its on-link status.

func (NDPPrefixInformation) PreferredLifetime

func (o NDPPrefixInformation) PreferredLifetime() time.Duration

PreferredLifetime returns the length of time that an address generated from the prefix via Stateless Address Auto-Configuration remains preferred. This value is relative to the send time of the packet that the Prefix Information option was present in.

Note, a value of 0 implies that addresses generated from the prefix should no longer remain preferred, and a value of infinity is represented by NDPPrefixInformationInfiniteLifetime.

Also note that the value of this field MUST NOT exceed the Valid Lifetime field to avoid preferring addresses that are no longer valid, for the purpose of Stateless Address Auto-Configuration.

func (NDPPrefixInformation) Prefix

func (o NDPPrefixInformation) Prefix() tcpip.Address

Prefix returns an IPv6 address or a prefix of an IPv6 address. The Prefix Length field (see NDPPrefixInformation.PrefixLength) contains the number of valid leading bits in the prefix.

Hosts SHOULD ignore an NDP Prefix Information option where the Prefix field holds the link-local prefix (fe80::).

func (NDPPrefixInformation) PrefixLength

func (o NDPPrefixInformation) PrefixLength() uint8

PrefixLength returns the value in the number of leading bits in the Prefix that are valid.

Valid values are in the range [0, 128], but o may not always contain valid values. It is up to the caller to valdiate the Prefix Information option.

func (NDPPrefixInformation) Subnet

func (o NDPPrefixInformation) Subnet() tcpip.Subnet

Subnet returns the Prefix field and Prefix Length field represented in a tcpip.Subnet.

func (NDPPrefixInformation) Type

func (o NDPPrefixInformation) Type() uint8

Type implements NDPOption.Type.

func (NDPPrefixInformation) ValidLifetime

func (o NDPPrefixInformation) ValidLifetime() time.Duration

ValidLifetime returns the length of time that the prefix is valid for the purpose of on-link determination. This value is relative to the send time of the packet that the Prefix Information option was present in.

Note, a value of 0 implies the prefix should not be considered as on-link, and a value of infinity/forever is represented by NDPPrefixInformationInfiniteLifetime.

type NDPRouterAdvert

type NDPRouterAdvert []byte

NDPRouterAdvert is an NDP Router Advertisement message. It will only contain the body of an ICMPv6 packet.

See RFC 4861 section 4.2 for more details.

func (NDPRouterAdvert) CurrHopLimit

func (b NDPRouterAdvert) CurrHopLimit() uint8

CurrHopLimit returns the value of the Curr Hop Limit field.

func (NDPRouterAdvert) ManagedAddrConfFlag

func (b NDPRouterAdvert) ManagedAddrConfFlag() bool

ManagedAddrConfFlag returns the value of the Managed Address Configuration flag.

func (NDPRouterAdvert) Options

func (b NDPRouterAdvert) Options() NDPOptions

Options returns an NDPOptions of the the options body.

func (NDPRouterAdvert) OtherConfFlag

func (b NDPRouterAdvert) OtherConfFlag() bool

OtherConfFlag returns the value of the Other Configuration flag.

func (NDPRouterAdvert) ReachableTime

func (b NDPRouterAdvert) ReachableTime() time.Duration

ReachableTime returns the time that a node assumes a neighbor is reachable after having received a reachability confirmation. A value of 0 means that it is unspecified by the source of the Router Advertisement message.

func (NDPRouterAdvert) RetransTimer

func (b NDPRouterAdvert) RetransTimer() time.Duration

RetransTimer returns the time between retransmitted Neighbor Solicitation messages. A value of 0 means that it is unspecified by the source of the Router Advertisement message.

func (NDPRouterAdvert) RouterLifetime

func (b NDPRouterAdvert) RouterLifetime() time.Duration

RouterLifetime returns the lifetime associated with the default router. A value of 0 means the source of the Router Advertisement is not a default router and SHOULD NOT appear on the default router list. Note, a value of 0 only means that the router should not be used as a default router, it does not apply to other information contained in the Router Advertisement.

type NDPTargetLinkLayerAddressOption

type NDPTargetLinkLayerAddressOption tcpip.LinkAddress

NDPTargetLinkLayerAddressOption is the NDP Target Link Layer Option as defined by RFC 4861 section 4.6.1.

It is the first X bytes following the NDP option's Type and Length field where X is the value in Length multiplied by lengthByteUnits - 2 bytes.

func (NDPTargetLinkLayerAddressOption) EthernetAddress

EthernetAddress will return an ethernet (MAC) address if the NDPTargetLinkLayerAddressOption's body has at minimum EthernetAddressSize bytes. If the body has more than EthernetAddressSize bytes, only the first EthernetAddressSize bytes are returned as that is all that is needed for an Ethernet address.

func (NDPTargetLinkLayerAddressOption) Length

Length implements NDPOption.Length.

func (NDPTargetLinkLayerAddressOption) Type

Type implements NDPOption.Type.

type Network

type Network interface {
	// SourceAddress returns the value of the "source address" field.
	SourceAddress() tcpip.Address

	// DestinationAddress returns the value of the "destination address"
	// field.
	DestinationAddress() tcpip.Address

	// Checksum returns the value of the "checksum" field.
	Checksum() uint16

	// SetSourceAddress sets the value of the "source address" field.
	SetSourceAddress(tcpip.Address)

	// SetDestinationAddress sets the value of the "destination address"
	// field.
	SetDestinationAddress(tcpip.Address)

	// SetChecksum sets the value of the "checksum" field.
	SetChecksum(uint16)

	// TransportProtocol returns the number of the transport protocol
	// stored in the payload.
	TransportProtocol() tcpip.TransportProtocolNumber

	// Payload returns a byte slice containing the payload of the network
	// packet.
	Payload() []byte

	// TOS returns the values of the "type of service" and "flow label" fields.
	TOS() (uint8, uint32)

	// SetTOS sets the values of the "type of service" and "flow label" fields.
	SetTOS(t uint8, l uint32)
}

Network offers generic methods to query and/or update the fields of the header of a network protocol buffer.

type SACKBlock

type SACKBlock struct {
	// Start indicates the lowest sequence number in the block.
	Start seqnum.Value

	// End indicates the sequence number immediately following the last
	// sequence number of this block.
	End seqnum.Value
}

SACKBlock represents a single contiguous SACK block.

+stateify savable

func (SACKBlock) Contains

func (r SACKBlock) Contains(b SACKBlock) bool

Contains returns true if b is completely contained in r.

func (SACKBlock) Less

func (r SACKBlock) Less(b btree.Item) bool

Less returns true if r.Start < b.Start.

type TCP

type TCP []byte

TCP represents a TCP header stored in a byte array.

func (TCP) AckNumber

func (b TCP) AckNumber() uint32

AckNumber returns the "ack number" field of the tcp header.

func (TCP) CalculateChecksum

func (b TCP) CalculateChecksum(partialChecksum uint16) uint16

CalculateChecksum calculates the checksum of the tcp segment. partialChecksum is the checksum of the network-layer pseudo-header and the checksum of the segment data.

func (TCP) Checksum

func (b TCP) Checksum() uint16

Checksum returns the "checksum" field of the tcp header.

func (TCP) DataOffset

func (b TCP) DataOffset() uint8

DataOffset returns the "data offset" field of the tcp header.

func (TCP) DestinationPort

func (b TCP) DestinationPort() uint16

DestinationPort returns the "destination port" field of the tcp header.

func (TCP) Encode

func (b TCP) Encode(t *TCPFields)

Encode encodes all the fields of the tcp header.

func (TCP) EncodePartial

func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, rcvwnd uint16)

EncodePartial updates a subset of the fields of the tcp header. It is useful in cases when similar segments are produced.

func (TCP) Flags

func (b TCP) Flags() uint8

Flags returns the flags field of the tcp header.

func (TCP) Options

func (b TCP) Options() []byte

Options returns a slice that holds the unparsed TCP options in the segment.

func (TCP) ParsedOptions

func (b TCP) ParsedOptions() TCPOptions

ParsedOptions returns a TCPOptions structure which parses and caches the TCP option values in the TCP segment. NOTE: Invoking this function repeatedly is expensive as it reparses the options on each invocation.

func (TCP) Payload

func (b TCP) Payload() []byte

Payload returns the data in the tcp packet.

func (TCP) SequenceNumber

func (b TCP) SequenceNumber() uint32

SequenceNumber returns the "sequence number" field of the tcp header.

func (TCP) SetChecksum

func (b TCP) SetChecksum(checksum uint16)

SetChecksum sets the checksum field of the tcp header.

func (TCP) SetDestinationPort

func (b TCP) SetDestinationPort(port uint16)

SetDestinationPort sets the "destination port" field of the tcp header.

func (TCP) SetSourcePort

func (b TCP) SetSourcePort(port uint16)

SetSourcePort sets the "source port" field of the tcp header.

func (TCP) SourcePort

func (b TCP) SourcePort() uint16

SourcePort returns the "source port" field of the tcp header.

func (TCP) WindowSize

func (b TCP) WindowSize() uint16

WindowSize returns the "window size" field of the tcp header.

type TCPFields

type TCPFields struct {
	// SrcPort is the "source port" field of a TCP packet.
	SrcPort uint16

	// DstPort is the "destination port" field of a TCP packet.
	DstPort uint16

	// SeqNum is the "sequence number" field of a TCP packet.
	SeqNum uint32

	// AckNum is the "acknowledgement number" field of a TCP packet.
	AckNum uint32

	// DataOffset is the "data offset" field of a TCP packet.
	DataOffset uint8

	// Flags is the "flags" field of a TCP packet.
	Flags uint8

	// WindowSize is the "window size" field of a TCP packet.
	WindowSize uint16

	// Checksum is the "checksum" field of a TCP packet.
	Checksum uint16

	// UrgentPointer is the "urgent pointer" field of a TCP packet.
	UrgentPointer uint16
}

TCPFields contains the fields of a TCP packet. It is used to describe the fields of a packet that needs to be encoded.

type TCPOptions

type TCPOptions struct {
	// TS is true if the TimeStamp option is enabled.
	TS bool

	// TSVal is the value in the TSVal field of the segment.
	TSVal uint32

	// TSEcr is the value in the TSEcr field of the segment.
	TSEcr uint32

	// SACKBlocks are the SACK blocks specified in the segment.
	SACKBlocks []SACKBlock
}

TCPOptions are used to parse and cache the TCP segment options for a non syn/syn-ack segment.

+stateify savable

func ParseTCPOptions

func ParseTCPOptions(b []byte) TCPOptions

ParseTCPOptions extracts and stores all known options in the provided byte slice in a TCPOptions structure.

type TCPSynOptions

type TCPSynOptions struct {
	// MSS is the maximum segment size provided by the peer in the SYN.
	MSS uint16

	// WS is the window scale option provided by the peer in the SYN.
	//
	// Set to -1 if no window scale option was provided.
	WS int

	// TS is true if the timestamp option was provided in the syn/syn-ack.
	TS bool

	// TSVal is the value of the TSVal field in the timestamp option.
	TSVal uint32

	// TSEcr is the value of the TSEcr field in the timestamp option.
	TSEcr uint32

	// SACKPermitted is true if the SACK option was provided in the SYN/SYN-ACK.
	SACKPermitted bool
}

TCPSynOptions is used to return the parsed TCP Options in a syn segment.

func ParseSynOptions

func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions

ParseSynOptions parses the options received in a SYN segment and returns the relevant ones. opts should point to the option part of the TCP Header.

type Transport

type Transport interface {
	// SourcePort returns the value of the "source port" field.
	SourcePort() uint16

	// Destination returns the value of the "destination port" field.
	DestinationPort() uint16

	// Checksum returns the value of the "checksum" field.
	Checksum() uint16

	// SetSourcePort sets the value of the "source port" field.
	SetSourcePort(uint16)

	// SetDestinationPort sets the value of the "destination port" field.
	SetDestinationPort(uint16)

	// SetChecksum sets the value of the "checksum" field.
	SetChecksum(uint16)

	// Payload returns the data carried in the transport buffer.
	Payload() []byte
}

Transport offers generic methods to query and/or update the fields of the header of a transport protocol buffer.

type UDP

type UDP []byte

UDP represents a UDP header stored in a byte array.

func (UDP) CalculateChecksum

func (b UDP) CalculateChecksum(partialChecksum uint16) uint16

CalculateChecksum calculates the checksum of the udp packet, given the checksum of the network-layer pseudo-header and the checksum of the payload.

func (UDP) Checksum

func (b UDP) Checksum() uint16

Checksum returns the "checksum" field of the udp header.

func (UDP) DestinationPort

func (b UDP) DestinationPort() uint16

DestinationPort returns the "destination port" field of the udp header.

func (UDP) Encode

func (b UDP) Encode(u *UDPFields)

Encode encodes all the fields of the udp header.

func (UDP) Length

func (b UDP) Length() uint16

Length returns the "length" field of the udp header.

func (UDP) Payload

func (b UDP) Payload() []byte

Payload returns the data contained in the UDP datagram.

func (UDP) SetChecksum

func (b UDP) SetChecksum(checksum uint16)

SetChecksum sets the "checksum" field of the udp header.

func (UDP) SetDestinationPort

func (b UDP) SetDestinationPort(port uint16)

SetDestinationPort sets the "destination port" field of the udp header.

func (UDP) SetSourcePort

func (b UDP) SetSourcePort(port uint16)

SetSourcePort sets the "source port" field of the udp header.

func (UDP) SourcePort

func (b UDP) SourcePort() uint16

SourcePort returns the "source port" field of the udp header.

type UDPFields

type UDPFields struct {
	// SrcPort is the "source port" field of a UDP packet.
	SrcPort uint16

	// DstPort is the "destination port" field of a UDP packet.
	DstPort uint16

	// Length is the "length" field of a UDP packet.
	Length uint16

	// Checksum is the "checksum" field of a UDP packet.
	Checksum uint16
}

UDPFields contains the fields of a UDP packet. It is used to describe the fields of a packet that needs to be encoded.

Jump to

Keyboard shortcuts

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