Documentation ¶
Overview ¶
Package fwdpacket contains routines and types for manipulating packets.
Index ¶
- Constants
- Variables
- func Log(packet Packet)
- func MaxSize(id FieldID) int
- func Pad(id FieldID, field []byte) []byte
- func Register(p Parser)
- func SetNID(packet Packet, nid fwdobject.NID, num fwdpb.PacketFieldNum) error
- func Truncate(field []byte, size int) []byte
- func Validate(id FieldID, size int) error
- type FieldID
- type Packet
- type Parser
Constants ¶
const ( FirstField = 0 // The first (outermost) instance of a field. LastField = (1 << 8) - 1 // The last (innermost) instance of a field. )
Constants used to indicate relative instances.
const ( OpInc = iota // Increment a field with the specified value. OpDec // Decrement a field with the specified value. OpSet // Set a field to the specified value. )
Operations that can be applied to a field.
const ( LogDebugMessage = iota // log a debug message LogDebugFrame // log a debug message with the frame LogErrorFrame // log an error message with the frame LogDesc // sets the packet's description (prefixed to all messages) )
Enumeration of various operations that can be performed on the packet log.
Variables ¶
var AttrPacketDebug = fwdattribute.ID("PacketDebug")
AttrPacketDebug controls packet debugging.
Functions ¶
Types ¶
type FieldID ¶
type FieldID struct { IsUDF bool // true if the field is a UDF. Instance uint8 // Instance of the field in a packet. Num fwdpb.PacketFieldNum // Field number. Header fwdpb.PacketHeaderGroup // Header type of UDF. Offset uint8 // UDF's offset within the header. Size uint8 // UDF size in bytes. }
A FieldID identifies a field in a packet. It supports fields using field numbers and user defined fields (UDF).
func NewFieldID ¶
func NewFieldID(field *fwdpb.PacketFieldId) FieldID
NewFieldID creates a new packet field id.
func NewFieldIDFromBytes ¶
func NewFieldIDFromBytes(header fwdpb.PacketHeaderGroup, offset, size, instance uint32) FieldID
NewFieldIDFromBytes creates a new field id from a set of bytes.
func NewFieldIDFromNum ¶
func NewFieldIDFromNum(num fwdpb.PacketFieldNum, instance uint32) FieldID
NewFieldIDFromNum creates a new field id from a field number.
type Packet ¶
type Packet interface { // Field returns the bytes associated with a field ID. Field(id FieldID) ([]byte, error) // Update updates a field in the packet. Update(id FieldID, op int, arg []byte) error // Decap removes the outermost header of the specified type. Decap(id fwdpb.PacketHeaderId) error // Encap adds an outermost header of the specified type. Encap(id fwdpb.PacketHeaderId) error // Reparse reparses the current packet to start from the specified packet header // id. Note that the current packet is rebuilt before it is reparsed. Note that // by default reparsing creates a new packet, so metadata fields will be lost. // Additional fields specified during reparsing ensures that the field values // are copied from the old packet to the new packet. This can be used to retain // metadata field values across a packet reparse. It can also prepend the // rebuilt packet with the specified set of bytes before reparsing the packet. Reparse(id fwdpb.PacketHeaderId, fields []FieldID, prepend []byte) error // Mirror creates a new packet from the current packet. Note that the current // packet is rebuilt before it is mirrored. Note that by default the metadata // fields are lost. Additional fields specified during the mirror ensures that // the field values are copied from the old packet to the new packet. This can // be used to retain metadata field values across a mirror. Mirror(fields []FieldID) (Packet, error) // String formats the packet into a string. String() string // Length returns the length of the packet in bytes. Length() int // Frame returns the packet as a slice of bytes. Frame() []byte // Debug control debugging for the packet. Debug(enable bool) // Logf controls the packet's message log. Logf(level int, fmt string, args ...interface{}) // Log returns the contents of the packet's log. Log() []string // Attributes returns the attributes associated with the packet. Attributes() fwdattribute.Set // StartHeader returns the first header of the packet. StartHeader() fwdpb.PacketHeaderId }
Packet is a network packet that can be queried and manipulated.
Packet repesents a network packet that has been parsed and verfied. It supports queries on various fields. Additionally it can change the network packet by adding and removing headers or setting packet fields.
type Parser ¶
type Parser interface { // New creates a new packet using the specified first header id. New(hid fwdpb.PacketHeaderId, bytes []byte) (Packet, error) // Validate validates the size of the specified field. Validate(id FieldID, size int) error // MaxSize returns the maximum size of the specified field. MaxSize(id FieldID) int }
Parser can create a Packet from a slice of bytes containing the packet.