suricata
util-streaming-buffer.c File Reference

Streaming Buffer API. More...

#include "suricata-common.h"
#include "util-streaming-buffer.h"
#include "util-unittest.h"
#include "util-print.h"
#include "util-validate.h"
Include dependency graph for util-streaming-buffer.c:

Go to the source code of this file.

Macros

#define MALLOC(cfg, s)   (cfg)->Malloc ? (cfg)->Malloc((s)) : SCMalloc((s))
 
#define CALLOC(cfg, n, s)   (cfg)->Calloc ? (cfg)->Calloc((n), (s)) : SCCalloc((n), (s))
 
#define REALLOC(cfg, ptr, orig_s, s)   (cfg)->Realloc ? (cfg)->Realloc((ptr), (orig_s), (s)) : SCRealloc((ptr), (s))
 
#define FREE(cfg, ptr, s)   (cfg)->Free ? (cfg)->Free((ptr), (s)) : SCFree((ptr))
 
#define DATA_FITS(sb, len)   ((sb)->buf_offset + (len) <= (sb)->buf_size)
 
#define DATA_FITS_AT_OFFSET(sb, len, offset)   ((offset) + (len) <= (sb)->buf_size)
 

Functions

 RB_GENERATE (SBB, StreamingBufferBlock, rb, SBBCompare)
 
int SBBCompare (struct StreamingBufferBlock *a, struct StreamingBufferBlock *b)
 
StreamingBufferBlockSBB_RB_FIND_INCLUSIVE (struct SBB *head, StreamingBufferBlock *elm)
 
StreamingBufferStreamingBufferInit (const StreamingBufferConfig *cfg)
 
void StreamingBufferClear (StreamingBuffer *sb)
 
void StreamingBufferFree (StreamingBuffer *sb)
 
void StreamingBufferSlideToOffset (StreamingBuffer *sb, uint64_t offset)
 slide to absolute offset More...
 
void StreamingBufferSlide (StreamingBuffer *sb, uint32_t slide)
 
StreamingBufferSegment * StreamingBufferAppendRaw (StreamingBuffer *sb, const uint8_t *data, uint32_t data_len)
 
int StreamingBufferAppend (StreamingBuffer *sb, StreamingBufferSegment *seg, const uint8_t *data, uint32_t data_len)
 
int StreamingBufferAppendNoTrack (StreamingBuffer *sb, const uint8_t *data, uint32_t data_len)
 add data w/o tracking a segment More...
 
int StreamingBufferInsertAt (StreamingBuffer *sb, StreamingBufferSegment *seg, const uint8_t *data, uint32_t data_len, uint64_t offset)
 
int StreamingBufferSegmentIsBeforeWindow (const StreamingBuffer *sb, const StreamingBufferSegment *seg)
 
void StreamingBufferSBBGetData (const StreamingBuffer *sb, const StreamingBufferBlock *sbb, const uint8_t **data, uint32_t *data_len)
 get the data for one SBB More...
 
void StreamingBufferSBBGetDataAtOffset (const StreamingBuffer *sb, const StreamingBufferBlock *sbb, const uint8_t **data, uint32_t *data_len, uint64_t offset)
 get the data for one SBB More...
 
void StreamingBufferSegmentGetData (const StreamingBuffer *sb, const StreamingBufferSegment *seg, const uint8_t **data, uint32_t *data_len)
 
int StreamingBufferSegmentCompareRawData (const StreamingBuffer *sb, const StreamingBufferSegment *seg, const uint8_t *rawdata, uint32_t rawdata_len)
 
int StreamingBufferGetData (const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t *stream_offset)
 
int StreamingBufferGetDataAtOffset (const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t offset)
 
int StreamingBufferCompareRawData (const StreamingBuffer *sb, const uint8_t *rawdata, uint32_t rawdata_len)
 
void StreamingBufferRegisterTests (void)
 

Detailed Description

Streaming Buffer API.

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Definition in file util-streaming-buffer.c.

Macro Definition Documentation

◆ CALLOC

#define CALLOC (   cfg,
  n,
 
)    (cfg)->Calloc ? (cfg)->Calloc((n), (s)) : SCCalloc((n), (s))

Definition at line 36 of file util-streaming-buffer.c.

◆ DATA_FITS

#define DATA_FITS (   sb,
  len 
)    ((sb)->buf_offset + (len) <= (sb)->buf_size)

Definition at line 532 of file util-streaming-buffer.c.

◆ DATA_FITS_AT_OFFSET

#define DATA_FITS_AT_OFFSET (   sb,
  len,
  offset 
)    ((offset) + (len) <= (sb)->buf_size)

Definition at line 655 of file util-streaming-buffer.c.

◆ FREE

#define FREE (   cfg,
  ptr,
 
)    (cfg)->Free ? (cfg)->Free((ptr), (s)) : SCFree((ptr))

Definition at line 40 of file util-streaming-buffer.c.

◆ MALLOC

#define MALLOC (   cfg,
 
)    (cfg)->Malloc ? (cfg)->Malloc((s)) : SCMalloc((s))

Definition at line 34 of file util-streaming-buffer.c.

◆ REALLOC

#define REALLOC (   cfg,
  ptr,
  orig_s,
 
)    (cfg)->Realloc ? (cfg)->Realloc((ptr), (orig_s), (s)) : SCRealloc((ptr), (s))

Definition at line 38 of file util-streaming-buffer.c.

Function Documentation

◆ RB_GENERATE()

RB_GENERATE ( SBB  ,
StreamingBufferBlock  ,
rb  ,
SBBCompare   
)

◆ SBB_RB_FIND_INCLUSIVE()

StreamingBufferBlock* SBB_RB_FIND_INCLUSIVE ( struct SBB *  head,
StreamingBufferBlock elm 
)

