checker

package
v0.0.0-202406181927 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package checker provides helper functions to check networking packets for validity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPv4

func IPv4(t *testing.T, v *buffer.View, checkers ...NetworkChecker)

IPv4 checks the validity and properties of the given IPv4 packet. It is expected to be used in conjunction with other network checkers for specific properties. For example, to check the source and destination address, one would call:

checker.IPv4(t, v, checker.SrcAddr(x), checker.DstAddr(y))

func IPv6

func IPv6(t *testing.T, v *buffer.View, checkers ...NetworkChecker)

IPv6 checks the validity and properties of the given IPv6 packet. The usage is similar to IPv4.

func IPv6WithExtHdr

func IPv6WithExtHdr(t *testing.T, v *buffer.View, checkers ...NetworkChecker)

IPv6WithExtHdr is like IPv6 but allows IPv6 packets with extension headers.

func IgnoreCmpPath

func IgnoreCmpPath(paths ...string) cmp.Option

IgnoreCmpPath returns a cmp.Option that ignores listed field paths.

Types

type ControlMessagesChecker

type ControlMessagesChecker func(*testing.T, tcpip.ReceivableControlMessages)

ControlMessagesChecker is a function to check a property of ancillary data.

func NoHopLimitReceived

func NoHopLimitReceived() ControlMessagesChecker

NoHopLimitReceived creates a checker that checks the absence of the HopLimit field in ControlMessages.

func NoIPPacketInfoReceived

func NoIPPacketInfoReceived() ControlMessagesChecker

NoIPPacketInfoReceived creates a checker that checks the PacketInfo field in ControlMessages.

func NoIPv6PacketInfoReceived

func NoIPv6PacketInfoReceived() ControlMessagesChecker

NoIPv6PacketInfoReceived creates a checker that checks the PacketInfo field in ControlMessages.

func NoTClassReceived

func NoTClassReceived() ControlMessagesChecker

NoTClassReceived creates a checker that checks the absence of the TCLASS field in ControlMessages.

func NoTOSReceived

func NoTOSReceived() ControlMessagesChecker

NoTOSReceived creates a checker that checks the absence of the TOS field in ControlMessages.

func NoTTLReceived

func NoTTLReceived() ControlMessagesChecker

NoTTLReceived creates a checker that checks the absence of the TTL field in ControlMessages.

func ReceiveHopLimit

func ReceiveHopLimit(want uint8) ControlMessagesChecker

ReceiveHopLimit creates a checker that checks the HopLimit field in ControlMessages.

func ReceiveIPPacketInfo

func ReceiveIPPacketInfo(want tcpip.IPPacketInfo) ControlMessagesChecker

ReceiveIPPacketInfo creates a checker that checks the PacketInfo field in ControlMessages.

func ReceiveIPv6PacketInfo

func ReceiveIPv6PacketInfo(want tcpip.IPv6PacketInfo) ControlMessagesChecker

ReceiveIPv6PacketInfo creates a checker that checks the IPv6PacketInfo field in ControlMessages.

func ReceiveOriginalDstAddr

func ReceiveOriginalDstAddr(want tcpip.FullAddress) ControlMessagesChecker

ReceiveOriginalDstAddr creates a checker that checks the OriginalDstAddress field in ControlMessages.

func ReceiveTClass

func ReceiveTClass(want uint32) ControlMessagesChecker

ReceiveTClass creates a checker that checks the TCLASS field in ControlMessages.

func ReceiveTOS

func ReceiveTOS(want uint8) ControlMessagesChecker

ReceiveTOS creates a checker that checks the TOS field in ControlMessages.

func ReceiveTTL

func ReceiveTTL(want uint8) ControlMessagesChecker

ReceiveTTL creates a checker that checks the TTL field in ControlMessages.

type IPv6ExtHdrChecker

type IPv6ExtHdrChecker func(*testing.T, header.IPv6PayloadHeader)

IPv6ExtHdrChecker is a function to check an extension header.

func IPv6HopByHopExtensionHeader

func IPv6HopByHopExtensionHeader(checkers ...IPv6ExtHdrOptionChecker) IPv6ExtHdrChecker

IPv6HopByHopExtensionHeader checks the extension header is a Hop by Hop extension header and validates the containing options with checkers.

checkers must exhaustively contain all the expected options.

type IPv6ExtHdrOptionChecker

type IPv6ExtHdrOptionChecker func(*testing.T, header.IPv6ExtHdrOption)

IPv6ExtHdrOptionChecker is a function to check an extension header option.

func IPv6RouterAlert

IPv6RouterAlert validates that an extension header option is the RouterAlert option and matches on its value.

func IPv6UnknownOption

func IPv6UnknownOption() IPv6ExtHdrOptionChecker

IPv6UnknownOption validates that an extension header option is the unknown header option.

type NetworkChecker

type NetworkChecker func(*testing.T, []header.Network)

NetworkChecker is a function to check a property of a network packet.

func DstAddr

func DstAddr(addr tcpip.Address) NetworkChecker

DstAddr creates a checker that checks the destination address.

func FragmentFlags

func FragmentFlags(flags uint8) NetworkChecker

FragmentFlags creates a checker that checks the fragment flags field.

func FragmentOffset

func FragmentOffset(offset uint16) NetworkChecker

FragmentOffset creates a checker that checks the FragmentOffset field.

func ICMPv4

func ICMPv4(checkers ...TransportChecker) NetworkChecker

ICMPv4 creates a checker that checks that the transport protocol is ICMPv4 and potentially additional ICMPv4 header fields.

func ICMPv6

func ICMPv6(checkers ...TransportChecker) NetworkChecker

ICMPv6 creates a checker that checks that the transport protocol is ICMPv6 and potentially additional ICMPv6 header fields.

ICMPv6 will validate the checksum field before calling checkers.

func IGMP

func IGMP(checkers ...TransportChecker) NetworkChecker

IGMP checks the validity and properties of the given IGMP packet. It is expected to be used in conjunction with other IGMP transport checkers for specific properties.

func IGMPv3Report

func IGMPv3Report(expectedRecords map[tcpip.Address]header.IGMPv3ReportRecordType) NetworkChecker

IGMPv3Report creates a checker that checks that the packet contains a valid IGMPv3 report with the specified records.

Note that observed records are removed from expectedRecords. No error is logged if the report does not have all the records expected.

func IPFullLength

func IPFullLength(packetLength uint16) NetworkChecker

IPFullLength creates a checker for the full IP packet length. The expected size is checked against both the Total Length in the header and the number of bytes received.

func IPPayload

func IPPayload(payload []byte) NetworkChecker

IPPayload creates a checker that checks the payload.

func IPv4HeaderLength

func IPv4HeaderLength(headerLength int) NetworkChecker

IPv4HeaderLength creates a checker that checks the IPv4 Header length.

func IPv4Options

func IPv4Options(want header.IPv4Options) NetworkChecker

IPv4Options returns a checker that checks the options in an IPv4 packet.

func IPv4RouterAlert

func IPv4RouterAlert() NetworkChecker

IPv4RouterAlert returns a checker that checks that the RouterAlert option is set in an IPv4 packet.

func IPv6ExtHdr

func IPv6ExtHdr(headers ...IPv6ExtHdrChecker) NetworkChecker

IPv6ExtHdr checks for the presence of extension headers.

All the extension headers in headers will be checked exhaustively in the order provided.

func IPv6Fragment

func IPv6Fragment(checkers ...NetworkChecker) NetworkChecker

IPv6Fragment creates a checker that validates an IPv6 fragment.

func MLD

func MLD(msgType header.ICMPv6Type, minSize int, checkers ...TransportChecker) NetworkChecker

MLD creates a checker that checks that the packet contains a valid MLD message for type of mldType, with potentially additional checks specified by checkers.

Checkers may assume that a valid ICMPv6 is passed to it containing a valid MLD message as far as the size of the message (minSize) is concerned. The values within the message are up to checkers to validate.

func MLDv2Report

func MLDv2Report(expectedRecords map[tcpip.Address]header.MLDv2ReportRecordType) NetworkChecker

MLDv2Report creates a checker that checks that the packet contains a valid MLDv2 report with the specified records.

Note that observed records are removed from expectedRecords. No error is logged if the report does not have all the records expected.

func NDP

func NDP(msgType header.ICMPv6Type, minSize int, checkers ...TransportChecker) NetworkChecker

NDP creates a checker that checks that the packet contains a valid NDP message for type of ty, with potentially additional checks specified by checkers.

Checkers may assume that a valid ICMPv6 is passed to it containing a valid NDP message as far as the size of the message (minSize) is concerned. The values within the message are up to checkers to validate.

func NDPNA

func NDPNA(checkers ...TransportChecker) NetworkChecker

NDPNA creates a checker that checks that the packet contains a valid NDP Neighbor Advertisement message (as per the raw wire format), with potentially additional checks specified by checkers.

Checkers may assume that a valid ICMPv6 is passed to it containing a valid NDPNA message as far as the size of the message is concerned. The values within the message are up to checkers to validate.

func NDPNS

func NDPNS(checkers ...TransportChecker) NetworkChecker

NDPNS creates a checker that checks that the packet contains a valid NDP Neighbor Solicitation message (as per the raw wire format), with potentially additional checks specified by checkers.

Checkers may assume that a valid ICMPv6 is passed to it containing a valid NDPNS message as far as the size of the message is concerned. The values within the message are up to checkers to validate.

func NDPRS

func NDPRS(checkers ...TransportChecker) NetworkChecker

NDPRS creates a checker that checks that the packet contains a valid NDP Router Solicitation message (as per the raw wire format).

Checkers may assume that a valid ICMPv6 is passed to it containing a valid NDPRS as far as the size of the message is concerned. The values within the message are up to checkers to validate.

func PayloadLen

func PayloadLen(payloadLength int) NetworkChecker

PayloadLen creates a checker that checks the payload length.

func Raw

func Raw(want []byte) NetworkChecker

Raw creates a checker that checks the bytes of payload. The checker always checks the payload of the last network header. For instance, in case of IPv6 fragments, the payload that will be checked is the one containing the actual data that the packet is carrying, without the bytes added by the IPv6 fragmentation.

func SrcAddr

func SrcAddr(addr tcpip.Address) NetworkChecker

SrcAddr creates a checker that checks the source address.

func TCP

func TCP(checkers ...TransportChecker) NetworkChecker

TCP creates a checker that checks that the transport protocol is TCP and potentially additional transport header fields.

func TOS

func TOS(tos uint8, label uint32) NetworkChecker

TOS creates a checker that checks the TOS field.

func TTL

func TTL(ttl uint8) NetworkChecker

TTL creates a checker that checks the TTL (ipv4) or HopLimit (ipv6).

func UDP

func UDP(checkers ...TransportChecker) NetworkChecker

UDP creates a checker that checks that the transport protocol is UDP and potentially additional transport header fields.

type TransportChecker

type TransportChecker func(*testing.T, header.Transport)

TransportChecker is a function to check a property of a transport packet.

func DstPort

func DstPort(port uint16) TransportChecker

DstPort creates a checker that checks the destination port.

func ICMPv4Checksum

func ICMPv4Checksum() TransportChecker

ICMPv4Checksum creates a checker that checks the ICMPv4 Checksum. This assumes that the payload exactly makes up the rest of the slice.

func ICMPv4Code

func ICMPv4Code(want header.ICMPv4Code) TransportChecker

ICMPv4Code creates a checker that checks the ICMPv4 Code field.

func ICMPv4Ident

func ICMPv4Ident(want uint16) TransportChecker

ICMPv4Ident creates a checker that checks the ICMPv4 echo Ident.

func ICMPv4Payload

func ICMPv4Payload(want []byte) TransportChecker

ICMPv4Payload creates a checker that checks the payload in an ICMPv4 packet.

func ICMPv4Pointer

func ICMPv4Pointer(want uint8) TransportChecker

ICMPv4Pointer creates a checker that checks the ICMPv4 Param Problem pointer.

func ICMPv4Seq

func ICMPv4Seq(want uint16) TransportChecker

ICMPv4Seq creates a checker that checks the ICMPv4 echo Sequence.

func ICMPv4Type

func ICMPv4Type(want header.ICMPv4Type) TransportChecker

ICMPv4Type creates a checker that checks the ICMPv4 Type field.

func ICMPv6Code

func ICMPv6Code(want header.ICMPv6Code) TransportChecker

ICMPv6Code creates a checker that checks the ICMPv6 Code field.

func ICMPv6Payload

func ICMPv6Payload(want []byte) TransportChecker

ICMPv6Payload creates a checker that checks the payload in an ICMPv6 packet.

func ICMPv6Type

func ICMPv6Type(want header.ICMPv6Type) TransportChecker

ICMPv6Type creates a checker that checks the ICMPv6 Type field.

func ICMPv6TypeSpecific

func ICMPv6TypeSpecific(want uint32) TransportChecker

ICMPv6TypeSpecific creates a checker that checks the ICMPv6 TypeSpecific field.

func IGMPGroupAddress

func IGMPGroupAddress(want tcpip.Address) TransportChecker

IGMPGroupAddress creates a checker that checks the IGMP Group Address field.

func IGMPGroupAddressUnordered

func IGMPGroupAddressUnordered(expectedGroups map[tcpip.Address]struct{}) TransportChecker

IGMPGroupAddressUnordered creates a checker that checks that the group address in the IGMP message is expected to be seen.

The seen address is removed from the expected groups map.

The returned TransportChecker assumes that a valid IGMP is passed to it containing a valid IGMP message as far as the size is concerned.

func IGMPMaxRespTime

func IGMPMaxRespTime(want time.Duration) TransportChecker

IGMPMaxRespTime creates a checker that checks the IGMP Max Resp Time field.

func IGMPType

func IGMPType(want header.IGMPType) TransportChecker

IGMPType creates a checker that checks the IGMP Type field.

func MLDMaxRespDelay

func MLDMaxRespDelay(want time.Duration) TransportChecker

MLDMaxRespDelay creates a checker that checks the Maximum Response Delay field of a MLD message.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid MLD message as far as the size is concerned.

func MLDMulticastAddress

func MLDMulticastAddress(want tcpip.Address) TransportChecker

MLDMulticastAddress creates a checker that checks the Multicast Address field of a MLD message.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid MLD message as far as the size is concerned.

func MLDMulticastAddressUnordered

func MLDMulticastAddressUnordered(expectedGroups map[tcpip.Address]struct{}) TransportChecker

MLDMulticastAddressUnordered creates a checker that checks that the multicast address in the MLD message is expected to be seen.

The seen address is removed from the expected groups map.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid MLD message as far as the size is concerned.

func NDPNAOptions

func NDPNAOptions(opts []header.NDPOption) TransportChecker

NDPNAOptions creates a checker that checks that the packet contains the provided NDP options within an NDP Neighbor Solicitation message.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPNA message as far as the size is concerned.

func NDPNASolicitedFlag

func NDPNASolicitedFlag(want bool) TransportChecker

NDPNASolicitedFlag creates a checker that checks the Solicited field of a header.NDPNeighborAdvert.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPNA message as far as the size is concerned.

func NDPNATargetAddress

func NDPNATargetAddress(want tcpip.Address) TransportChecker

NDPNATargetAddress creates a checker that checks the Target Address field of a header.NDPNeighborAdvert.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPNA message as far as the size is concerned.

func NDPNSOptions

func NDPNSOptions(opts []header.NDPOption) TransportChecker

NDPNSOptions creates a checker that checks that the packet contains the provided NDP options within an NDP Neighbor Solicitation message.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPNS message as far as the size is concerned.

func NDPNSTargetAddress

func NDPNSTargetAddress(want tcpip.Address) TransportChecker

NDPNSTargetAddress creates a checker that checks the Target Address field of a header.NDPNeighborSolicit.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPNS message as far as the size is concerned.

func NDPRSOptions

func NDPRSOptions(opts []header.NDPOption) TransportChecker

NDPRSOptions creates a checker that checks that the packet contains the provided NDP options within an NDP Router Solicitation message.

The returned TransportChecker assumes that a valid ICMPv6 is passed to it containing a valid NDPRS message as far as the size is concerned.

func NoChecksum

func NoChecksum(noChecksum bool) TransportChecker

NoChecksum creates a checker that checks if the checksum is zero.

func Payload

func Payload(want []byte) TransportChecker

Payload creates a checker that checks the payload.

func SrcPort

func SrcPort(port uint16) TransportChecker

SrcPort creates a checker that checks the source port.

func TCPAckNum

func TCPAckNum(seq uint32) TransportChecker

TCPAckNum creates a checker that checks the ack number.

func TCPFlags

func TCPFlags(flags header.TCPFlags) TransportChecker

TCPFlags creates a checker that checks the tcp flags.

func TCPFlagsMatch

func TCPFlagsMatch(flags, mask header.TCPFlags) TransportChecker

TCPFlagsMatch creates a checker that checks that the tcp flags, masked by the given mask, match the supplied flags.

func TCPSACKBlockChecker

func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker

TCPSACKBlockChecker creates a checker that verifies that the segment does contain the specified SACK blocks in the TCP options.

func TCPSeqNum

func TCPSeqNum(seq uint32) TransportChecker

TCPSeqNum creates a checker that checks the sequence number.

func TCPSynOptions

func TCPSynOptions(wantOpts header.TCPSynOptions) TransportChecker

TCPSynOptions creates a checker that checks the presence of TCP options in SYN segments.

If wndscale is negative, the window scale option must not be present.

func TCPTimestampChecker

func TCPTimestampChecker(wantTS bool, wantTSVal uint32, wantTSEcr uint32) TransportChecker

TCPTimestampChecker creates a checker that validates that a TCP segment has a TCP Timestamp option if wantTS is true, it also compares the wantTSVal and wantTSEcr values with those in the TCP segment (if present).

If wantTSVal or wantTSEcr is zero then the corresponding comparison is skipped.

func TCPWindow

func TCPWindow(window uint16) TransportChecker

TCPWindow creates a checker that checks the tcp window.

func TCPWindowGreaterThanEq

func TCPWindowGreaterThanEq(window uint16) TransportChecker

TCPWindowGreaterThanEq creates a checker that checks that the TCP window is greater than or equal to the provided value.

func TCPWindowLessThanEq

func TCPWindowLessThanEq(window uint16) TransportChecker

TCPWindowLessThanEq creates a checker that checks that the tcp window is less than or equal to the provided value.

func TransportChecksum

func TransportChecksum(want uint16) TransportChecker

TransportChecksum creates a checker that checks the checksum value.

Jump to

Keyboard shortcuts

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