Documentation
¶
Overview ¶
Package alignedbuff implements encoding and decoding aligned data elements to/from buffers in native endianess.
Note ¶
The alignment/padding as implemented in this package must match that of kernel's and user space C implementations for a particular architecture (bit size). Please see also the "dummy structure" _xt_align (https://elixir.bootlin.com/linux/v5.17.7/source/include/uapi/linux/netfilter/x_tables.h#L93) as well as the associated XT_ALIGN C preprocessor macro.
In particular, we rely on the Go compiler to follow the same architecture alignments as the C compiler(s) on Linux.
Index ¶
- Variables
- type AlignedBuff
- func (a *AlignedBuff) BytesAligned32(size int) ([]byte, error)
- func (a *AlignedBuff) Data() []byte
- func (a *AlignedBuff) Int32() (int32, error)
- func (a *AlignedBuff) PutBytesAligned32(data []byte, size int)
- func (a *AlignedBuff) PutInt32(v int32)
- func (a *AlignedBuff) PutString(v string)
- func (a *AlignedBuff) PutUint(v uint)
- func (a *AlignedBuff) PutUint16(v uint16)
- func (a *AlignedBuff) PutUint16BE(v uint16)
- func (a *AlignedBuff) PutUint32(v uint32)
- func (a *AlignedBuff) PutUint64(v uint64)
- func (a *AlignedBuff) PutUint8(v uint8)
- func (a *AlignedBuff) String() (string, error)
- func (a *AlignedBuff) StringWithLength(len int) (string, error)
- func (a *AlignedBuff) Uint() (uint, error)
- func (a *AlignedBuff) Uint16() (uint16, error)
- func (a *AlignedBuff) Uint16BE() (uint16, error)
- func (a *AlignedBuff) Uint32() (uint32, error)
- func (a *AlignedBuff) Uint64() (uint64, error)
- func (a *AlignedBuff) Uint8() (uint8, error)
Constants ¶
This section is empty.
Variables ¶
var ErrEOF = errors.New("not enough data left")
ErrEOF signals trying to read beyond the available payload information.
Functions ¶
This section is empty.
Types ¶
type AlignedBuff ¶
type AlignedBuff struct {
// contains filtered or unexported fields
}
AlignedBuff implements marshalling and unmarshalling information in platform/architecture native endianess and data type alignment. It additionally covers some of the nftables-xtables translation-specific idiosyncracies to the extend needed in order to properly marshal and unmarshal Match and Target expressions, and their Info payload in particular.
func New ¶
func New() AlignedBuff
New returns a new AlignedBuff for marshalling aligned data in native endianess.
func NewWithData ¶
func NewWithData(data []byte) AlignedBuff
NewWithData returns a new AlignedBuff for unmarshalling the passed data in native endianess.
func (*AlignedBuff) BytesAligned32 ¶
func (a *AlignedBuff) BytesAligned32(size int) ([]byte, error)
BytesAligned32 unmarshals the given amount of bytes starting with the native alignment for uint32 data types. It returns ErrEOF when trying to read beyond the payload.
BytesAligned32 is used to unmarshal IP addresses for different IP versions, which are always aligned the same way as the native alignment for uint32.
func (*AlignedBuff) Data ¶
func (a *AlignedBuff) Data() []byte
Data returns the properly padded info payload data written before by calling the various Uint8, Uint16, ... marshalling functions.
func (*AlignedBuff) Int32 ¶
func (a *AlignedBuff) Int32() (int32, error)
Int32 unmarshals an int32 in native endianess and alignment. It returns ErrEOF when trying to read beyond the payload.
func (*AlignedBuff) PutBytesAligned32 ¶
func (a *AlignedBuff) PutBytesAligned32(data []byte, size int)
PutBytesAligned32 marshals the given bytes starting with the native alignment for uint32 data types. It additionaly adds padding to reach the specified size.
PutBytesAligned32 is used to marshal IP addresses for different IP versions, which are always aligned the same way as the native alignment for uint32.
func (*AlignedBuff) PutInt32 ¶
func (a *AlignedBuff) PutInt32(v int32)
PutInt32 marshals an int32 in native endianess and alignment.
func (*AlignedBuff) PutString ¶
func (a *AlignedBuff) PutString(v string)
PutString marshals a string.
func (*AlignedBuff) PutUint ¶
func (a *AlignedBuff) PutUint(v uint)
PutUint marshals an uint in native endianess and alignment for the C "unsigned int" type. Please note that on 64bit platforms, the size and alignment of C's and Go's unsigned integer data types differ, so we encapsulate this difference here.
func (*AlignedBuff) PutUint16 ¶
func (a *AlignedBuff) PutUint16(v uint16)
PutUint16 marshals an uint16 in native endianess and alignment.
func (*AlignedBuff) PutUint16BE ¶
func (a *AlignedBuff) PutUint16BE(v uint16)
PutUint16BE marshals an uint16 in "network" (=big endian) endianess and native uint16 alignment.
func (*AlignedBuff) PutUint32 ¶
func (a *AlignedBuff) PutUint32(v uint32)
PutUint32 marshals an uint32 in native endianess and alignment.
func (*AlignedBuff) PutUint64 ¶
func (a *AlignedBuff) PutUint64(v uint64)
PutUint64 marshals an uint64 in native endianess and alignment.
func (*AlignedBuff) PutUint8 ¶
func (a *AlignedBuff) PutUint8(v uint8)
PutUint8 marshals an uint8 in native endianess and alignment.
func (*AlignedBuff) String ¶
func (a *AlignedBuff) String() (string, error)
String unmarshals a null terminated string
func (*AlignedBuff) StringWithLength ¶
func (a *AlignedBuff) StringWithLength(len int) (string, error)
StringWithLength unmarshals a string of a given length (for non-null terminated strings)
func (*AlignedBuff) Uint ¶
func (a *AlignedBuff) Uint() (uint, error)
Uint unmarshals an uint in native endianess and alignment for the C "unsigned int" type. It returns ErrEOF when trying to read beyond the payload. Please note that on 64bit platforms, the size and alignment of C's and Go's unsigned integer data types differ, so we encapsulate this difference here.
func (*AlignedBuff) Uint16 ¶
func (a *AlignedBuff) Uint16() (uint16, error)
Uint16 unmarshals an uint16 in native endianess and alignment. It returns ErrEOF when trying to read beyond the payload.
func (*AlignedBuff) Uint16BE ¶
func (a *AlignedBuff) Uint16BE() (uint16, error)
Uint16BE unmarshals an uint16 in "network" (=big endian) endianess and native uint16 alignment. It returns ErrEOF when trying to read beyond the payload.
func (*AlignedBuff) Uint32 ¶
func (a *AlignedBuff) Uint32() (uint32, error)
Uint32 unmarshals an uint32 in native endianess and alignment. It returns ErrEOF when trying to read beyond the payload.
func (*AlignedBuff) Uint64 ¶
func (a *AlignedBuff) Uint64() (uint64, error)
Uint64 unmarshals an uint64 in native endianess and alignment. It returns ErrEOF when trying to read beyond the payload.
func (*AlignedBuff) Uint8 ¶
func (a *AlignedBuff) Uint8() (uint8, error)
Uint8 unmarshals an uint8 in native endianess and alignment. It returns ErrEOF when trying to read beyond the payload.