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 "util-debug.h"
#include "util-error.h"
#include "app-layer-htp-mem.h"
#include "conf-yaml-loader.h"
#include "app-layer-htp.h"
Include dependency graph for util-streaming-buffer.c:

Go to the source code of this file.

Macros

#define DUMP_REGIONS   0
 
#define CALLOC(cfg, n, s)   (cfg)->Calloc ? (cfg)->Calloc((n), (s)) : CallocFunc((n), (s))
 
#define REALLOC(cfg, ptr, orig_s, s)   (cfg)->Realloc ? (cfg)->Realloc((ptr), (orig_s), (s)) : ReallocFunc((ptr), (s))
 
#define FREE(cfg, ptr, s)   (cfg)->Free ? (cfg)->Free((ptr), (s)) : SCFree((ptr))
 

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, const StreamingBufferConfig *cfg)
 
void StreamingBufferFree (StreamingBuffer *sb, const StreamingBufferConfig *cfg)
 
void StreamingBufferSlideToOffset (StreamingBuffer *sb, const StreamingBufferConfig *cfg, uint64_t offset)
 slide to absolute offset More...
 
int StreamingBufferAppend (StreamingBuffer *sb, const StreamingBufferConfig *cfg, StreamingBufferSegment *seg, const uint8_t *data, uint32_t data_len)
 
int StreamingBufferAppendNoTrack (StreamingBuffer *sb, const StreamingBufferConfig *cfg, const uint8_t *data, uint32_t data_len)
 add data w/o tracking a segment More...
 
int StreamingBufferInsertAt (StreamingBuffer *sb, const StreamingBufferConfig *cfg, 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)) : CallocFunc((n), (s))

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

◆ DUMP_REGIONS

#define DUMP_REGIONS   0

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

◆ FREE

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

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

◆ REALLOC

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

Definition at line 65 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,
const StreamingBufferConfig cfg,
StreamingBufferSegment *  seg,
const uint8_t *  data,
uint32_t  data_len 
)

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

References BIT_U32, StreamingBufferRegion_::buf, DEBUG_VALIDATE_BUG_ON, and StreamingBuffer_::region.

Referenced by HtpBodyAppendChunk(), and UTHAddStreamToFlow().

Here is the caller graph for this function:

◆ StreamingBufferAppendNoTrack()

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

add data w/o tracking a segment

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

References BIT_U32, StreamingBufferRegion_::buf, DEBUG_VALIDATE_BUG_ON, and StreamingBuffer_::region.

◆ StreamingBufferClear()

void StreamingBufferClear ( StreamingBuffer sb,
const StreamingBufferConfig cfg 
)

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

References StreamingBufferRegion_::buf_size, StreamingBuffer_::region, 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 1830 of file util-streaming-buffer.c.

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

Here is the call graph for this function:

◆ StreamingBufferFree()

void StreamingBufferFree ( StreamingBuffer sb,
const StreamingBufferConfig cfg 
)

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

References 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 
)

◆ StreamingBufferGetDataAtOffset()

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

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

◆ StreamingBufferInit()

StreamingBuffer* StreamingBufferInit ( const StreamingBufferConfig cfg)

◆ StreamingBufferInsertAt()

int StreamingBufferInsertAt ( StreamingBuffer sb,
const StreamingBufferConfig cfg,
StreamingBufferSegment *  seg,
const uint8_t *  data,
uint32_t  data_len,
uint64_t  offset 
)
Parameters
offsetoffset relative to StreamingBuffer::stream_offset
Returns
SC_OK in case of success
SC_E* errors otherwise

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

References BIT_U32, DEBUG_VALIDATE_BUG_ON, SC_EINVAL, and StreamingBufferRegion_::stream_offset.

◆ StreamingBufferRegisterTests()

void StreamingBufferRegisterTests ( void  )

Definition at line 2417 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 
)

get the data for one SBB

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

Referenced by UTHCheckDataAtPosition().

Here is the caller graph for this function:

◆ StreamingBufferSBBGetDataAtOffset()

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 1701 of file util-streaming-buffer.c.

References DEBUG_VALIDATE_BUG_ON, StreamingBufferBlock::len, offset, and StreamingBufferBlock::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 1775 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 
)

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

Referenced by StreamingBufferSegmentCompareRawData(), StreamTcpInlineSegmentCompare(), StreamTcpSegmentForEach(), and StreamTcpSegmentForSession().

Here is the caller graph for this function:

◆ StreamingBufferSegmentIsBeforeWindow()

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

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

References StreamingBuffer_::region, and StreamingBufferRegion_::stream_offset.

Referenced by HtpBodyPrune().

Here is the caller graph for this function:

◆ StreamingBufferSlideToOffset()

void StreamingBufferSlideToOffset ( StreamingBuffer sb,
const StreamingBufferConfig cfg,
uint64_t  offset 
)

slide to absolute offset

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

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

References offset, and SCLogDebug.

Referenced by HtpBodyPrune().

Here is the caller graph for this function: