header

package
v0.0.0-...-0f8db9f Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, MIT Imports: 14 Imported by: 361

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 = 28
)
View Source
const (
	// EthernetMinimumSize is the minimum size of a valid ethernet frame.
	EthernetMinimumSize = 14

	// EthernetMaximumSize is the maximum size of a valid ethernet frame.
	EthernetMaximumSize = 18

	// EthernetAddressSize is the size, in bytes, of an ethernet address.
	EthernetAddressSize = 6

	// UnspecifiedEthernetAddress is the unspecified ethernet address
	// (all bits set to 0).
	UnspecifiedEthernetAddress = tcpip.LinkAddress("\x00\x00\x00\x00\x00\x00")

	// EthernetBroadcastAddress is an ethernet address that addresses every node
	// on a local link.
	EthernetBroadcastAddress = tcpip.LinkAddress("\xff\xff\xff\xff\xff\xff")
)
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 Universal 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

	// ICMPv4MinimumErrorPayloadSize Is the smallest number of bytes of an
	// errant packet's transport layer that an ICMP error type packet should
	// attempt to send as per RFC 792 (see each type) and RFC 1122
	// section 3.2.2 which states:
	//      Every ICMP error message includes the Internet header and at
	//      least the first 8 data octets of the datagram that triggered
	//      the error; more than 8 octets MAY be sent; this header and data
	//      MUST be unchanged from the received datagram.
	//
	// RFC 792 shows:
	//   0                   1                   2                   3
	//  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	// |     Type      |     Code      |          Checksum             |
	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	// |                             unused                            |
	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	// |      Internet Header + 64 bits of Original Data Datagram      |
	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	ICMPv4MinimumErrorPayloadSize = 8

	// ICMPv4ProtocolNumber is the ICMP transport protocol number.
	ICMPv4ProtocolNumber tcpip.TransportProtocolNumber = 1
)
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

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

	// ICMPv6ErrorHeaderSize is the size of an ICMP error packet header,
	// as per RFC 4443, Appendix A, item 4 and the errata.
	//   ... all ICMP error messages shall have exactly
	//   32 bits of type-specific data, so that receivers can reliably find
	//   the embedded invoking packet even when they don't recognize the
	//   ICMP message Type.
	ICMPv6ErrorHeaderSize = 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

	// ICMPv6ChecksumOffset is the offset of the checksum field
	// in an ICMPv6 message.
	ICMPv6ChecksumOffset = 2

	// 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 (
	// IGMPMinimumSize is the minimum size of a valid IGMP packet in bytes,
	// as per RFC 2236, Section 2, Page 2.
	IGMPMinimumSize = 8

	// IGMPQueryMinimumSize is the minimum size of a valid Membership Query
	// Message in bytes, as per RFC 2236, Section 2, Page 2.
	IGMPQueryMinimumSize = 8

	// IGMPReportMinimumSize is the minimum size of a valid Report Message in
	// bytes, as per RFC 2236, Section 2, Page 2.
	IGMPReportMinimumSize = 8

	// IGMPLeaveMessageMinimumSize is the minimum size of a valid Leave Message
	// in bytes, as per RFC 2236, Section 2, Page 2.
	IGMPLeaveMessageMinimumSize = 8

	// IGMPTTL is the TTL for all IGMP messages, as per RFC 2236, Section 3, Page
	// 3.
	IGMPTTL = 1

	// IGMPProtocolNumber is IGMP's transport protocol number.
	IGMPProtocolNumber tcpip.TransportProtocolNumber = 2
)
View Source
const (
	// IPv4MinimumSize is the minimum size of a valid IPv4 packet;
	// i.e. a packet header with no options.
	IPv4MinimumSize = 20

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

	// IPv4MaximumOptionsSize is the largest size the IPv4 options can be.
	IPv4MaximumOptionsSize = IPv4MaximumHeaderSize - IPv4MinimumSize

	// IPv4MaximumPayloadSize is the maximum size of a valid IPv4 payload.
	//
	// Linux limits this to 65,515 octets (the max IP datagram size - the IPv4
	// header size). But RFC 791 section 3.2 discusses the design of the IPv4
	// fragment "allows 2**13 = 8192 fragments of 8 octets each for a total of
	// 65,536 octets. Note that this is consistent with the datagram total
	// length field (of course, the header is counted in the total length and not
	// in the fragments)."
	IPv4MaximumPayloadSize = 65536

	// 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

	// IPv4AddressSizeBits is the size, in bits, of an IPv4 address.
	IPv4AddressSizeBits = 32

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

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

	// IPv4MinimumProcessableDatagramSize is the minimum size of an IP
	// packet that every IPv4 capable host must be able to
	// process/reassemble.
	IPv4MinimumProcessableDatagramSize = 576

	// IPv4MinimumMTU is the minimum MTU required by IPv4, per RFC 791,
	// section 3.2:
	//   Every internet module must be able to forward a datagram of 68 octets
	//   without further fragmentation.  This is because an internet header may be
	//   up to 60 octets, and the minimum fragment is 8 octets.
	IPv4MinimumMTU = 68
)
View Source
const (
	IPv4FlagMoreFragments = 1 << iota
	IPv4FlagDontFragment
)

Flags that may be set in an IPv4 packet.

View Source
const (
	// IPv4OptionTimestampHdrLength is the length of the timestamp option header.
	IPv4OptionTimestampHdrLength = 4

	// IPv4OptionTimestampSize is the size of an IP timestamp.
	IPv4OptionTimestampSize = 4

	// IPv4OptionTimestampWithAddrSize is the size of an IP timestamp + Address.
	IPv4OptionTimestampWithAddrSize = IPv4AddressSize + IPv4OptionTimestampSize

	// IPv4OptionTimestampMaxSize is limited by space for options
	IPv4OptionTimestampMaxSize = IPv4MaximumOptionsSize

	// IPv4OptionTimestampOnlyFlag is a flag indicating that only timestamp
	// is present.
	IPv4OptionTimestampOnlyFlag IPv4OptTSFlags = 0

	// IPv4OptionTimestampWithIPFlag is a flag indicating that both timestamps and
	// IP are present.
	IPv4OptionTimestampWithIPFlag IPv4OptTSFlags = 1

	// IPv4OptionTimestampWithPredefinedIPFlag is a flag indicating that
	// predefined IP is present.
	IPv4OptionTimestampWithPredefinedIPFlag IPv4OptTSFlags = 3
)

Timestamp option specific related constants.

View Source
const (
	// IPv4OptTSPointerOffset is the offset of the Timestamp pointer field.
	IPv4OptTSPointerOffset = 2

	// IPv4OptTSPointerOffset is the offset of the combined Flag and Overflow
	// fields, (each being 4 bits).
	IPv4OptTSOFLWAndFLGOffset = 3
)

IP Timestamp option fields.

View Source
const (
	// IPv4OptionRecordRouteHdrLength is the length of the Record Route option
	// header.
	IPv4OptionRecordRouteHdrLength = 3

	// IPv4OptRRPointerOffset is the offset to the pointer field in an RR
	// option, which points to the next free slot in the list of addresses.
	IPv4OptRRPointerOffset = 2
)

RecordRoute option specific related constants.

from RFC 791 page 20:

Record Route

      +--------+--------+--------+---------//--------+
      |00000111| length | pointer|     route data    |
      +--------+--------+--------+---------//--------+
        Type=7

      The record route option provides a means to record the route of
      an internet datagram.

      The option begins with the option type code.  The second octet
      is the option length which includes the option type code and the
      length octet, the pointer octet, and length-3 octets of route
      data.  The third octet is the pointer into the route data
      indicating the octet which begins the next area to store a route
      address.  The pointer is relative to this option, and the
      smallest legal value for the pointer is 4.
View Source
const (
	// IPv4OptionRouterAlertLength is the length of a Router Alert option.
	IPv4OptionRouterAlertLength = 4

	// IPv4OptionRouterAlertValue is the only permissible value of the 16 bit
	// payload of the router alert option.
	IPv4OptionRouterAlertValue = 0

	// IPv4OptionRouterAlertValueOffset is the offset for the value of a
	// RouterAlert option.
	IPv4OptionRouterAlertValueOffset = 2
)

Router Alert option specific related constants.

from RFC 2113 section 2.1:

+--------+--------+--------+--------+
|10010100|00000100|  2 octet value  |
+--------+--------+--------+--------+

Type:
Copied flag:  1 (all fragments must carry the option)
Option class: 0 (control)
Option number: 20 (decimal)

Length: 4

Value:  A two octet code with the following values:
0 - Router shall examine packet
1-65535 - Reserved
View Source
const (
	// IPv4OptionExperimentLength  is the length of an Experiment option.
	IPv4OptionExperimentLength = 4

	// IPv4OptionExperimentValueOffset is the offset for the value of an
	// Experiment option.
	IPv4OptionExperimentValueOffset = 2
)

Experiment option specific related constants.

View Source
const (

	// IPv6PayloadLenOffset is the offset of the PayloadLength field in
	// IPv6 header.
	IPv6PayloadLenOffset = 4
	// IPv6NextHeaderOffset is the offset of the NextHeader field in
	// IPv6 header.
	IPv6NextHeaderOffset = 6

	// IPv6FixedHeaderSize is the size of the fixed header.
	IPv6FixedHeaderSize = v6DstAddr + IPv6AddressSize
)
View Source
const (
	// IPv6MinimumSize is the minimum size of a valid IPv6 packet.
	IPv6MinimumSize = IPv6FixedHeaderSize

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

	// IPv6AddressSizeBits is the size, in bits, of an IPv6 address.
	IPv6AddressSizeBits = 128

	// IPv6MaximumPayloadSize is the maximum size of a valid IPv6 payload per
	// RFC 8200 Section 4.5.
	IPv6MaximumPayloadSize = 65535

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

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

	// IIDSize is the size of an interface identifier (IID), in bytes, as
	// defined by RFC 4291 section 2.5.1.
	IIDSize = 8

	// IPv6MinimumMTU is the minimum MTU required by IPv6, per RFC 8200,
	// section 5:
	//   IPv6 requires that every link in the Internet have an MTU of 1280 octets
	//   or greater.  This is known as the IPv6 minimum link MTU.
	IPv6MinimumMTU = 1280

	// IIDOffsetInIPv6Address is the offset, in bytes, from the start
	// of an IPv6 address to the beginning of the interface identifier
	// (IID) for auto-generated addresses. That is, all bytes before
	// the IIDOffsetInIPv6Address-th byte are the prefix bytes, and all
	// bytes including and after the IIDOffsetInIPv6Address-th byte are
	// for the IID.
	IIDOffsetInIPv6Address = 8

	// OpaqueIIDSecretKeyMinBytes is the recommended minimum number of bytes
	// for the secret key used to generate an opaque interface identifier as
	// outlined by RFC 7217.
	OpaqueIIDSecretKeyMinBytes = 16
)
View Source
const (
	IPv6Reserved0MulticastScope         = IPv6MulticastScope(0x0)
	IPv6InterfaceLocalMulticastScope    = IPv6MulticastScope(0x1)
	IPv6LinkLocalMulticastScope         = IPv6MulticastScope(0x2)
	IPv6RealmLocalMulticastScope        = IPv6MulticastScope(0x3)
	IPv6AdminLocalMulticastScope        = IPv6MulticastScope(0x4)
	IPv6SiteLocalMulticastScope         = IPv6MulticastScope(0x5)
	IPv6OrganizationLocalMulticastScope = IPv6MulticastScope(0x8)
	IPv6GlobalMulticastScope            = IPv6MulticastScope(0xE)
	IPv6ReservedFMulticastScope         = IPv6MulticastScope(0xF)
)

The various values for IPv6 multicast scopes, as per RFC 7346 section 2:

+------+--------------------------+-------------------------+
| scop | NAME                     | REFERENCE               |
+------+--------------------------+-------------------------+
|  0   | Reserved                 | [RFC4291], RFC 7346     |
|  1   | Interface-Local scope    | [RFC4291], RFC 7346     |
|  2   | Link-Local scope         | [RFC4291], RFC 7346     |
|  3   | Realm-Local scope        | [RFC4291], RFC 7346     |
|  4   | Admin-Local scope        | [RFC4291], RFC 7346     |
|  5   | Site-Local scope         | [RFC4291], RFC 7346     |
|  6   | Unassigned               |                         |
|  7   | Unassigned               |                         |
|  8   | Organization-Local scope | [RFC4291], RFC 7346     |
|  9   | Unassigned               |                         |
|  A   | Unassigned               |                         |
|  B   | Unassigned               |                         |
|  C   | Unassigned               |                         |
|  D   | Unassigned               |                         |
|  E   | Global scope             | [RFC4291], RFC 7346     |
|  F   | Reserved                 | [RFC4291], RFC 7346     |
+------+--------------------------+-------------------------+
View Source
const (

	// IPv6FragmentExtHdrLength is the length of an IPv6 extension header, in
	// bytes.
	IPv6FragmentExtHdrLength = 8

	// IPv6FragmentExtHdrFragmentOffsetBytesPerUnit is the unit size of a Fragment
	// extension header's Fragment Offset field. That is, given a Fragment Offset
	// of 2, the extension header is indicating that the fragment's payload
	// starts at the 16th byte in the reassembled packet.
	IPv6FragmentExtHdrFragmentOffsetBytesPerUnit = 8
)
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 (
	// MLDMinimumSize is the minimum size for an MLD message.
	MLDMinimumSize = 20

	// MLDHopLimit is the Hop Limit for all IPv6 packets with an MLD message, as
	// per RFC 2710 section 3.
	MLDHopLimit = 1
)
View Source
const (
	// MLDv2QueryMinimumSize is the minimum size for an MLDv2 message.
	MLDv2QueryMinimumSize = 24

	// MLDv2ReportMinimumSize is the minimum size of an MLDv2 report.
	MLDv2ReportMinimumSize = 24
)
View Source
const (
	// NDPLinkLayerAddressSize is the size of a Source or Target Link Layer
	// Address option for an Ethernet address.
	NDPLinkLayerAddressSize = 8

	// NDPInfiniteLifetime is a value that represents infinity for the
	// 4-byte lifetime fields found in various NDP options. Its value is
	// (2^32 - 1)s = 4294967295s.
	NDPInfiniteLifetime = time.Second * math.MaxUint32
)
View Source
const (
	// HighRoutePreference indicates a high preference, as per
	// RFC 4191 section 2.1.
	HighRoutePreference NDPRoutePreference = 0b01

	// MediumRoutePreference indicates a medium preference, as per
	// RFC 4191 section 2.1.
	//
	// This is the default preference value.
	MediumRoutePreference = 0b00

	// LowRoutePreference indicates a low preference, as per
	// RFC 4191 section 2.1.
	LowRoutePreference = 0b11

	// ReservedRoutePreference is a reserved preference value, as per
	// RFC 4191 section 2.1.
	//
	// It MUST NOT be sent.
	ReservedRoutePreference = 0b10
)
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 (
	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 (
	TCPOptionMSSLength           = 4
	TCPOptionTSLength            = 10
	TCPOptionWSLength            = 3
	TCPOptionSackPermittedLength = 2
)

Option Lengths.

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

	// TCPTotalHeaderMaximumSize is the maximum size of headers from all layers in
	// a TCP packet. It analogous to MAX_TCP_HEADER in Linux.
	//
	// TODO(b/319936470): Investigate why this needs to be at least 140 bytes. In
	// Linux this value is at least 160, but in theory we should be able to use
	// 138. In practice anything less than 140 starts to break GSO on gVNIC
	// hardware.
	TCPTotalHeaderMaximumSize = 160

	// 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

	// TCPMinimumSendMSS is the minimum value for MSS in a sender. This is the
	// same as the value TCP_MIN_SND_MSS in net/tcp.h.
	TCPMinimumSendMSS = TCPOptionsMaximumSize + MinIPFragmentPayloadSize

	// 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

	// UDPMaximumSize is the maximum size of a valid UDP packet. The length field
	// in the UDP header is 16 bits as per RFC 768.
	UDPMaximumSize = math.MaxUint16

	// UDPProtocolNumber is UDP's transport protocol number.
	UDPProtocolNumber tcpip.TransportProtocolNumber = 17
)
View Source
const DatagramMaximumSize = 0xffff // 65KB.

DatagramMaximumSize is the maximum supported size of a single datagram.

View Source
const (
	// GUEMinimumSize is the minimum size of a valid GUE packet.
	GUEMinimumSize = 4
)
View Source
const (
	// IGMPv3QueryMinimumSize is the mimum size of a valid IGMPv3 query,
	// as per RFC 3376 section 4.1.
	IGMPv3QueryMinimumSize = 12
)
View Source
const (
	IPv4IHLStride = 4
)

RFC 791 page 11 shows the header length (IHL) is in the lower 4 bits of the first byte, and is counted in multiples of 4 bytes.

 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  (...)
 Version:  4 bits
   The Version field indicates the format of the internet header.  This
   document describes version 4.

 IHL:  4 bits
   Internet Header Length is the length of the internet header in 32
   bit words, and thus points to the beginning of the data.  Note that
   the minimum value for a correct header is 5.
View Source
const (

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

RFC 971 defines the fields of the IPv4 header on page 11 using the following diagram: ("Figure 4")

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination Address                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
View Source
const (
	IPv6ExperimentHdrLength = 8
)

ipv6RouterAlertPayloadLength is the length of the Router Alert payload as defined in RFC 4727 section 3.3.

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
)

As per RFC 4191 section 2.2,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cur Hop Limit |M|O|H|Prf|Resvd|       Router Lifetime         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Reachable Time                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Retrans Timer                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options ...
+-+-+-+-+-+-+-+-+-+-+-+-
View Source
const (
	// NDPRSMinimumSize is the minimum size of a valid NDP Router
	// Solicitation message (body of an ICMPv6 packet).
	NDPRSMinimumSize = 4
)
View Source
const (
	// UDPMaximumPacketSize is the largest possible UDP packet.
	UDPMaximumPacketSize = 0xffff
)
View Source
const (
	// VirtioNetHeaderSize is the size of VirtioNetHeader in bytes.
	VirtioNetHeaderSize = 10
)

Variables

View Source
var (
	// IPv4AllSystems is the all systems IPv4 multicast address as per
	// IANA's IPv4 Multicast Address Space Registry. See
	// https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml.
	IPv4AllSystems = tcpip.AddrFrom4([4]byte{0xe0, 0x00, 0x00, 0x01})

	// IPv4Broadcast is the broadcast address of the IPv4 procotol.
	IPv4Broadcast = tcpip.AddrFrom4([4]byte{0xff, 0xff, 0xff, 0xff})

	// IPv4Any is the non-routable IPv4 "any" meta address.
	IPv4Any = tcpip.AddrFrom4([4]byte{0x00, 0x00, 0x00, 0x00})

	// IPv4AllRoutersGroup is a multicast address for all routers.
	IPv4AllRoutersGroup = tcpip.AddrFrom4([4]byte{0xe0, 0x00, 0x00, 0x02})

	// IPv4Loopback is the loopback IPv4 address.
	IPv4Loopback = tcpip.AddrFrom4([4]byte{0x7f, 0x00, 0x00, 0x01})
)
View Source
var (
	// 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.AddrFrom16([16]byte{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})

	// IPv6AllRoutersInterfaceLocalMulticastAddress is an interface-local
	// multicast group that all IPv6 routers MUST join, as per RFC 4291, section
	// 2.8. Packets destined to this address will reach the router on an
	// interface.
	//
	// The address is ff01::2.
	IPv6AllRoutersInterfaceLocalMulticastAddress = tcpip.AddrFrom16([16]byte{0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02})

	// IPv6AllRoutersLinkLocalMulticastAddress is a link-local multicast group
	// that all IPv6 routers MUST join, as per RFC 4291, section 2.8. Packets
	// destined to this address will reach all routers on a link.
	//
	// The address is ff02::2.
	IPv6AllRoutersLinkLocalMulticastAddress = tcpip.AddrFrom16([16]byte{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02})

	// IPv6AllRoutersSiteLocalMulticastAddress is a site-local multicast group
	// that all IPv6 routers MUST join, as per RFC 4291, section 2.8. Packets
	// destined to this address will reach all routers in a site.
	//
	// The address is ff05::2.
	IPv6AllRoutersSiteLocalMulticastAddress = tcpip.AddrFrom16([16]byte{0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02})

	// IPv6Loopback is the IPv6 Loopback address.
	IPv6Loopback = tcpip.AddrFrom16([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})

	// IPv6Any is the non-routable IPv6 "any" meta address. It is also
	// known as the unspecified address.
	IPv6Any = tcpip.AddrFrom16([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
)
View Source
var (
	ErrNDPOptMalformedBody   = errors.New("NDP option has a malformed body")
	ErrNDPOptMalformedHeader = errors.New("NDP option has a malformed header")
)

Potential errors when iterating over an NDPOptions.

View Source
var ErrMalformedIPv6ExtHdrOption = errors.New("malformed IPv6 extension header option")

ErrMalformedIPv6ExtHdrOption indicates that an IPv6 extension header option is malformed.

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 (
	// IGMPv3RoutersAddress is the address to send IGMPv3 reports to.
	//
	// As per RFC 3376 section 4.2.14,
	//
	//   Version 3 Reports are sent with an IP destination address of
	//   224.0.0.22, to which all IGMPv3-capable multicast routers listen.
	IGMPv3RoutersAddress = tcpip.AddrFrom4([4]byte{0xe0, 0x00, 0x00, 0x16})
)
View Source
var IPv4CurrentNetworkSubnet = func() tcpip.Subnet {
	subnet, err := tcpip.NewSubnet(IPv4Any, tcpip.MaskFrom("\xff\x00\x00\x00"))
	if err != nil {
		panic(err)
	}
	return subnet
}()

IPv4CurrentNetworkSubnet is the subnet of addresses for the current network, per RFC 6890 section 2.2.2,

+----------------------+----------------------------+
| Attribute            | Value                      |
+----------------------+----------------------------+
| Address Block        | 0.0.0.0/8                  |
| Name                 | "This host on this network"|
| RFC                  | [RFC1122], Section 3.2.1.3 |
| Allocation Date      | September 1981             |
| Termination Date     | N/A                        |
| Source               | True                       |
| Destination          | False                      |
| Forwardable          | False                      |
| Global               | False                      |
| Reserved-by-Protocol | True                       |
+----------------------+----------------------------+
View Source
var IPv4EmptySubnet = func() tcpip.Subnet {
	subnet, err := tcpip.NewSubnet(IPv4Any, tcpip.MaskFrom("\x00\x00\x00\x00"))
	if err != nil {
		panic(err)
	}
	return subnet
}()

IPv4EmptySubnet is the empty IPv4 subnet.

View Source
var IPv4LoopbackSubnet = func() tcpip.Subnet {
	subnet, err := tcpip.NewSubnet(tcpip.AddrFrom4([4]byte{0x7f, 0x00, 0x00, 0x00}), tcpip.MaskFrom("\xff\x00\x00\x00"))
	if err != nil {
		panic(err)
	}
	return subnet
}()

IPv4LoopbackSubnet is the loopback subnet for IPv4.

View Source
var IPv4MappedIPv6Subnet = tcpip.AddressWithPrefix{
	Address:   tcpip.AddrFrom16([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}),
	PrefixLen: 96,
}.Subnet()

IPv4MappedIPv6Subnet is the prefix for an IPv4 mapped IPv6 address as defined by RFC 4291 section 2.5.5.

View Source
var IPv6EmptySubnet = tcpip.AddressWithPrefix{
	Address:   IPv6Any,
	PrefixLen: 0,
}.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:   tcpip.AddrFrom16([16]byte{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
	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 (
	// MLDv2RoutersAddress is the address to send MLDv2 reports to.
	//
	// As per RFC 3810 section 5.2.14,
	//
	//   Version 2 Multicast Listener Reports are sent with an IP destination
	//   address of FF02:0:0:0:0:0:0:16, to which all MLDv2-capable multicast
	//   routers listen (see section 11 for IANA considerations related to
	//   this special destination address).
	MLDv2RoutersAddress = tcpip.AddrFrom16([16]byte{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16})
)

Functions

func Acceptable

func Acceptable(segSeq seqnum.Value, segLen seqnum.Size, rcvNxt, rcvAcc seqnum.Value) bool

Acceptable checks if a segment that starts at segSeq and has length segLen is "acceptable" for arriving in a receive window that starts at rcvNxt and ends before rcvAcc, according to the table on page 26 and 69 of RFC 793.

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 AppendOpaqueInterfaceIdentifier

func AppendOpaqueInterfaceIdentifier(buf []byte, prefix tcpip.Subnet, nicName string, dadCounter uint8, secretKey []byte) []byte

AppendOpaqueInterfaceIdentifier appends a 64 bit opaque interface identifier (IID) to buf as outlined by RFC 7217 and returns the extended buffer.

The opaque IID is generated from the cryptographic hash of the concatenation of the prefix, NIC's name, DAD counter (DAD retry counter) and the secret key. The secret key SHOULD be at least OpaqueIIDSecretKeyMinBytes bytes and MUST be generated to a pseudo-random number. See RFC 4086 for randomness requirements for security.

If buf has enough capacity for the IID (IIDSize bytes), a new underlying array for the buffer will not be allocated.

func DecisecondToDuration

func DecisecondToDuration(ds uint16) time.Duration

DecisecondToDuration converts a value representing deci-seconds to a time.Duration.

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 EthernetAdddressToModifiedEUI64IntoBuf

func EthernetAdddressToModifiedEUI64IntoBuf(linkAddr tcpip.LinkAddress, buf []byte)

EthernetAdddressToModifiedEUI64IntoBuf populates buf with a modified EUI-64 from a 48-bit Ethernet/MAC address, as per RFC 4291 section 2.5.1.

buf MUST be at least 8 bytes.

func EthernetAddressFromMulticastIPv4Address

func EthernetAddressFromMulticastIPv4Address(addr tcpip.Address) tcpip.LinkAddress

EthernetAddressFromMulticastIPv4Address returns a multicast Ethernet address for a multicast IPv4 address.

addr MUST be a multicast IPv4 address.

func EthernetAddressFromMulticastIPv6Address

func EthernetAddressFromMulticastIPv6Address(addr tcpip.Address) tcpip.LinkAddress

EthernetAddressFromMulticastIPv6Address returns a multicast Ethernet address for a multicast IPv6 address.

addr MUST be a multicast IPv6 address.

func EthernetAddressToModifiedEUI64

func EthernetAddressToModifiedEUI64(linkAddr tcpip.LinkAddress) [IIDSize]byte

EthernetAddressToModifiedEUI64 computes a modified EUI-64 from a 48-bit Ethernet/MAC address, as per RFC 4291 section 2.5.1.

func GenerateTempIPv6SLAACAddr

func GenerateTempIPv6SLAACAddr(tempIIDHistory []byte, stableAddr tcpip.Address) tcpip.AddressWithPrefix

GenerateTempIPv6SLAACAddr generates a temporary SLAAC IPv6 address for an associated stable/permanent SLAAC address.

GenerateTempIPv6SLAACAddr will update the temporary IID history value to be used when generating a new temporary IID.

Panics if tempIIDHistory is not at least IIDSize bytes.

func ICMPv4Checksum

func ICMPv4Checksum(h ICMPv4, payloadCsum uint16) uint16

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

func ICMPv6Checksum

func ICMPv6Checksum(params ICMPv6ChecksumParams) uint16

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

func IGMPCalculateChecksum

func IGMPCalculateChecksum(h IGMP) uint16

IGMPCalculateChecksum calculates the IGMP checksum over the provided IGMP header.

func IGMPv3MaximumResponseDelay

func IGMPv3MaximumResponseDelay(codeRaw uint8) time.Duration

IGMPv3MaximumResponseDelay returns the Maximum Response Delay in an IGMPv3 Maximum Response Code.

As per RFC 3376 section 4.1.1,

The Max Resp Code field specifies the maximum time allowed before
sending a responding report.  The actual time allowed, called the Max
Resp Time, is represented in units of 1/10 second and is derived from
the Max Resp Code as follows:

If Max Resp Code < 128, Max Resp Time = Max Resp Code

If Max Resp Code >= 128, Max Resp Code represents a floating-point
value as follows:

    0 1 2 3 4 5 6 7
  +-+-+-+-+-+-+-+-+
   |1| exp | mant  |
   +-+-+-+-+-+-+-+-+

Max Resp Time = (mant | 0x10) << (exp + 3)

Small values of Max Resp Time allow IGMPv3 routers to tune the "leave
latency" (the time between the moment the last host leaves a group
and the moment the routing protocol is notified that there are no
more members).  Larger values, especially in the exponential range,
allow tuning of the burstiness of IGMP traffic on a network.

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 InitialTempIID

func InitialTempIID(initialTempIIDHistory []byte, seed []byte, nicID tcpip.NICID)

InitialTempIID generates the initial temporary IID history value to generate temporary SLAAC addresses with.

Panics if initialTempIIDHistory is not at least IIDSize bytes.

func IsMulticastEthernetAddress

func IsMulticastEthernetAddress(addr tcpip.LinkAddress) bool

IsMulticastEthernetAddress returns true if the address is a multicast ethernet address.

func IsSolicitedNodeAddr

func IsSolicitedNodeAddr(addr tcpip.Address) bool

IsSolicitedNodeAddr determines whether the address is a solicited-node multicast address.

func IsV4LinkLocalMulticastAddress

func IsV4LinkLocalMulticastAddress(addr tcpip.Address) bool

IsV4LinkLocalMulticastAddress determines if the provided address is an IPv4 link-local multicast address.

func IsV4LinkLocalUnicastAddress

func IsV4LinkLocalUnicastAddress(addr tcpip.Address) bool

IsV4LinkLocalUnicastAddress determines if the provided address is an IPv4 link-local unicast address.

func IsV4LoopbackAddress

func IsV4LoopbackAddress(addr tcpip.Address) bool

IsV4LoopbackAddress determines if the provided address is an IPv4 loopback address (belongs to 127.0.0.0/8 subnet). See RFC 1122 section 3.2.1.3.

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 IsV6LinkLocalMulticastAddress

func IsV6LinkLocalMulticastAddress(addr tcpip.Address) bool

IsV6LinkLocalMulticastAddress returns true iff the provided address is an IPv6 link-local multicast address, as defined by RFC 4291 section 2.7.

func IsV6LinkLocalUnicastAddress

func IsV6LinkLocalUnicastAddress(addr tcpip.Address) bool

IsV6LinkLocalUnicastAddress returns true iff the provided address is an IPv6 link-local unicast address, as defined by RFC 4291 section 2.5.6.

func IsV6LoopbackAddress

func IsV6LoopbackAddress(addr tcpip.Address) bool

IsV6LoopbackAddress returns true iff the provided address is an IPv6 loopback address, as defined by RFC 4291 section 2.5.3.

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 the address is a 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 LinkLocalAddrWithOpaqueIID

func LinkLocalAddrWithOpaqueIID(nicName string, dadCounter uint8, secretKey []byte) tcpip.Address

LinkLocalAddrWithOpaqueIID computes the default IPv6 link-local address with an opaque IID.

func MLDv2MaximumResponseDelay

func MLDv2MaximumResponseDelay(codeRaw uint16) time.Duration

MLDv2MaximumResponseDelay returns the Maximum Response Delay in an MLDv2 Maximum Response Code.

As per RFC 3810 section 5.1.3,

The Maximum Response Code field specifies the maximum time allowed
before sending a responding Report.  The actual time allowed, called
the Maximum Response Delay, is represented in units of milliseconds,
and is derived from the Maximum Response Code as follows:

If Maximum Response Code < 32768,
   Maximum Response Delay = Maximum Response Code

If Maximum Response Code >=32768, Maximum Response Code represents a
floating-point value as follows:

    0 1 2 3 4 5 6 7 8 9 A B C D E F
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |1| exp |          mant         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Maximum Response Delay = (mant | 0x1000) << (exp+3)

Small values of Maximum Response Delay allow MLDv2 routers to tune
the "leave latency" (the time between the moment the last node on a
link ceases to listen to a specific multicast address and the moment
the routing protocol is notified that there are no more listeners for
that address).  Larger values, especially in the exponential range,
allow the tuning of the burstiness of MLD traffic on a link.

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.

func TCPValid

func TCPValid(hdr TCP, payloadChecksum func() uint16, payloadSize uint16, srcAddr, dstAddr tcpip.Address, skipChecksumValidation bool) (csum uint16, csumValid, ok bool)

TCPValid returns true if the pkt has a valid TCP header. It checks whether:

  • The data offset is too small.
  • The data offset is too large.
  • The checksum is invalid.

TCPValid corresponds to net/netfilter/nf_conntrack_proto_tcp.c:tcp_error.

func UDPValid

func UDPValid(hdr UDP, payloadChecksum func() uint16, payloadSize uint16, netProto tcpip.NetworkProtocolNumber, srcAddr, dstAddr tcpip.Address, skipChecksumValidation bool) (lengthValid, csumValid bool)

UDPValid returns true if the pkt has a valid UDP header. It checks whether:

  • The length field is too small.
  • The length field is too large.
  • The checksum is invalid.

UDPValid corresponds to net/netfilter/nf_conntrack_proto_udp.c:udp_error.

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 ARPHardwareType

type ARPHardwareType uint16

ARPHardwareType is the hardware type for LinkEndpoint in an ARP header.

const (
	ARPHardwareNone ARPHardwareType = 0
	// ARPHardwareEther specifically is the HTYPE for Ethernet as specified
	// in the IANA list here:
	//
	// https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml#arp-parameters-2
	ARPHardwareEther    ARPHardwareType = 1
	ARPHardwareLoopback ARPHardwareType = 2
)

Typical ARP HardwareType values. Some of the constants have to be specific values as they are egressed on the wire in the HTYPE field of an ARP header.

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 AddressIterator

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

AddressIterator is an iterator over IPv6 addresses.

func MakeAddressIterator

func MakeAddressIterator(addressSize int, buf *bytes.Buffer) AddressIterator

MakeAddressIterator returns an AddressIterator.

func (*AddressIterator) Done

func (it *AddressIterator) Done() bool

Done indicates that the iterator has been exhausted/has no more elements.

func (*AddressIterator) Next

func (it *AddressIterator) Next() (tcpip.Address, bool)

Next returns the next address in the iterator.

Returns false if the iterator has been exhausted.

type ChecksummableNetwork

type ChecksummableNetwork interface {
	Network

	// SetSourceAddressAndChecksum sets the source address and updates the
	// checksum to reflect the new address.
	SetSourceAddressWithChecksumUpdate(tcpip.Address)

	// SetDestinationAddressAndChecksum sets the destination address and
	// updates the checksum to reflect the new address.
	SetDestinationAddressWithChecksumUpdate(tcpip.Address)
}

ChecksummableNetwork is a Network that supports checksumming.

type ChecksummableTransport

type ChecksummableTransport interface {
	Transport

	// SetSourcePortWithChecksumUpdate sets the source port and updates
	// the checksum.
	//
	// The receiver's checksum must be a fully calculated checksum.
	SetSourcePortWithChecksumUpdate(port uint16)

	// SetDestinationPortWithChecksumUpdate sets the destination port and updates
	// the checksum.
	//
	// The receiver's checksum must be a fully calculated checksum.
	SetDestinationPortWithChecksumUpdate(port uint16)

	// UpdateChecksumPseudoHeaderAddress updates the checksum to reflect an
	// updated address in the pseudo header.
	//
	// If fullChecksum is true, the receiver's checksum field is assumed to hold a
	// fully calculated checksum. Otherwise, it is assumed to hold a partially
	// calculated checksum which only reflects the pseudo header.
	UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullChecksum bool)
}

ChecksummableTransport is a Transport that supports checksumming.

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() ICMPv4Code

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) Pointer

func (b ICMPv4) Pointer() byte

Pointer returns the pointer field in a Parameter Problem packet.

func (ICMPv4) Sequence

func (b ICMPv4) Sequence() uint16

Sequence retrieves the Sequence field from an ICMPv4 message.

func (ICMPv4) SetChecksum

func (b ICMPv4) SetChecksum(cs uint16)

SetChecksum sets the ICMP checksum field.

func (ICMPv4) SetCode

func (b ICMPv4) SetCode(c ICMPv4Code)

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) SetIdentWithChecksumUpdate

func (b ICMPv4) SetIdentWithChecksumUpdate(new uint16)

SetIdentWithChecksumUpdate sets the Ident field and updates the checksum.

func (ICMPv4) SetMTU

func (b ICMPv4) SetMTU(mtu uint16)

SetMTU sets the MTU field from an ICMPv4 message.

func (ICMPv4) SetPointer

func (b ICMPv4) SetPointer(c byte)

SetPointer sets the pointer field in a Parameter Problem packet.

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 ICMPv4Code

type ICMPv4Code byte

ICMPv4Code is the ICMP code field described in RFC 792.

const (
	ICMPv4TTLExceeded       ICMPv4Code = 0
	ICMPv4ReassemblyTimeout ICMPv4Code = 1
)

ICMP codes for ICMPv4 Time Exceeded messages as defined in RFC 792.

const (
	ICMPv4NetUnreachable            ICMPv4Code = 0
	ICMPv4HostUnreachable           ICMPv4Code = 1
	ICMPv4ProtoUnreachable          ICMPv4Code = 2
	ICMPv4PortUnreachable           ICMPv4Code = 3
	ICMPv4FragmentationNeeded       ICMPv4Code = 4
	ICMPv4SourceRouteFailed         ICMPv4Code = 5
	ICMPv4DestinationNetworkUnknown ICMPv4Code = 6
	ICMPv4DestinationHostUnknown    ICMPv4Code = 7
	ICMPv4SourceHostIsolated        ICMPv4Code = 8
	ICMPv4NetProhibited             ICMPv4Code = 9
	ICMPv4HostProhibited            ICMPv4Code = 10
	ICMPv4NetUnreachableForTos      ICMPv4Code = 11
	ICMPv4HostUnreachableForTos     ICMPv4Code = 12
	ICMPv4AdminProhibited           ICMPv4Code = 13
	ICMPv4HostPrecedenceViolation   ICMPv4Code = 14
	ICMPv4PrecedenceCutInEffect     ICMPv4Code = 15
)

ICMP codes for ICMPv4 Destination Unreachable messages as defined in RFC 792, RFC 1122 section 3.2.2.1 and RFC 1812 section 5.2.7.1.

const ICMPv4UnusedCode ICMPv4Code = 0

ICMPv4UnusedCode is a code to use in ICMP messages where no code is needed.

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() ICMPv6Code

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) MessageBody

func (b ICMPv6) MessageBody() []byte

MessageBody returns the 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(cs uint16)

SetChecksum sets the ICMP checksum field.

func (ICMPv6) SetCode

func (b ICMPv6) SetCode(c ICMPv6Code)

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) SetIdentWithChecksumUpdate

func (b ICMPv6) SetIdentWithChecksumUpdate(new uint16)

SetIdentWithChecksumUpdate sets the Ident field and updates the checksum.

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) SetTypeSpecific

func (b ICMPv6) SetTypeSpecific(val uint32)

SetTypeSpecific sets the type specific data 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.

func (ICMPv6) TypeSpecific

func (b ICMPv6) TypeSpecific() uint32

TypeSpecific returns the type specific data field.

func (ICMPv6) UpdateChecksumPseudoHeaderAddress

func (b ICMPv6) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address)

UpdateChecksumPseudoHeaderAddress updates the checksum to reflect an updated address in the pseudo header.

type ICMPv6ChecksumParams

type ICMPv6ChecksumParams struct {
	Header      ICMPv6
	Src         tcpip.Address
	Dst         tcpip.Address
	PayloadCsum uint16
	PayloadLen  int
}

ICMPv6ChecksumParams contains parameters to calculate ICMPv6 checksum.

type ICMPv6Code

type ICMPv6Code byte

ICMPv6Code is the ICMP Code field described in RFC 4443.

const (
	ICMPv6NetworkUnreachable ICMPv6Code = 0
	ICMPv6Prohibited         ICMPv6Code = 1
	ICMPv6BeyondScope        ICMPv6Code = 2
	ICMPv6AddressUnreachable ICMPv6Code = 3
	ICMPv6PortUnreachable    ICMPv6Code = 4
	ICMPv6Policy             ICMPv6Code = 5
	ICMPv6RejectRoute        ICMPv6Code = 6
)

ICMP codes used with Destination Unreachable (Type 1). As per RFC 4443 section 3.1.

const (
	ICMPv6HopLimitExceeded  ICMPv6Code = 0
	ICMPv6ReassemblyTimeout ICMPv6Code = 1
)

ICMP codes used with Time Exceeded (Type 3). As per RFC 4443 section 3.3.

const (
	// ICMPv6ErroneousHeader indicates an erroneous header field was encountered.
	ICMPv6ErroneousHeader ICMPv6Code = 0

	// ICMPv6UnknownHeader indicates an unrecognized Next Header type encountered.
	ICMPv6UnknownHeader ICMPv6Code = 1

	// ICMPv6UnknownOption indicates an unrecognized IPv6 option was encountered.
	ICMPv6UnknownOption ICMPv6Code = 2
)

ICMP codes used with Parameter Problem (Type 4). As per RFC 4443 section 3.4.

const ICMPv6UnusedCode ICMPv6Code = 0

ICMPv6UnusedCode is the code value used with ICMPv6 messages which don't use the code field. (Types not mentioned above.)

type ICMPv6Type

type ICMPv6Type byte

ICMPv6Type is the ICMP type field described in RFC 4443.

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

	ICMPv6MulticastListenerQuery  ICMPv6Type = 130
	ICMPv6MulticastListenerReport ICMPv6Type = 131
	ICMPv6MulticastListenerDone   ICMPv6Type = 132

	ICMPv6MulticastListenerV2Report ICMPv6Type = 143
)

Values for use in the Type field of ICMPv6 packet from RFC 4433.

func (ICMPv6Type) IsErrorType

func (typ ICMPv6Type) IsErrorType() bool

IsErrorType returns true if the receiver is an ICMP error type.

type IGMP

type IGMP []byte

IGMP represents an IGMP header stored in a byte array.

func (IGMP) Checksum

func (b IGMP) Checksum() uint16

Checksum is the IGMP checksum field.

func (IGMP) DestinationPort

func (IGMP) DestinationPort() uint16

DestinationPort implements Transport.DestinationPort.

func (IGMP) GroupAddress

func (b IGMP) GroupAddress() tcpip.Address

GroupAddress gets the Group Address field.

func (IGMP) MaxRespTime

func (b IGMP) MaxRespTime() time.Duration

MaxRespTime gets the MaxRespTimeField. This is meaningful only in Membership Query messages, in other cases it is set to 0 by the sender and ignored by the receiver.

func (IGMP) Payload

func (IGMP) Payload() []byte

Payload implements Transport.Payload.

func (IGMP) SetChecksum

func (b IGMP) SetChecksum(checksum uint16)

SetChecksum sets the IGMP checksum field.

func (IGMP) SetDestinationPort

func (IGMP) SetDestinationPort(uint16)

SetDestinationPort implements Transport.SetDestinationPort.

func (IGMP) SetGroupAddress

func (b IGMP) SetGroupAddress(address tcpip.Address)

SetGroupAddress sets the Group Address field.

func (IGMP) SetMaxRespTime

func (b IGMP) SetMaxRespTime(m byte)

SetMaxRespTime sets the MaxRespTimeField.

func (IGMP) SetSourcePort

func (IGMP) SetSourcePort(uint16)

SetSourcePort implements Transport.SetSourcePort.

func (IGMP) SetType

func (b IGMP) SetType(t IGMPType)

SetType sets the IGMP type field.

func (IGMP) SourcePort

func (IGMP) SourcePort() uint16

SourcePort implements Transport.SourcePort.

func (IGMP) Type

func (b IGMP) Type() IGMPType

Type is the IGMP type field.

type IGMPType

type IGMPType byte

IGMPType is the IGMP type field as per RFC 2236.

const (
	// IGMPMembershipQuery indicates that the message type is Membership Query.
	// "There are two sub-types of Membership Query messages:
	//	- General Query, used to learn which groups have members on an
	//		attached network.
	//	- Group-Specific Query, used to learn if a particular group
	//		has any members on an attached network.
	// These two messages are differentiated by the Group Address, as
	// described in section 1.4 ."
	IGMPMembershipQuery IGMPType = 0x11
	// IGMPv1MembershipReport indicates that the message is a Membership Report
	// generated by a host using the IGMPv1 protocol: "an additional type of
	// message, for backwards-compatibility with IGMPv1"
	IGMPv1MembershipReport IGMPType = 0x12
	// IGMPv2MembershipReport indicates that the Message type is a Membership
	// Report generated by a host using the IGMPv2 protocol.
	IGMPv2MembershipReport IGMPType = 0x16
	// IGMPLeaveGroup indicates that the message type is a Leave Group
	// notification message.
	IGMPLeaveGroup IGMPType = 0x17
	// IGMPv3MembershipReport indicates that the message type is a IGMPv3 report.
	IGMPv3MembershipReport IGMPType = 0x22
)

Values for the IGMP Type described in RFC 2236 Section 2.1, Page 2. Descriptions below come from there.

type IGMPv3Query

type IGMPv3Query IGMP

IGMPv3Query is an IGMPv3 query message.

As per RFC 3376 section 4.1,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 0x11  | Max Resp Code |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Group Address                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Resv  |S| QRV |     QQIC      |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address [1]                      |
+-                                                             -+
|                       Source Address [2]                      |
+-                              .                              -+
.                               .                               .
.                               .                               .
+-                                                             -+
|                       Source Address [N]                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (IGMPv3Query) GroupAddress

func (i IGMPv3Query) GroupAddress() tcpip.Address

GroupAddress returns the group address.

func (IGMPv3Query) MaximumResponseCode

func (i IGMPv3Query) MaximumResponseCode() uint8

MaximumResponseCode returns the Maximum Response Code.

func (IGMPv3Query) QuerierQueryInterval

func (i IGMPv3Query) QuerierQueryInterval() time.Duration

QuerierQueryInterval returns the querier's query interval.

func (IGMPv3Query) QuerierRobustnessVariable

func (i IGMPv3Query) QuerierRobustnessVariable() uint8

QuerierRobustnessVariable returns the querier's robustness variable.

func (IGMPv3Query) Sources

func (i IGMPv3Query) Sources() (AddressIterator, bool)

Sources returns an iterator over source addresses in the query.

Returns false if the message cannot hold the expected number of sources.

type IGMPv3Report

type IGMPv3Report []byte

IGMPv3Report is an IGMPv3 Report.

As per RFC 3810 section 5.2,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 143   |    Reserved   |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Reserved            |Nr of Mcast Address Records (M)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [1]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [2]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               .                               |
.                               .                               .
|                               .                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [M]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (IGMPv3Report) Checksum

func (i IGMPv3Report) Checksum() uint16

Checksum returns the checksum.

func (IGMPv3Report) GroupAddressRecords

func (i IGMPv3Report) GroupAddressRecords() IGMPv3ReportGroupAddressRecordIterator

GroupAddressRecords returns an iterator of IGMPv3 Multicast Address Records.

type IGMPv3ReportGroupAddressRecord

type IGMPv3ReportGroupAddressRecord []byte

IGMPv3ReportGroupAddressRecord is an IGMPv3 record.

As per RFC 3810 section 5.2, a Multicast Address Record has the following internal format:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Record Type  |  Aux Data Len |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Multicast Address                       *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [1]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [2]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
.                               .                               .
.                               .                               .
.                               .                               .
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [N]                      *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                         Auxiliary Data                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (IGMPv3ReportGroupAddressRecord) AuxDataLen

func (r IGMPv3ReportGroupAddressRecord) AuxDataLen() int

AuxDataLen returns the length of the auxiliary data in this record.

func (IGMPv3ReportGroupAddressRecord) GroupAddress

func (r IGMPv3ReportGroupAddressRecord) GroupAddress() tcpip.Address

GroupAddress returns the multicast address this record targets.

func (IGMPv3ReportGroupAddressRecord) RecordType

RecordType returns the type of this record.

func (IGMPv3ReportGroupAddressRecord) Sources

Sources returns an iterator over source addresses in the query.

Returns false if the message cannot hold the expected number of sources.

type IGMPv3ReportGroupAddressRecordIterator

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

IGMPv3ReportGroupAddressRecordIterator is an iterator over IGMPv3 Multicast Address Records.

func (*IGMPv3ReportGroupAddressRecordIterator) Next

Next returns the next IGMPv3 Multicast Address Record.

type IGMPv3ReportGroupAddressRecordIteratorNextDisposition

type IGMPv3ReportGroupAddressRecordIteratorNextDisposition int

IGMPv3ReportGroupAddressRecordIteratorNextDisposition is the possible return values from IGMPv3ReportGroupAddressRecordIterator.Next.

const (
	// IGMPv3ReportGroupAddressRecordIteratorNextOk indicates that a multicast
	// address record was yielded.
	IGMPv3ReportGroupAddressRecordIteratorNextOk IGMPv3ReportGroupAddressRecordIteratorNextDisposition = iota

	// IGMPv3ReportGroupAddressRecordIteratorNextDone indicates that the iterator
	// has been exhausted.
	IGMPv3ReportGroupAddressRecordIteratorNextDone

	// IGMPv3ReportGroupAddressRecordIteratorNextErrBufferTooShort indicates
	// that the iterator expected another record, but the buffer ended
	// prematurely.
	IGMPv3ReportGroupAddressRecordIteratorNextErrBufferTooShort
)

type IGMPv3ReportGroupAddressRecordSerializer

type IGMPv3ReportGroupAddressRecordSerializer struct {
	RecordType   IGMPv3ReportRecordType
	GroupAddress tcpip.Address
	Sources      []tcpip.Address
}

IGMPv3ReportGroupAddressRecordSerializer is an IGMPv3 Multicast Address Record serializer.

As per RFC 3810 section 5.2, a Multicast Address Record has the following internal format:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Record Type  |  Aux Data Len |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Multicast Address                       *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [1]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [2]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
.                               .                               .
.                               .                               .
.                               .                               .
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [N]                      *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                         Auxiliary Data                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (*IGMPv3ReportGroupAddressRecordSerializer) Length

Length returns the number of bytes this serializer would occupy.

func (*IGMPv3ReportGroupAddressRecordSerializer) SerializeInto

func (s *IGMPv3ReportGroupAddressRecordSerializer) SerializeInto(b []byte)

SerializeInto serializes the record into the buffer.

Panics if the buffer does not have enough space to fit the record.

type IGMPv3ReportRecordType

type IGMPv3ReportRecordType int

IGMPv3ReportRecordType is the type of an IGMPv3 multicast address record found in an IGMPv3 report, as per RFC 3810 section 5.2.12.

const (
	IGMPv3ReportRecordModeIsInclude       IGMPv3ReportRecordType = 1
	IGMPv3ReportRecordModeIsExclude       IGMPv3ReportRecordType = 2
	IGMPv3ReportRecordChangeToIncludeMode IGMPv3ReportRecordType = 3
	IGMPv3ReportRecordChangeToExcludeMode IGMPv3ReportRecordType = 4
	IGMPv3ReportRecordAllowNewSources     IGMPv3ReportRecordType = 5
	IGMPv3ReportRecordBlockOldSources     IGMPv3ReportRecordType = 6
)

IGMPv3 multicast address record types, as per RFC 3810 section 5.2.12.

type IGMPv3ReportSerializer

type IGMPv3ReportSerializer struct {
	Records []IGMPv3ReportGroupAddressRecordSerializer
}

IGMPv3ReportSerializer is an MLD Version 2 Report serializer.

As per RFC 3810 section 5.2,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 143   |    Reserved   |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Reserved            |Nr of Mcast Address Records (M)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [1]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [2]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               .                               |
.                               .                               .
|                               .                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [M]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (*IGMPv3ReportSerializer) Length

func (s *IGMPv3ReportSerializer) Length() int

Length returns the number of bytes this serializer would occupy.

func (*IGMPv3ReportSerializer) SerializeInto

func (s *IGMPv3ReportSerializer) SerializeInto(b []byte)

SerializeInto serializes the report into the buffer.

Panics if the buffer does not have enough space to fit the report.

type IPv4

type IPv4 []byte

IPv4 is an IPv4 header. 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) DestinationAddressSlice

func (b IPv4) DestinationAddressSlice() []byte

DestinationAddressSlice returns the "destination address" field of the IPv4 header as a byte slice.

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. The length returned is in bytes.

func (IPv4) ID

func (b IPv4) ID() uint16

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

func (IPv4) IsChecksumValid

func (b IPv4) IsChecksumValid() bool

IsChecksumValid returns true iff the IPv4 header's checksum is valid.

func (IPv4) IsValid

func (b IPv4) IsValid(pktSize int) bool

IsValid performs basic validation on the packet.

func (IPv4) More

func (b IPv4) More() bool

More returns whether the more fragments flag is set.

func (IPv4) Options

func (b IPv4) Options() IPv4Options

Options returns a buffer holding the options.

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) SetDestinationAddressWithChecksumUpdate

func (b IPv4) SetDestinationAddressWithChecksumUpdate(new tcpip.Address)

SetDestinationAddressWithChecksumUpdate implements ChecksummableNetwork.

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) SetHeaderLength

func (b IPv4) SetHeaderLength(hdrLen uint8)

SetHeaderLength sets the value of the "Internet Header Length" field.

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) SetSourceAddressWithChecksumUpdate

func (b IPv4) SetSourceAddressWithChecksumUpdate(new tcpip.Address)

SetSourceAddressWithChecksumUpdate implements ChecksummableNetwork.

func (IPv4) SetTOS

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

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

func (IPv4) SetTTL

func (b IPv4) SetTTL(v byte)

SetTTL sets the "Time to Live" 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) SourceAddressSlice

func (b IPv4) SourceAddressSlice() []byte

SourceAddressSlice returns the "source address" field of the IPv4 header as a byte slice.

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 {
	// 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

	// Options must be 40 bytes or less as they must fit along with the
	// rest of the IPv4 header into the maximum size describable in the
	// IHL field. RFC 791 section 3.1 says:
	//    IHL:  4 bits
	//
	//    Internet Header Length is the length of the internet header in 32
	//    bit words, and thus points to the beginning of the data.  Note that
	//    the minimum value for a correct header is 5.
	//
	// That leaves ten 32 bit (4 byte) fields for options. An attempt to encode
	// more will fail.
	Options IPv4OptionsSerializer
}

IPv4Fields contains the fields of an IPv4 packet. It is used to describe the fields of a packet that needs to be encoded. The IHL field is not here as it is totally defined by the size of the options.

type IPv4OptParameterProblem

type IPv4OptParameterProblem struct {
	Pointer  uint8
	NeedICMP bool
}

IPv4OptParameterProblem indicates that a Parameter Problem message should be generated, and gives the offset in the current entity that should be used in that packet.

type IPv4OptTSFlags

type IPv4OptTSFlags uint8

IPv4OptTSFlags sefines the values expected in the Timestamp option Flags field.

type IPv4Option

type IPv4Option interface {
	// Type returns the type identifier of the option.
	Type() IPv4OptionType

	// Size returns the size of the option in bytes.
	Size() uint8

	// Contents returns a slice holding the contents of the option.
	Contents() []byte
}

IPv4Option is an interface representing various option types.

type IPv4OptionExperiment

type IPv4OptionExperiment []byte

IPv4OptionExperiment is an IPv4 option defined by RFC 4727.

func (*IPv4OptionExperiment) Contents

func (ex *IPv4OptionExperiment) Contents() []byte

Contents implements IPv4Option.

func (*IPv4OptionExperiment) Size

func (*IPv4OptionExperiment) Size() uint8

Size implements IPv4Option.

func (*IPv4OptionExperiment) Type

Type implements IPv4Option.

func (*IPv4OptionExperiment) Value

func (ex *IPv4OptionExperiment) Value() uint16

Value returns the value of the IPv4OptionRouterAlert.

type IPv4OptionGeneric

type IPv4OptionGeneric []byte

IPv4OptionGeneric is an IPv4 Option of unknown type.

func (*IPv4OptionGeneric) Contents

func (o *IPv4OptionGeneric) Contents() []byte

Contents implements IPv4Option.

func (*IPv4OptionGeneric) Size

func (o *IPv4OptionGeneric) Size() uint8

Size implements IPv4Option.

func (*IPv4OptionGeneric) Type

Type implements IPv4Option.

type IPv4OptionIterator

type IPv4OptionIterator struct {

	// ErrCursor is where we are while parsing options. It is exported as any
	// resulting ICMP packet is supposed to have a pointer to the byte within
	// the IP packet where the error was detected.
	ErrCursor uint8
	// contains filtered or unexported fields
}

IPv4OptionIterator is an iterator pointing to a specific IP option at any point of time. It also holds information as to a new options buffer that we are building up to hand back to the caller. TODO(https://gvisor.dev/issues/5513): Add unit tests for IPv4OptionIterator.

func (*IPv4OptionIterator) ConsumeBuffer

func (i *IPv4OptionIterator) ConsumeBuffer(size int)

ConsumeBuffer marks a portion of the new buffer as used.

func (*IPv4OptionIterator) Finalize

func (i *IPv4OptionIterator) Finalize() IPv4Options

Finalize returns the completed replacement options buffer padded as needed.

func (*IPv4OptionIterator) InitReplacement

func (i *IPv4OptionIterator) InitReplacement(option IPv4Option) IPv4Options

InitReplacement copies the option into the new option buffer.

func (*IPv4OptionIterator) Next

Next returns the next IP option in the buffer/list of IP options. It returns

  • A slice of bytes holding the next option or nil if there is error.
  • A boolean which is true if parsing of all the options is complete. Undefined in the case of error.
  • An error indication which is non-nil if an error condition was found.

func (*IPv4OptionIterator) PushNOPOrEnd

func (i *IPv4OptionIterator) PushNOPOrEnd(val IPv4OptionType)

PushNOPOrEnd puts one of the single byte options onto the new options. Only values 0 or 1 (ListEnd or NOP) are valid input.

func (*IPv4OptionIterator) RemainingBuffer

func (i *IPv4OptionIterator) RemainingBuffer() IPv4Options

RemainingBuffer returns the remaining (unused) part of the new option buffer, into which a new option may be written.

type IPv4OptionRecordRoute

type IPv4OptionRecordRoute []byte

IPv4OptionRecordRoute is an IPv4 RecordRoute option defined by RFC 791.

func (*IPv4OptionRecordRoute) Contents

func (rr *IPv4OptionRecordRoute) Contents() []byte

Contents implements IPv4Option.

func (*IPv4OptionRecordRoute) Pointer

func (rr *IPv4OptionRecordRoute) Pointer() uint8

Pointer returns the pointer field in the IP RecordRoute option.

func (*IPv4OptionRecordRoute) Size

func (rr *IPv4OptionRecordRoute) Size() uint8

Size implements IPv4Option.

func (*IPv4OptionRecordRoute) StoreAddress

func (rr *IPv4OptionRecordRoute) StoreAddress(addr tcpip.Address)

StoreAddress stores the given IPv4 address into the next free slot.

func (*IPv4OptionRecordRoute) Type

Type implements IPv4Option.

type IPv4OptionRouterAlert

type IPv4OptionRouterAlert []byte

IPv4OptionRouterAlert is an IPv4 RouterAlert option defined by RFC 2113.

func (*IPv4OptionRouterAlert) Contents

func (ra *IPv4OptionRouterAlert) Contents() []byte

Contents implements IPv4Option.

func (*IPv4OptionRouterAlert) Size

func (ra *IPv4OptionRouterAlert) Size() uint8

Size implements IPv4Option.

func (*IPv4OptionRouterAlert) Type

Type implements IPv4Option.

func (*IPv4OptionRouterAlert) Value

func (ra *IPv4OptionRouterAlert) Value() uint16

Value returns the value of the IPv4OptionRouterAlert.

type IPv4OptionTimestamp

type IPv4OptionTimestamp []byte

IPv4OptionTimestamp is a Timestamp option from RFC 791.

func (*IPv4OptionTimestamp) Contents

func (ts *IPv4OptionTimestamp) Contents() []byte

Contents implements IPv4Option.

func (*IPv4OptionTimestamp) Flags

func (ts *IPv4OptionTimestamp) Flags() IPv4OptTSFlags

Flags returns the flags field in the IP Timestamp option.

func (*IPv4OptionTimestamp) IncOverflow

func (ts *IPv4OptionTimestamp) IncOverflow() uint8

IncOverflow increments the Overflow field in the IP Timestamp option. It returns the incremented value. If the return value is 0 then the field overflowed.

func (*IPv4OptionTimestamp) Overflow

func (ts *IPv4OptionTimestamp) Overflow() uint8

Overflow returns the Overflow field in the IP Timestamp option.

func (*IPv4OptionTimestamp) Pointer

func (ts *IPv4OptionTimestamp) Pointer() uint8

Pointer returns the pointer field in the IP Timestamp option.

func (*IPv4OptionTimestamp) Size

func (ts *IPv4OptionTimestamp) Size() uint8

Size implements IPv4Option.

func (*IPv4OptionTimestamp) Type

Type implements IPv4Option.Type().

func (*IPv4OptionTimestamp) UpdateTimestamp

func (ts *IPv4OptionTimestamp) UpdateTimestamp(addr tcpip.Address, clock tcpip.Clock)

UpdateTimestamp updates the fields of the next free timestamp slot.

type IPv4OptionType

type IPv4OptionType byte

An IPv4OptionType can hold the value for the Type in an IPv4 option.

const (
	// IPv4OptionListEndType is the option type for the End Of Option List
	// option. Anything following is ignored.
	IPv4OptionListEndType IPv4OptionType = 0

	// IPv4OptionNOPType is the No-Operation option. May appear between other
	// options and may appear multiple times.
	IPv4OptionNOPType IPv4OptionType = 1

	// IPv4OptionRouterAlertType is the option type for the Router Alert option,
	// defined in RFC 2113 Section 2.1.
	IPv4OptionRouterAlertType IPv4OptionType = 20 | 0x80

	// IPv4OptionRecordRouteType is used by each router on the path of the packet
	// to record its path. It is carried over to an Echo Reply.
	IPv4OptionRecordRouteType IPv4OptionType = 7

	// IPv4OptionTimestampType is the option type for the Timestamp option.
	IPv4OptionTimestampType IPv4OptionType = 68

	// IPv4OptionExperimentType is the option type for the Experiment option.
	IPv4OptionExperimentType IPv4OptionType = 30

	// IPv4OptionLengthOffset is the offset in an option of its length field.
	IPv4OptionLengthOffset = 1
)

type IPv4Options

type IPv4Options []byte

IPv4Options is a buffer that holds all the raw IP options.

func (IPv4Options) MakeIterator

func (o IPv4Options) MakeIterator() IPv4OptionIterator

MakeIterator sets up and returns an iterator of options. It also sets up the building of a new option set.

type IPv4OptionsSerializer

type IPv4OptionsSerializer []IPv4SerializableOption

IPv4OptionsSerializer is a serializer for IPv4 options.

func (IPv4OptionsSerializer) Length

func (s IPv4OptionsSerializer) Length() uint8

Length returns the total number of bytes required to serialize the options.

func (IPv4OptionsSerializer) Serialize

func (s IPv4OptionsSerializer) Serialize(b []byte) uint8

Serialize serializes the provided list of IPV4 options into b.

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

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

type IPv4SerializableExperimentOption

type IPv4SerializableExperimentOption struct {
	Tag uint16
}

IPv4SerializableExperimentOption provides serialization for the IPv4 Experiment option.

type IPv4SerializableListEndOption

type IPv4SerializableListEndOption struct{}

IPv4SerializableListEndOption provides serialization for the IPv4 List End option.

type IPv4SerializableNOPOption

type IPv4SerializableNOPOption struct{}

IPv4SerializableNOPOption provides serialization for the IPv4 no-op option.

type IPv4SerializableOption

type IPv4SerializableOption interface {
	// contains filtered or unexported methods
}

IPv4SerializableOption is an interface to represent serializable IPv4 option types.

type IPv4SerializableOptionPayload

type IPv4SerializableOptionPayload interface {
	// contains filtered or unexported methods
}

IPv4SerializableOptionPayload is an interface providing serialization of the payload of an IPv4 option.

type IPv4SerializableRouterAlertOption

type IPv4SerializableRouterAlertOption struct{}

IPv4SerializableRouterAlertOption provides serialization of the Router Alert IPv4 option according to RFC 2113.

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) DestinationAddressSlice

func (b IPv6) DestinationAddressSlice() []byte

DestinationAddressSlice returns the "destination address" field of the ipv6 header as a byte slice.

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) SetHopLimit

func (b IPv6) SetHopLimit(v uint8)

SetHopLimit sets the value of the "Hop Limit" field.

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) SourceAddressSlice

func (b IPv6) SourceAddressSlice() []byte

SourceAddressSlice returns the "source address" field of the ipv6 header as a byte slice.

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 IPv6AddressScope

type IPv6AddressScope int

IPv6AddressScope is the scope of an IPv6 address.

const (
	// LinkLocalScope indicates a link-local address.
	LinkLocalScope IPv6AddressScope = iota

	// GlobalScope indicates a global address.
	GlobalScope
)

func ScopeForIPv6Address

func ScopeForIPv6Address(addr tcpip.Address) (IPv6AddressScope, tcpip.Error)

ScopeForIPv6Address returns the scope for an IPv6 address.

type IPv6DestinationOptionsExtHdr

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

IPv6DestinationOptionsExtHdr is a buffer holding the Destination Options extension header.

func (IPv6DestinationOptionsExtHdr) Iter

func (i IPv6DestinationOptionsExtHdr) Iter() IPv6OptionsExtHdrOptionsIterator

Iter returns an iterator over the IPv6 extension header options held in b.

func (IPv6DestinationOptionsExtHdr) Release

func (i IPv6DestinationOptionsExtHdr) Release()

Release implements IPv6PayloadHeader.Release.

type IPv6ExperimentExtHdr

type IPv6ExperimentExtHdr struct {
	Value uint16
}

IPv6ExperimentExtHdr is a buffer holding the Experiment extension header.

func (IPv6ExperimentExtHdr) Release

func (IPv6ExperimentExtHdr) Release()

Release implements IPv6PayloadHeader.Release.

type IPv6ExtHdrOption

type IPv6ExtHdrOption interface {
	// UnknownAction returns the action to take in response to an unrecognized
	// option.
	UnknownAction() IPv6OptionUnknownAction
	// contains filtered or unexported methods
}

IPv6ExtHdrOption is implemented by the various IPv6 extension header options.

type IPv6ExtHdrOptionIdentifier

type IPv6ExtHdrOptionIdentifier uint8

IPv6ExtHdrOptionIdentifier is an IPv6 extension header option identifier.

type IPv6ExtHdrSerializer

type IPv6ExtHdrSerializer []IPv6SerializableExtHdr

IPv6ExtHdrSerializer provides serialization of IPv6 extension headers.

func (IPv6ExtHdrSerializer) Length

func (s IPv6ExtHdrSerializer) Length() int

Length returns the total number of bytes required to serialize the extension headers.

func (IPv6ExtHdrSerializer) Serialize

func (s IPv6ExtHdrSerializer) Serialize(transportProtocol tcpip.TransportProtocolNumber, b []byte) (uint8, int)

Serialize serializes the provided list of IPv6 extension headers into b.

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

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

Serialize takes the transportProtocol value to be used as the last extension header's Next Header value and returns the header identifier of the first serialized extension header and the total serialized length.

type IPv6ExtensionHeaderIdentifier

type IPv6ExtensionHeaderIdentifier uint8

IPv6ExtensionHeaderIdentifier is an IPv6 extension header identifier.

const (
	// IPv6HopByHopOptionsExtHdrIdentifier is the header identifier of a Hop by
	// Hop Options extension header, as per RFC 8200 section 4.3.
	IPv6HopByHopOptionsExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 0

	// IPv6RoutingExtHdrIdentifier is the header identifier of a Routing extension
	// header, as per RFC 8200 section 4.4.
	IPv6RoutingExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 43

	// IPv6FragmentExtHdrIdentifier is the header identifier of a Fragment
	// extension header, as per RFC 8200 section 4.5.
	IPv6FragmentExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 44

	// IPv6DestinationOptionsExtHdrIdentifier is the header identifier of a
	// Destination Options extension header, as per RFC 8200 section 4.6.
	IPv6DestinationOptionsExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 60

	// IPv6NoNextHeaderIdentifier is the header identifier used to signify the end
	// of an IPv6 payload, as per RFC 8200 section 4.7.
	IPv6NoNextHeaderIdentifier IPv6ExtensionHeaderIdentifier = 59

	// IPv6ExperimentExtHdrIdentifier is the header identifier of an Experiment
	// extension header, as per RFC 4727 section 3.3.
	IPv6ExperimentExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 253

	// IPv6UnknownExtHdrIdentifier is reserved by IANA.
	// https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml#extension-header
	// "254	Use for experimentation and testing	[RFC3692][RFC4727]"
	IPv6UnknownExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 254
)

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, including
	// the length of all extension headers.
	PayloadLength uint16

	// TransportProtocol is the transport layer protocol number. Serialized in the
	// last "next header" field of the IPv6 header + extension headers.
	TransportProtocol tcpip.TransportProtocolNumber

	// 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

	// ExtensionHeaders are the extension headers following the IPv6 header.
	ExtensionHeaders IPv6ExtHdrSerializer
}

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) 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 IPv6FragmentExtHdr

type IPv6FragmentExtHdr [6]byte

IPv6FragmentExtHdr is a buffer holding the Fragment extension header specific data as outlined in RFC 8200 section 4.5.

Note, the buffer does not include the Next Header and Reserved fields.

func (IPv6FragmentExtHdr) FragmentOffset

func (b IPv6FragmentExtHdr) FragmentOffset() uint16

FragmentOffset returns the Fragment Offset field.

This value indicates where the buffer following the Fragment extension header starts in the target (reassembled) packet.

func (IPv6FragmentExtHdr) ID

func (b IPv6FragmentExtHdr) ID() uint32

ID returns the Identification field.

This value is used to uniquely identify the packet, between a source and destination.

func (IPv6FragmentExtHdr) IsAtomic

func (b IPv6FragmentExtHdr) IsAtomic() bool

IsAtomic returns whether the fragment header indicates an atomic fragment. An atomic fragment is a fragment that contains all the data required to reassemble a full packet.

func (IPv6FragmentExtHdr) More

func (b IPv6FragmentExtHdr) More() bool

More returns the More (M) flag.

This indicates whether any fragments are expected to succeed b.

func (IPv6FragmentExtHdr) Release

func (IPv6FragmentExtHdr) Release()

Release implements IPv6PayloadHeader.Release.

type IPv6HopByHopOptionsExtHdr

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

IPv6HopByHopOptionsExtHdr is a buffer holding the Hop By Hop Options extension header.

func (IPv6HopByHopOptionsExtHdr) Iter

func (i IPv6HopByHopOptionsExtHdr) Iter() IPv6OptionsExtHdrOptionsIterator

Iter returns an iterator over the IPv6 extension header options held in b.

func (IPv6HopByHopOptionsExtHdr) Release

func (i IPv6HopByHopOptionsExtHdr) Release()

Release implements IPv6PayloadHeader.Release.

type IPv6MulticastScope

type IPv6MulticastScope uint8

IPv6MulticastScope is the scope of a multicast IPv6 address, as defined by RFC 7346 section 2.

func V6MulticastScope

func V6MulticastScope(addr tcpip.Address) IPv6MulticastScope

V6MulticastScope returns the scope of a multicast address.

type IPv6OptionUnknownAction

type IPv6OptionUnknownAction int

IPv6OptionUnknownAction is the action that must be taken if the processing IPv6 node does not recognize the option, as outlined in RFC 8200 section 4.2.

const (
	// IPv6OptionUnknownActionSkip indicates that the unrecognized option must
	// be skipped and the node should continue processing the header.
	IPv6OptionUnknownActionSkip IPv6OptionUnknownAction = 0

	// IPv6OptionUnknownActionDiscard indicates that the packet must be silently
	// discarded.
	IPv6OptionUnknownActionDiscard IPv6OptionUnknownAction = 1

	// IPv6OptionUnknownActionDiscardSendICMP indicates that the packet must be
	// discarded and the node must send an ICMP Parameter Problem, Code 2, message
	// to the packet's source, regardless of whether or not the packet's
	// Destination was a multicast address.
	IPv6OptionUnknownActionDiscardSendICMP IPv6OptionUnknownAction = 2

	// IPv6OptionUnknownActionDiscardSendICMPNoMulticastDest indicates that the
	// packet must be discarded and the node must send an ICMP Parameter Problem,
	// Code 2, message to the packet's source only if the packet's Destination was
	// not a multicast address.
	IPv6OptionUnknownActionDiscardSendICMPNoMulticastDest IPv6OptionUnknownAction = 3
)

type IPv6OptionsExtHdrOptionsIterator

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

IPv6OptionsExtHdrOptionsIterator is an iterator over IPv6 extension header options.

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

func (*IPv6OptionsExtHdrOptionsIterator) Next

Next returns the next option in the options data.

If the next item is not a known extension header option, IPv6UnknownExtHdrOption will be returned with the option identifier and data.

The return is of the format (option, done, error). done will be true when Next is unable to return anything because the iterator has reached the end of the options data, or an error occurred.

func (*IPv6OptionsExtHdrOptionsIterator) OptionOffset

func (i *IPv6OptionsExtHdrOptionsIterator) OptionOffset() uint32

OptionOffset returns the number of bytes parsed while processing the option field of the current Extension Header.

type IPv6PayloadHeader

type IPv6PayloadHeader interface {

	// Release frees all resources held by the header.
	Release()
	// contains filtered or unexported methods
}

IPv6PayloadHeader is implemented by the various headers that can be found in an IPv6 payload.

These headers include IPv6 extension headers or upper layer data.

type IPv6PayloadIterator

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

IPv6PayloadIterator is an iterator over the contents of an IPv6 payload.

The IPv6 payload may contain IPv6 extension headers before any upper layer data.

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

func MakeIPv6PayloadIterator

func MakeIPv6PayloadIterator(nextHdrIdentifier IPv6ExtensionHeaderIdentifier, payload buffer.Buffer) IPv6PayloadIterator

MakeIPv6PayloadIterator returns an iterator over the IPv6 payload containing extension headers, or a raw payload if the payload cannot be parsed. The iterator takes ownership of the payload.

func (*IPv6PayloadIterator) AsRawHeader

func (i *IPv6PayloadIterator) AsRawHeader(consume bool) IPv6RawPayloadHeader

AsRawHeader returns the remaining payload of i as a raw header and optionally consumes the iterator.

If consume is true, calls to Next after calling AsRawHeader on i will indicate that the iterator is done. The returned header takes ownership of its payload.

func (IPv6PayloadIterator) HeaderOffset

func (i IPv6PayloadIterator) HeaderOffset() uint32

HeaderOffset returns the offset to the start of the extension header most recently processed.

func (*IPv6PayloadIterator) Next

Next returns the next item in the payload.

If the next item is not a known IPv6 extension header, IPv6RawPayloadHeader will be returned with the remaining bytes and next header identifier.

The return is of the format (header, done, error). done will be true when Next is unable to return anything because the iterator has reached the end of the payload, or an error occurred.

func (*IPv6PayloadIterator) NextHeaderIdentifier

func (i *IPv6PayloadIterator) NextHeaderIdentifier() IPv6ExtensionHeaderIdentifier

NextHeaderIdentifier returns the identifier of the header next returned by it.Next().

func (IPv6PayloadIterator) ParseOffset

func (i IPv6PayloadIterator) ParseOffset() uint32

ParseOffset returns the number of bytes successfully parsed.

func (*IPv6PayloadIterator) Release

func (i *IPv6PayloadIterator) Release()

Release frees the resources owned by the iterator.

type IPv6RawPayloadHeader

type IPv6RawPayloadHeader struct {
	Identifier IPv6ExtensionHeaderIdentifier
	Buf        buffer.Buffer
}

IPv6RawPayloadHeader the remainder of an IPv6 payload after an iterator encounters a Next Header field it does not recognize as an IPv6 extension header. The caller is responsible for releasing the underlying buffer after it's no longer needed.

func (IPv6RawPayloadHeader) Release

func (i IPv6RawPayloadHeader) Release()

Release implements IPv6PayloadHeader.Release.

type IPv6RouterAlertOption

type IPv6RouterAlertOption struct {
	Value IPv6RouterAlertValue
}

IPv6RouterAlertOption is the IPv6 Router alert Hop by Hop option defined in RFC 2711 section 2.1.

func (*IPv6RouterAlertOption) UnknownAction

UnknownAction implements IPv6ExtHdrOption.

type IPv6RouterAlertValue

type IPv6RouterAlertValue uint16

IPv6RouterAlertValue is the payload of an IPv6 Router Alert option.

const (
	// IPv6RouterAlertMLD indicates a datagram containing a Multicast Listener
	// Discovery message as defined in RFC 2711 section 2.1.
	IPv6RouterAlertMLD IPv6RouterAlertValue = 0
	// IPv6RouterAlertRSVP indicates a datagram containing an RSVP message as
	// defined in RFC 2711 section 2.1.
	IPv6RouterAlertRSVP IPv6RouterAlertValue = 1
	// IPv6RouterAlertActiveNetworks indicates a datagram containing an Active
	// Networks message as defined in RFC 2711 section 2.1.
	IPv6RouterAlertActiveNetworks IPv6RouterAlertValue = 2
)

type IPv6RoutingExtHdr

type IPv6RoutingExtHdr struct {
	Buf *buffer.View
}

IPv6RoutingExtHdr is a buffer holding the Routing extension header specific data as outlined in RFC 8200 section 4.4.

func (IPv6RoutingExtHdr) Release

func (b IPv6RoutingExtHdr) Release()

Release implements IPv6PayloadHeader.Release.

func (IPv6RoutingExtHdr) SegmentsLeft

func (b IPv6RoutingExtHdr) SegmentsLeft() uint8

SegmentsLeft returns the Segments Left field.

type IPv6SerializableExtHdr

type IPv6SerializableExtHdr interface {
	// contains filtered or unexported methods
}

IPv6SerializableExtHdr provides serialization for IPv6 extension headers.

type IPv6SerializableFragmentExtHdr

type IPv6SerializableFragmentExtHdr struct {
	// 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
}

IPv6SerializableFragmentExtHdr is used to serialize an IPv6 fragment extension header as defined in RFC 8200 section 4.5.

type IPv6SerializableHopByHopExtHdr

type IPv6SerializableHopByHopExtHdr []IPv6SerializableHopByHopOption

IPv6SerializableHopByHopExtHdr implements serialization of the Hop by Hop options extension header.

type IPv6SerializableHopByHopOption

type IPv6SerializableHopByHopOption interface {
	// contains filtered or unexported methods
}

IPv6SerializableHopByHopOption provides serialization for hop by hop options.

type IPv6UnknownExtHdrOption

type IPv6UnknownExtHdrOption struct {
	Identifier IPv6ExtHdrOptionIdentifier
	Data       *buffer.View
}

IPv6UnknownExtHdrOption holds the identifier and data for an IPv6 extension header option that is unknown by the parsing utilities.

func (*IPv6UnknownExtHdrOption) UnknownAction

UnknownAction implements IPv6OptionUnknownAction.UnknownAction.

type MLD

type MLD []byte

MLD is a Multicast Listener Discovery message in an ICMPv6 packet.

MLD will only contain the body of an ICMPv6 packet.

As per RFC 2710 section 3, MLD messages have the following format (MLD only holds the bytes after the first four bytes in the diagram below):

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Maximum Response Delay    |          Reserved             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                       Multicast Address                       +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (MLD) MaximumResponseDelay

func (m MLD) MaximumResponseDelay() time.Duration

MaximumResponseDelay returns the Maximum Response Delay.

func (MLD) MulticastAddress

func (m MLD) MulticastAddress() tcpip.Address

MulticastAddress returns the Multicast Address.

func (MLD) SetMaximumResponseDelay

func (m MLD) SetMaximumResponseDelay(maxRespDelayMS uint16)

SetMaximumResponseDelay sets the Maximum Response Delay field.

maxRespDelayMS is the value in milliseconds.

func (MLD) SetMulticastAddress

func (m MLD) SetMulticastAddress(multicastAddress tcpip.Address)

SetMulticastAddress sets the Multicast Address field.

type MLDv2Query

type MLDv2Query MLD

MLDv2Query is a Multicast Listener Discovery Version 2 Query message in an ICMPv6 packet.

MLDv2Query will only contain the body of an ICMPv6 packet.

As per RFC 3810 section 5.1, MLDv2 Query messages have the following format (MLDv2Query only holds the bytes after the first four bytes in the diagram below):

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 130   |      Code     |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Maximum Response Code      |           Reserved            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Multicast Address                       *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Resv  |S| QRV |     QQIC      |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [1]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [2]                      *
|                                                               |
*                                                               *
|                                                               |
+-                              .                              -+
.                               .                               .
.                               .                               .
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [N]                      *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (MLDv2Query) MaximumResponseCode

func (m MLDv2Query) MaximumResponseCode() uint16

MaximumResponseCode returns the Maximum Response Code

func (MLDv2Query) MulticastAddress

func (m MLDv2Query) MulticastAddress() tcpip.Address

MulticastAddress returns the Multicast Address.

func (MLDv2Query) QuerierQueryInterval

func (m MLDv2Query) QuerierQueryInterval() time.Duration

QuerierQueryInterval returns the querier's query interval.

func (MLDv2Query) QuerierRobustnessVariable

func (m MLDv2Query) QuerierRobustnessVariable() uint8

QuerierRobustnessVariable returns the querier's robustness variable.

func (MLDv2Query) Sources

func (m MLDv2Query) Sources() (AddressIterator, bool)

Sources returns an iterator over source addresses in the query.

Returns false if the message cannot hold the expected number of sources.

type MLDv2Report

type MLDv2Report []byte

MLDv2Report is an MLDv2 Report.

As per RFC 3810 section 5.2,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 143   |    Reserved   |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Reserved            |Nr of Mcast Address Records (M)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [1]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [2]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               .                               |
.                               .                               .
|                               .                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [M]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (MLDv2Report) MulticastAddressRecords

func (m MLDv2Report) MulticastAddressRecords() MLDv2ReportMulticastAddressRecordIterator

MulticastAddressRecords returns an iterator of MLDv2 Multicast Address Records.

type MLDv2ReportMulticastAddressRecord

type MLDv2ReportMulticastAddressRecord []byte

MLDv2ReportMulticastAddressRecord is an MLDv2 record.

As per RFC 3810 section 5.2, a Multicast Address Record has the following internal format:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Record Type  |  Aux Data Len |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Multicast Address                       *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [1]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [2]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
.                               .                               .
.                               .                               .
.                               .                               .
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [N]                      *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                         Auxiliary Data                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (MLDv2ReportMulticastAddressRecord) AuxDataLen

func (r MLDv2ReportMulticastAddressRecord) AuxDataLen() int

AuxDataLen returns the length of the auxiliary data in this record.

func (MLDv2ReportMulticastAddressRecord) MulticastAddress

func (r MLDv2ReportMulticastAddressRecord) MulticastAddress() tcpip.Address

MulticastAddress returns the multicast address this record targets.

func (MLDv2ReportMulticastAddressRecord) RecordType

RecordType returns the type of this record.

func (MLDv2ReportMulticastAddressRecord) Sources

Sources returns an iterator over source addresses in the query.

Returns false if the message cannot hold the expected number of sources.

type MLDv2ReportMulticastAddressRecordIterator

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

MLDv2ReportMulticastAddressRecordIterator is an iterator over MLDv2 Multicast Address Records.

func (*MLDv2ReportMulticastAddressRecordIterator) Next

Next returns the next MLDv2 Multicast Address Record.

type MLDv2ReportMulticastAddressRecordIteratorNextDisposition

type MLDv2ReportMulticastAddressRecordIteratorNextDisposition int

MLDv2ReportMulticastAddressRecordIteratorNextDisposition is the possible return values from MLDv2ReportMulticastAddressRecordIterator.Next.

const (
	// MLDv2ReportMulticastAddressRecordIteratorNextOk indicates that a multicast
	// address record was yielded.
	MLDv2ReportMulticastAddressRecordIteratorNextOk MLDv2ReportMulticastAddressRecordIteratorNextDisposition = iota

	// MLDv2ReportMulticastAddressRecordIteratorNextDone indicates that the iterator
	// has been exhausted.
	MLDv2ReportMulticastAddressRecordIteratorNextDone

	// MLDv2ReportMulticastAddressRecordIteratorNextErrBufferTooShort indicates
	// that the iterator expected another record, but the buffer ended
	// prematurely.
	MLDv2ReportMulticastAddressRecordIteratorNextErrBufferTooShort
)

type MLDv2ReportMulticastAddressRecordSerializer

type MLDv2ReportMulticastAddressRecordSerializer struct {
	RecordType       MLDv2ReportRecordType
	MulticastAddress tcpip.Address
	Sources          []tcpip.Address
}

MLDv2ReportMulticastAddressRecordSerializer is an MLDv2 Multicast Address Record serializer.

As per RFC 3810 section 5.2, a Multicast Address Record has the following internal format:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Record Type  |  Aux Data Len |     Number of Sources (N)     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Multicast Address                       *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [1]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [2]                      *
|                                                               |
*                                                               *
|                                                               |
+-                                                             -+
.                               .                               .
.                               .                               .
.                               .                               .
+-                                                             -+
|                                                               |
*                                                               *
|                                                               |
*                       Source Address [N]                      *
|                                                               |
*                                                               *
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                         Auxiliary Data                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (*MLDv2ReportMulticastAddressRecordSerializer) Length

Length returns the number of bytes this serializer would occupy.

func (*MLDv2ReportMulticastAddressRecordSerializer) SerializeInto

func (s *MLDv2ReportMulticastAddressRecordSerializer) SerializeInto(b []byte)

SerializeInto serializes the record into the buffer.

Panics if the buffer does not have enough space to fit the record.

type MLDv2ReportRecordType

type MLDv2ReportRecordType int

MLDv2ReportRecordType is the type of an MLDv2 multicast address record found in an MLDv2 report, as per RFC 3810 section 5.2.12.

const (
	MLDv2ReportRecordModeIsInclude       MLDv2ReportRecordType = 1
	MLDv2ReportRecordModeIsExclude       MLDv2ReportRecordType = 2
	MLDv2ReportRecordChangeToIncludeMode MLDv2ReportRecordType = 3
	MLDv2ReportRecordChangeToExcludeMode MLDv2ReportRecordType = 4
	MLDv2ReportRecordAllowNewSources     MLDv2ReportRecordType = 5
	MLDv2ReportRecordBlockOldSources     MLDv2ReportRecordType = 6
)

MLDv2 multicast address record types, as per RFC 3810 section 5.2.12.

type MLDv2ReportSerializer

type MLDv2ReportSerializer struct {
	Records []MLDv2ReportMulticastAddressRecordSerializer
}

MLDv2ReportSerializer is an MLD Version 2 Report serializer.

As per RFC 3810 section 5.2,

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Type = 143   |    Reserved   |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Reserved            |Nr of Mcast Address Records (M)|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [1]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [2]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               .                               |
.                               .                               .
|                               .                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                  Multicast Address Record [M]                 .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (*MLDv2ReportSerializer) Length

func (s *MLDv2ReportSerializer) Length() int

Length returns the number of bytes this serializer would occupy.

func (*MLDv2ReportSerializer) SerializeInto

func (s *MLDv2ReportSerializer) SerializeInto(b []byte)

SerializeInto serializes the report into the buffer.

Panics if the buffer does not have enough space to fit the report.

type NDPDNSSearchList

type NDPDNSSearchList []byte

NDPDNSSearchList is the NDP DNS Search List option, as defined by RFC 8106 section 5.2.

func (NDPDNSSearchList) DomainNames

func (o NDPDNSSearchList) DomainNames() ([]string, error)

DomainNames returns a DNS search list of domain names.

DomainNames will parse the backing buffer as outlined by RFC 1035 section 3.1 and return a list of strings, with all domain names in lower case.

func (NDPDNSSearchList) Lifetime

func (o NDPDNSSearchList) Lifetime() time.Duration

Lifetime returns the length of time that the DNS search list of domain names in this option may be used for name resolution.

Note, a value of 0 implies the domain names should no longer be used, and a value of infinity/forever is represented by NDPInfiniteLifetime.

func (NDPDNSSearchList) String

func (o NDPDNSSearchList) String() string

String implements fmt.Stringer.

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 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 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 NDPNonceOption

type NDPNonceOption []byte

NDPNonceOption is the NDP Nonce Option as defined by RFC 3971 section 5.3.2.

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 (NDPNonceOption) Nonce

func (o NDPNonceOption) Nonce() []byte

Nonce returns the nonce value this option holds.

func (NDPNonceOption) String

func (o NDPNonceOption) String() string

String implements fmt.Stringer.

type NDPOption

type NDPOption interface {
	fmt.Stringer
	// 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 occurred.

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 b.

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) 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 NDPInfiniteLifetime.

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) String

func (o NDPPrefixInformation) String() string

String implements fmt.Stringer.

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) 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 NDPInfiniteLifetime.

type NDPRecursiveDNSServer

type NDPRecursiveDNSServer []byte

NDPRecursiveDNSServer is the NDP Recursive DNS Server option, as defined by RFC 8106 section 5.1.

To make sure that the option meets its minimum length and does not end in the middle of a DNS server's IPv6 address, the length of a valid NDPRecursiveDNSServer must meet the following constraint:

(Length - ndpRecursiveDNSServerAddressesOffset) % IPv6AddressSize == 0

func (NDPRecursiveDNSServer) Addresses

func (o NDPRecursiveDNSServer) Addresses() ([]tcpip.Address, error)

Addresses returns the recursive DNS server IPv6 addresses that may be used for name resolution.

Note, the addresses MAY be link-local addresses.

func (NDPRecursiveDNSServer) Lifetime

func (o NDPRecursiveDNSServer) Lifetime() time.Duration

Lifetime returns the length of time that the DNS server addresses in this option may be used for name resolution.

Note, a value of 0 implies the addresses should no longer be used, and a value of infinity/forever is represented by NDPInfiniteLifetime.

Lifetime may panic if o does not have enough bytes to hold the Lifetime field.

func (NDPRecursiveDNSServer) String

func (o NDPRecursiveDNSServer) String() string

String implements fmt.Stringer.

type NDPRouteInformation

type NDPRouteInformation []byte

NDPRouteInformation is the NDP Router Information option, as defined by RFC 4191 section 2.3.

func (NDPRouteInformation) Prefix

func (o NDPRouteInformation) Prefix() (tcpip.Subnet, error)

Prefix returns the prefix of the destination subnet this route is for.

func (NDPRouteInformation) PrefixLength

func (o NDPRouteInformation) PrefixLength() uint8

PrefixLength returns the length of the prefix.

func (NDPRouteInformation) RouteLifetime

func (o NDPRouteInformation) RouteLifetime() time.Duration

RouteLifetime returns the lifetime of the route.

Note, a value of 0 implies the route is now invalid and a value of infinity/forever is represented by NDPInfiniteLifetime.

func (NDPRouteInformation) RoutePreference

func (o NDPRouteInformation) RoutePreference() NDPRoutePreference

RoutePreference returns the preference of the route over other routes to the same destination but through a different router.

func (NDPRouteInformation) String

func (o NDPRouteInformation) String() string

String implements fmt.Stringer.

type NDPRoutePreference

type NDPRoutePreference uint8

NDPRoutePreference is the preference values for default routers or more-specific routes.

As per RFC 4191 section 2.1,

Default router preferences and preferences for more-specific routes
are encoded the same way.

Preference values are encoded as a two-bit signed integer, as
follows:

   01      High
   00      Medium (default)
   11      Low
   10      Reserved - MUST NOT be sent

Note that implementations can treat the value as a two-bit signed
integer.

Having just three values reinforces that they are not metrics and
more values do not appear to be necessary for reasonable scenarios.

func (NDPRoutePreference) String

func (p NDPRoutePreference) String() string

String implements fmt.Stringer.

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 and RFC 4191 section 2.2 for more details.

func (NDPRouterAdvert) CurrHopLimit

func (b NDPRouterAdvert) CurrHopLimit() uint8

CurrHopLimit returns the value of the Curr Hop Limit field.

func (NDPRouterAdvert) DefaultRouterPreference

func (b NDPRouterAdvert) DefaultRouterPreference() NDPRoutePreference

DefaultRouterPreference returns the Default Router Preference 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 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 NDPRouterSolicit

type NDPRouterSolicit []byte

NDPRouterSolicit is an NDP Router Solicitation message. It will only contain the body of an ICMPv6 packet.

See RFC 4861 section 4.1 for more details.

func (NDPRouterSolicit) Options

func (b NDPRouterSolicit) Options() NDPOptions

Options returns an NDPOptions of the options body.

type NDPSourceLinkLayerAddressOption

type NDPSourceLinkLayerAddressOption tcpip.LinkAddress

NDPSourceLinkLayerAddressOption is the NDP Source 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 (NDPSourceLinkLayerAddressOption) EthernetAddress

EthernetAddress will return an ethernet (MAC) address if the NDPSourceLinkLayerAddressOption'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 (NDPSourceLinkLayerAddressOption) String

String implements fmt.Stringer.

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) String

String implements fmt.Stringer.

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. The return value is the length of the TCP header in bytes.

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 TCPFlags, 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() TCPFlags

Flags returns the flags field of the TCP header.

func (TCP) IsChecksumValid

func (b TCP) IsChecksumValid(src, dst tcpip.Address, payloadChecksum, payloadLength uint16) bool

IsChecksumValid returns true iff the TCP header's checksum is valid.

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) SetAckNumber

func (b TCP) SetAckNumber(ackNum uint32)

SetAckNumber sets the ack number field of the TCP header.

func (TCP) SetChecksum

func (b TCP) SetChecksum(xsum uint16)

SetChecksum sets the checksum field of the TCP header.

func (TCP) SetDataOffset

func (b TCP) SetDataOffset(headerLen uint8)

SetDataOffset sets the data offset field of the TCP header. headerLen should be the length of the TCP header in bytes.

func (TCP) SetDestinationPort

func (b TCP) SetDestinationPort(port uint16)

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

func (TCP) SetDestinationPortWithChecksumUpdate

func (b TCP) SetDestinationPortWithChecksumUpdate(new uint16)

SetDestinationPortWithChecksumUpdate implements ChecksummableTransport.

func (TCP) SetFlags

func (b TCP) SetFlags(flags uint8)

SetFlags sets the flags field of the TCP header.

func (TCP) SetSequenceNumber

func (b TCP) SetSequenceNumber(seqNum uint32)

SetSequenceNumber sets the sequence number 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) SetSourcePortWithChecksumUpdate

func (b TCP) SetSourcePortWithChecksumUpdate(new uint16)

SetSourcePortWithChecksumUpdate implements ChecksummableTransport.

func (TCP) SetUrgentPointer

func (b TCP) SetUrgentPointer(urgentPointer uint16)

SetUrgentPointer sets the window size field of the TCP header.

func (TCP) SetWindowSize

func (b TCP) SetWindowSize(rcvwnd uint16)

SetWindowSize sets the window size 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) UpdateChecksumPseudoHeaderAddress

func (b TCP) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullChecksum bool)

UpdateChecksumPseudoHeaderAddress implements ChecksummableTransport.

func (TCP) UrgentPointer

func (b TCP) UrgentPointer() uint16

UrgentPointer returns the "urgent pointer" 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. It is the length of
	// the TCP header in bytes.
	DataOffset uint8

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

	// 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 TCPFlags

type TCPFlags uint8

TCPFlags is the dedicated type for TCP flags.

const (
	TCPFlagFin TCPFlags = 1 << iota
	TCPFlagSyn
	TCPFlagRst
	TCPFlagPsh
	TCPFlagAck
	TCPFlagUrg
	TCPFlagEce
	TCPFlagCwr
)

Flags that may be set in a TCP segment.

func (TCPFlags) Contains

func (f TCPFlags) Contains(o TCPFlags) bool

Contains returns true iff all the flags in o are contained within f.

func (TCPFlags) Intersects

func (f TCPFlags) Intersects(o TCPFlags) bool

Intersects returns true iff there are flags common to both f and o.

func (TCPFlags) String

func (f TCPFlags) String() string

String implements Stringer.String.

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

	// Flags if specified are set on the outgoing SYN. The SYN flag is
	// always set.
	Flags TCPFlags
}

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

+stateify savable

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) IsChecksumValid

func (b UDP) IsChecksumValid(src, dst tcpip.Address, payloadChecksum uint16) bool

IsChecksumValid returns true iff the UDP header's checksum is valid.

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(xsum 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) SetDestinationPortWithChecksumUpdate

func (b UDP) SetDestinationPortWithChecksumUpdate(new uint16)

SetDestinationPortWithChecksumUpdate implements ChecksummableTransport.

func (UDP) SetLength

func (b UDP) SetLength(length uint16)

SetLength sets the "length" 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) SetSourcePortWithChecksumUpdate

func (b UDP) SetSourcePortWithChecksumUpdate(new uint16)

SetSourcePortWithChecksumUpdate implements ChecksummableTransport.

func (UDP) SourcePort

func (b UDP) SourcePort() uint16

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

func (UDP) UpdateChecksumPseudoHeaderAddress

func (b UDP) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullChecksum bool)

UpdateChecksumPseudoHeaderAddress implements ChecksummableTransport.

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.

type VirtioNetHeader

type VirtioNetHeader []byte

VirtioNetHeader represents a virtio net header stored in a byte array.

func (VirtioNetHeader) CSumOffset

func (v VirtioNetHeader) CSumOffset() uint16

CSumOffset returns the "csumOffset" field of the virtio net header.

func (VirtioNetHeader) CSumStart

func (v VirtioNetHeader) CSumStart() uint16

CSumStart returns the "csumStart" field of the virtio net header.

func (VirtioNetHeader) Encode

Encode encodes all the fields of the virtio net header.

func (VirtioNetHeader) Flags

func (v VirtioNetHeader) Flags() uint8

Flags returns the "flags" field of the virtio net header.

func (VirtioNetHeader) GSOSize

func (v VirtioNetHeader) GSOSize() uint16

GSOSize returns the "gsoSize" field of the virtio net header.

func (VirtioNetHeader) GSOType

func (v VirtioNetHeader) GSOType() uint8

GSOType returns the "gsoType" field of the virtio net header.

func (VirtioNetHeader) HdrLen

func (v VirtioNetHeader) HdrLen() uint16

HdrLen returns the "hdrLen" field of the virtio net header.

type VirtioNetHeaderFields

type VirtioNetHeaderFields struct {
	Flags      uint8
	GSOType    uint8
	HdrLen     uint16
	GSOSize    uint16
	CSumStart  uint16
	CSumOffset uint16
}

VirtioNetHeaderFields is the Go equivalent of the struct declared in linux/virtio_net.h.

Directories

Path Synopsis
Package parse provides utilities to parse packets.
Package parse provides utilities to parse packets.

Jump to

Keyboard shortcuts

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