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

#define CALLOC (   cfg,
  n,
 
)    (cfg)->Calloc ? (cfg)->Calloc((n), (s)) : SCCalloc((n), (s))
#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)

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

Referenced by StreamingBufferInsertAt().

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

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

#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.

Referenced by StreamingBufferFree().

Function Documentation

RB_GENERATE ( SBB  ,
StreamingBufferBlock  ,
rb  ,
SBBCompare   
)
int SBBCompare ( struct StreamingBufferBlock a,
struct StreamingBufferBlock b 
)
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 
)
StreamingBufferSegment* StreamingBufferAppendRaw ( StreamingBuffer sb,
const uint8_t *  data,
uint32_t  data_len 
)
void StreamingBufferClear ( StreamingBuffer sb)
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 
)
StreamingBuffer* StreamingBufferInit ( const StreamingBufferConfig cfg)

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

References StreamingBufferConfig_::buf_size, StreamingBuffer_::buf_size, CALLOC, StreamingBuffer_::cfg, and FREE.

Referenced by FileSetRange(), HtpBodyAppendChunk(), and StreamingBufferCompareRawData().

Here is the caller graph for this function:

int StreamingBufferInsertAt ( StreamingBuffer sb,
StreamingBufferSegment *  seg,
const uint8_t *  data,
uint32_t  data_len,
uint64_t  offset 
)
void StreamingBufferRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

void StreamingBufferSBBGetData ( const StreamingBuffer sb,
const StreamingBufferBlock sbb,
const uint8_t **  data,
uint32_t *  data_len 
)
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

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

References StreamingBuffer_::buf, StreamingBuffer_::buf_size, BUG_ON, StreamingBufferBlock::len, StreamingBufferBlock::offset, and StreamingBuffer_::stream_offset.

Referenced by StreamNeedsReassembly().

Here is the caller graph for this function:

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().

Referenced by DetectPcrePayloadMatch(), and StreamingBufferCompareRawData().

Here is the call graph for this function:

Here is the caller graph for this function:

void StreamingBufferSegmentGetData ( const StreamingBuffer sb,
const StreamingBufferSegment *  seg,
const uint8_t **  data,
uint32_t *  data_len 
)
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(), StreamingBufferCompareRawData(), and StreamTcpReassembleInsertSegment().

Here is the caller graph for this function:

void StreamingBufferSlide ( StreamingBuffer sb,
uint32_t  slide 
)

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

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

Referenced by StreamingBufferCompareRawData().

Here is the caller graph for this function:

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, SCLogDebug, stream_offset, and StreamingBuffer_::stream_offset.

Referenced by FileTrackedSize(), HtpBodyPrune(), and StreamTcpPruneSession().

Here is the caller graph for this function: