Documentation ¶
Overview ¶
Package checker provides helper functions to check networking packets for validity.
Index ¶
- func IPv4(t *testing.T, b []byte, checkers ...NetworkChecker)
- func IPv6(t *testing.T, b []byte, checkers ...NetworkChecker)
- type NetworkChecker
- func DstAddr(addr tcpip.Address) NetworkChecker
- func FragmentFlags(flags uint8) NetworkChecker
- func FragmentOffset(offset uint16) NetworkChecker
- func ICMPv4(checkers ...TransportChecker) NetworkChecker
- func ICMPv6(checkers ...TransportChecker) NetworkChecker
- func IPv6Fragment(checkers ...NetworkChecker) NetworkChecker
- func NDP(msgType header.ICMPv6Type, minSize int, checkers ...TransportChecker) NetworkChecker
- func NDPNS(checkers ...TransportChecker) NetworkChecker
- func PayloadLen(plen int) NetworkChecker
- func Raw(want []byte) NetworkChecker
- func SrcAddr(addr tcpip.Address) NetworkChecker
- func TCP(checkers ...TransportChecker) NetworkChecker
- func TOS(tos uint8, label uint32) NetworkChecker
- func TTL(ttl uint8) NetworkChecker
- func UDP(checkers ...TransportChecker) NetworkChecker
- type TransportChecker
- func AckNum(seq uint32) TransportChecker
- func DstPort(port uint16) TransportChecker
- func ICMPv4Code(want byte) TransportChecker
- func ICMPv4Type(want header.ICMPv4Type) TransportChecker
- func ICMPv6Code(want byte) TransportChecker
- func ICMPv6Type(want header.ICMPv6Type) TransportChecker
- func NDPNSTargetAddress(want tcpip.Address) TransportChecker
- func Payload(want []byte) TransportChecker
- func SeqNum(seq uint32) TransportChecker
- func SrcPort(port uint16) TransportChecker
- func TCPFlags(flags uint8) TransportChecker
- func TCPFlagsMatch(flags, mask uint8) TransportChecker
- func TCPNoSACKBlockChecker() TransportChecker
- func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker
- func TCPSynOptions(wantOpts header.TCPSynOptions) TransportChecker
- func TCPTimestampChecker(wantTS bool, wantTSVal uint32, wantTSEcr uint32) TransportChecker
- func Window(window uint16) TransportChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPv4 ¶
func IPv4(t *testing.T, b []byte, 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, b, checker.SrcAddr(x), checker.DstAddr(y))
Types ¶
type NetworkChecker ¶
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 IPv6Fragment ¶
func IPv6Fragment(checkers ...NetworkChecker) NetworkChecker
IPv6Fragment creates a checker that validates an IPv6 fragment.
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 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 messages concerned. The values within the message are up to checkers to validate.
func PayloadLen ¶
func PayloadLen(plen 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 ¶
TransportChecker is a function to check a property of a transport packet.
func AckNum ¶
func AckNum(seq uint32) TransportChecker
AckNum creates a checker that checks the ack number.
func DstPort ¶
func DstPort(port uint16) TransportChecker
DstPort creates a checker that checks the destination port.
func ICMPv4Code ¶
func ICMPv4Code(want byte) TransportChecker
ICMPv4Code creates a checker that checks the ICMPv4 Code field.
func ICMPv4Type ¶
func ICMPv4Type(want header.ICMPv4Type) TransportChecker
ICMPv4Type creates a checker that checks the ICMPv4 Type field.
func ICMPv6Code ¶
func ICMPv6Code(want byte) TransportChecker
ICMPv6Code creates a checker that checks the ICMPv6 Code field.
func ICMPv6Type ¶
func ICMPv6Type(want header.ICMPv6Type) TransportChecker
ICMPv6Type creates a checker that checks the ICMPv6 Type field.
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 Payload ¶
func Payload(want []byte) TransportChecker
Payload creates a checker that checks the payload.
func SeqNum ¶
func SeqNum(seq uint32) TransportChecker
SeqNum creates a checker that checks the sequence number.
func SrcPort ¶
func SrcPort(port uint16) TransportChecker
SrcPort creates a checker that checks the source port.
func TCPFlags ¶
func TCPFlags(flags uint8) TransportChecker
TCPFlags creates a checker that checks the tcp flags.
func TCPFlagsMatch ¶
func TCPFlagsMatch(flags, mask uint8) TransportChecker
TCPFlagsMatch creates a checker that checks that the tcp flags, masked by the given mask, match the supplied flags.
func TCPNoSACKBlockChecker ¶
func TCPNoSACKBlockChecker() TransportChecker
TCPNoSACKBlockChecker creates a checker that verifies that the segment does not contain any SACK blocks in the TCP options.
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 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 Window ¶
func Window(window uint16) TransportChecker
Window creates a checker that checks the tcp window.