Documentation ¶
Overview ¶
Package layerexts contains useful extensions to gopacket. E.g. creating layer decoders, running tests against the layers returned by a decode, and representing layers that can be both sent and received.
This package is public to ease extending the bmc library, however please consider contributing your additions back!
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDecoder ¶
func BuildDecoder(newLayer func() LayerDecodingLayer) gopacket.Decoder
BuildDecoder creates a gopacket.Decoder for a layer implementing the required methods. It is useful when creating a gopacket.LayerTypeMetadata, however note this decoder is not used in the context of gopacket.DecodingLayer. This function takes a generating function rather than concrete instance, as otherwise decoded layers will appear to overwrite each other.
Types ¶
type DecodedTypes ¶
DecodedTypes represents a sequence of layers in the order they were decoded.
Originally, this was a struct containing a slice of layers in the order they were decoded, along with a map[gopacket.LayerType]gopacket.Layer. The idea was the slice provided layer order (answering questions like "What is the inner-most layer?") and the map provides fast lookup ("Is this layer present in the response?"). There were several issues however. The map required a fresh allocation per packet decoded (morphing the previous map into the new one would be too inefficient), the layer returned by the map lookup was of the wrong type, and users of the map had access to a copy in the right type anyway, so this was not useful. It also turns out searching through a slice is quicker than a map lookup for sizes <5 or so, and in practice we never have more than 5 layers in a packet. Hence, the map was discarded.
func (DecodedTypes) Contains ¶
func (ts DecodedTypes) Contains(needle gopacket.LayerType) error
Contains ensures the provided layer is present. If not, it returns an appropriate error.
func (DecodedTypes) InnermostEquals ¶
func (ts DecodedTypes) InnermostEquals(want gopacket.LayerType) error
InnermostEquals ensures the inner-most layer, i.e. the last one decoded, is of a particular type. If it is not, an error is returned.
type LayerDecodingLayer ¶
type LayerDecodingLayer interface { gopacket.Layer DecodeFromBytes([]byte, gopacket.DecodeFeedback) error NextLayerType() gopacket.LayerType }
LayerDecodingLayer is satisfied by types that we can generate a decoder. This is lifted from gopacket, where it is not exported.
type SerializableDecodingLayer ¶
type SerializableDecodingLayer interface { gopacket.SerializableLayer gopacket.DecodingLayer }
SerializableDecodingLayer is satisfied by layers that can be both serialised and decoded. It is intended to be used for layers that can be both sent and received.