◆ SBBCompare()

int SBBCompare ( struct StreamingBufferBlock a,
struct StreamingBufferBlock b 
)

◆ StreamingBufferAppend()

int StreamingBufferAppend ( StreamingBuffer sb,
StreamingBufferSegment *  seg,
const uint8_t *  data,
uint32_t  data_len 
)

Definition at line 576 of file util-streaming-buffer.c.

References StreamingBuffer_::buf, and BUG_ON.

Referenced by UTHAddStreamToFlow().

Here is the caller graph for this function:

◆ StreamingBufferAppendNoTrack()

int StreamingBufferAppendNoTrack ( StreamingBuffer sb,
const uint8_t *  data,
uint32_t  data_len 
)

add data w/o tracking a segment

Definition at line 619 of file util-streaming-buffer.c.

References StreamingBuffer_::buf.

◆ StreamingBufferAppendRaw()

StreamingBufferSegment* StreamingBufferAppendRaw ( StreamingBuffer sb,
const uint8_t *  data,
uint32_t  data_len 
)

Definition at line 535 of file util-streaming-buffer.c.

References StreamingBuffer_::buf.

◆ StreamingBufferClear()

void StreamingBufferClear ( StreamingBuffer sb)

Definition at line 132 of file util-streaming-buffer.c.

References StreamingBuffer_::buf_size, and SCLogDebug.

Referenced by StreamingBufferFree(), StreamTcpPruneSession(), and StreamTcpStreamCleanup().

Here is the caller graph for this function:

◆ StreamingBufferCompareRawData()

int StreamingBufferCompareRawData ( const StreamingBuffer sb,
const uint8_t *  rawdata,
uint32_t  rawdata_len 
)
Return values
1data is the same
0data is different

Definition at line 889 of file util-streaming-buffer.c.

References offset, PrintRawDataFp(), SCLogDebug, and StreamingBufferGetData().

Referenced by StreamTcpCheckStreamContents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StreamingBufferFree()

void StreamingBufferFree ( StreamingBuffer sb)

Definition at line 145 of file util-streaming-buffer.c.

References StreamingBuffer_::cfg, FREE, and StreamingBufferClear().

Referenced by HtpBodyFree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StreamingBufferGetData()

int StreamingBufferGetData ( const StreamingBuffer sb,
const uint8_t **  data,
uint32_t *  data_len,
uint64_t *  stream_offset 
)

Definition at line 849 of file util-streaming-buffer.c.

References StreamingBuffer_::buf, StreamingBuffer_::buf_offset, stream_offset, and StreamingBuffer_::stream_offset.

Referenced by StreamingBufferCompareRawData().

Here is the caller graph for this function:

◆ StreamingBufferGetDataAtOffset()

int StreamingBufferGetDataAtOffset ( const StreamingBuffer sb,
const uint8_t **  data,
uint32_t *  data_len,
uint64_t  offset 
)

◆ StreamingBufferInit()

◆ StreamingBufferInsertAt()

int StreamingBufferInsertAt ( StreamingBuffer sb,
StreamingBufferSegment *  seg,
const uint8_t *  data,
uint32_t  data_len,
uint64_t  offset 
)
Parameters
offsetoffset relative to StreamingBuffer::stream_offset

Definition at line 661 of file util-streaming-buffer.c.

References StreamingBuffer_::buf, BUG_ON, and stream_offset.

◆ StreamingBufferRegisterTests()

void StreamingBufferRegisterTests ( void  )

Definition at line 1477 of file util-streaming-buffer.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ StreamingBufferSBBGetData()

void StreamingBufferSBBGetData ( const StreamingBuffer sb,
const StreamingBufferBlock sbb,
const uint8_t **  data,
uint32_t *  data_len 
)

◆ StreamingBufferSBBGetDataAtOffset()

void StreamingBufferSBBGetDataAtOffset ( const StreamingBuffer sb,
const StreamingBufferBlock sbb,
const uint8_t **  data,
uint32_t *  data_len,
uint64_t  offset 
)

◆ StreamingBufferSegmentCompareRawData()

int StreamingBufferSegmentCompareRawData ( const StreamingBuffer sb,
const StreamingBufferSegment *  seg,
const uint8_t *  rawdata,
uint32_t  rawdata_len 
)
Return values
1data is the same
0data is different

Definition at line 833 of file util-streaming-buffer.c.

References StreamingBufferSegmentGetData().

Here is the call graph for this function:

◆ StreamingBufferSegmentGetData()

void StreamingBufferSegmentGetData ( const StreamingBuffer sb,
const StreamingBufferSegment *  seg,
const uint8_t **  data,
uint32_t *  data_len 
)

◆ StreamingBufferSegmentIsBeforeWindow()

int StreamingBufferSegmentIsBeforeWindow ( const StreamingBuffer sb,
const StreamingBufferSegment *  seg 
)

Definition at line 731 of file util-streaming-buffer.c.

References StreamingBuffer_::stream_offset.

Referenced by HtpBodyPrune().

Here is the caller graph for this function:

◆ StreamingBufferSlide()

void StreamingBufferSlide ( StreamingBuffer sb,
uint32_t  slide 
)

◆ StreamingBufferSlideToOffset()

void StreamingBufferSlideToOffset ( StreamingBuffer sb,
uint64_t  offset 
)

slide to absolute offset

Todo:
if sliding beyond window, we could perhaps reset?

Definition at line 507 of file util-streaming-buffer.c.

References StreamingBuffer_::buf, StreamingBuffer_::buf_offset, offset, SCLogDebug, stream_offset, and StreamingBuffer_::stream_offset.

Referenced by HtpBodyPrune().

Here is the caller graph for this function: