htp: simplify streaming buffer config

Use a single static config instead of the per profile config.
pull/8426/head
Victor Julien 3 years ago
parent c79c0ca347
commit d0f1507c83

@ -33,8 +33,7 @@
#include "util-streaming-buffer.h"
#include "util-print.h"
static StreamingBufferConfig default_cfg = { 3072, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT,
HTPCalloc, HTPRealloc, HTPFree };
extern StreamingBufferConfig htp_sbcfg;
/**
* \brief Append a chunk of body to the HtpBody struct
@ -58,8 +57,7 @@ int HtpBodyAppendChunk(const HTPCfgDir *hcfg, HtpBody *body,
}
if (body->sb == NULL) {
const StreamingBufferConfig *cfg = hcfg ? &hcfg->sbcfg : &default_cfg;
body->sb = StreamingBufferInit(cfg);
body->sb = StreamingBufferInit(&htp_sbcfg);
if (body->sb == NULL)
SCReturnInt(-1);
}
@ -70,7 +68,7 @@ int HtpBodyAppendChunk(const HTPCfgDir *hcfg, HtpBody *body,
SCReturnInt(-1);
}
if (StreamingBufferAppend(body->sb, &hcfg->sbcfg, &bd->sbseg, data, len) != 0) {
if (StreamingBufferAppend(body->sb, &htp_sbcfg, &bd->sbseg, data, len) != 0) {
HTPFree(bd, sizeof(HtpBodyChunk));
SCReturnInt(-1);
}
@ -138,7 +136,7 @@ void HtpBodyFree(const HTPCfgDir *hcfg, HtpBody *body)
}
body->first = body->last = NULL;
StreamingBufferFree(body->sb, &hcfg->sbcfg);
StreamingBufferFree(body->sb, &htp_sbcfg);
}
/**
@ -187,7 +185,7 @@ void HtpBodyPrune(HtpState *state, HtpBody *body, int direction)
if (left_edge) {
SCLogDebug("sliding body to offset %"PRIu64, left_edge);
StreamingBufferSlideToOffset(body->sb, &cfg->sbcfg, left_edge);
StreamingBufferSlideToOffset(body->sb, &htp_sbcfg, left_edge);
}
SCLogDebug("pruning chunks of body %p", body);

@ -29,6 +29,8 @@
#include "app-layer-htp-range.h"
#include "util-validate.h"
extern StreamingBufferConfig htp_sbcfg;
/**
* \brief Open the file with "filename" and pass the first chunk
* of data if any.
@ -50,27 +52,22 @@ int HTPFileOpen(HtpState *s, HtpTxUserData *tx, const uint8_t *filename, uint16_
int retval = 0;
uint16_t flags = 0;
FileContainer *files = NULL;
const StreamingBufferConfig *sbcfg = NULL;
SCLogDebug("data %p data_len %"PRIu32, data, data_len);
if (direction & STREAM_TOCLIENT) {
files = &tx->files_tc;
flags = FileFlowFlagsToFlags(tx->tx_data.file_flags, STREAM_TOCLIENT);
sbcfg = &s->cfg->response.sbcfg;
// we shall not open a new file if there is a current one
DEBUG_VALIDATE_BUG_ON(tx->file_range != NULL);
} else {
files = &tx->files_ts;
flags = FileFlowFlagsToFlags(tx->tx_data.file_flags, STREAM_TOSERVER);
sbcfg = &s->cfg->request.sbcfg;
}
if (FileOpenFileWithId(files, sbcfg, s->file_track_id++,
filename, filename_len,
data, data_len, flags) != 0)
{
if (FileOpenFileWithId(files, &htp_sbcfg, s->file_track_id++, filename, filename_len, data,
data_len, flags) != 0) {
retval = -1;
}
@ -159,8 +156,8 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena
FileContainer *files = &txud->files_tc;
// we open a file for this specific range
if (FileOpenFileWithId(files, &s->cfg->response.sbcfg, s->file_track_id++, filename,
filename_len, data, data_len, flags) != 0) {
if (FileOpenFileWithId(files, &htp_sbcfg, s->file_track_id++, filename, filename_len, data,
data_len, flags) != 0) {
SCReturnInt(-1);
}
txud->tx_data.files_opened++;
@ -189,8 +186,8 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena
SCReturnInt(0);
}
DEBUG_VALIDATE_BUG_ON(htud->file_range);
htud->file_range = HttpRangeContainerOpenFile(keyurl, keylen, s->f, &crparsed,
&s->cfg->response.sbcfg, filename, filename_len, flags, data, data_len);
htud->file_range = HttpRangeContainerOpenFile(keyurl, keylen, s->f, &crparsed, &htp_sbcfg,
filename, filename_len, flags, data, data_len);
SCFree(keyurl);
if (htud->file_range == NULL) {
SCReturnInt(-1);
@ -219,14 +216,11 @@ int HTPFileStoreChunk(
int retval = 0;
int result = 0;
FileContainer *files = NULL;
const StreamingBufferConfig *sbcfg = NULL;
if (direction & STREAM_TOCLIENT) {
files = &tx->files_tc;
sbcfg = &s->cfg->response.sbcfg;
} else {
files = &tx->files_ts;
sbcfg = &s->cfg->request.sbcfg;
}
SCLogDebug("files %p data %p data_len %" PRIu32, files, data, data_len);
@ -237,12 +231,12 @@ int HTPFileStoreChunk(
}
if (tx->file_range != NULL) {
if (HttpRangeAppendData(sbcfg, tx->file_range, data, data_len) < 0) {
if (HttpRangeAppendData(&htp_sbcfg, tx->file_range, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
}
result = FileAppendData(files, sbcfg, data, data_len);
result = FileAppendData(files, &htp_sbcfg, data, data_len);
if (result == -1) {
SCLogDebug("appending data failed");
retval = -1;
@ -311,14 +305,11 @@ int HTPFileClose(HtpState *s, HtpTxUserData *tx, const uint8_t *data, uint32_t d
int retval = 0;
int result = 0;
FileContainer *files = NULL;
const StreamingBufferConfig *sbcfg = NULL;
if (direction & STREAM_TOCLIENT) {
files = &tx->files_tc;
sbcfg = &s->cfg->response.sbcfg;
} else {
files = &tx->files_ts;
sbcfg = &s->cfg->request.sbcfg;
}
SCLogDebug("files %p data %p data_len %" PRIu32, files, data, data_len);
@ -328,7 +319,7 @@ int HTPFileClose(HtpState *s, HtpTxUserData *tx, const uint8_t *data, uint32_t d
goto end;
}
result = FileCloseFile(files, sbcfg, data, data_len, flags);
result = FileCloseFile(files, &htp_sbcfg, data, data_len, flags);
if (result == -1) {
retval = -1;
} else if (result == -2) {
@ -337,7 +328,8 @@ int HTPFileClose(HtpState *s, HtpTxUserData *tx, const uint8_t *data, uint32_t d
SCLogDebug("result %u", result);
if (tx->file_range != NULL) {
bool added = HTPFileCloseHandleRange(sbcfg, files, flags, tx->file_range, data, data_len);
bool added =
HTPFileCloseHandleRange(&htp_sbcfg, files, flags, tx->file_range, data, data_len);
if (added) {
tx->tx_data.files_opened++;
}

@ -93,6 +93,8 @@ static SCRadixTree *cfgtree;
/** List of HTP configurations. */
static HTPCfgRec cfglist;
StreamingBufferConfig htp_sbcfg = STREAMING_BUFFER_CONFIG_INITIALIZER;
/** Limit to the number of libhtp messages that can be handled */
#define HTP_MAX_MESSAGES 512
@ -369,12 +371,11 @@ static void HtpTxUserDataFree(HtpState *state, HtpTxUserData *htud)
DetectEngineStateFree(htud->tx_data.de_state);
}
if (htud->file_range) {
HTPFileCloseHandleRange(
&state->cfg->response.sbcfg, &htud->files_tc, 0, htud->file_range, NULL, 0);
HTPFileCloseHandleRange(&htp_sbcfg, &htud->files_tc, 0, htud->file_range, NULL, 0);
HttpRangeFreeBlock(htud->file_range);
}
FileContainerRecycle(&htud->files_ts, &state->cfg->request.sbcfg);
FileContainerRecycle(&htud->files_tc, &state->cfg->response.sbcfg);
FileContainerRecycle(&htud->files_ts, &htp_sbcfg);
FileContainerRecycle(&htud->files_tc, &htp_sbcfg);
HTPFree(htud, sizeof(HtpTxUserData));
}
}
@ -2552,18 +2553,6 @@ static void HTPConfigSetDefaultsPhase2(const char *name, HTPCfgRec *cfg_prec)
}
htp_config_register_request_line(cfg_prec->cfg, HTPCallbackRequestLine);
cfg_prec->request.sbcfg.buf_size =
cfg_prec->request.inspect_window ? cfg_prec->request.inspect_window : 256;
cfg_prec->request.sbcfg.Calloc = HTPCalloc;
cfg_prec->request.sbcfg.Realloc = HTPRealloc;
cfg_prec->request.sbcfg.Free = HTPFree;
cfg_prec->response.sbcfg.buf_size =
cfg_prec->response.inspect_window ? cfg_prec->response.inspect_window : 256;
cfg_prec->response.sbcfg.Calloc = HTPCalloc;
cfg_prec->response.sbcfg.Realloc = HTPRealloc;
cfg_prec->response.sbcfg.Free = HTPFree;
return;
}
@ -2943,6 +2932,10 @@ void HTPConfigure(void)
cfglist.next = NULL;
htp_sbcfg.Calloc = HTPCalloc;
htp_sbcfg.Realloc = HTPRealloc;
htp_sbcfg.Free = HTPFree;
cfgtree = SCRadixCreateRadixTree(NULL, NULL);
if (NULL == cfgtree)
exit(EXIT_FAILURE);
@ -3026,17 +3019,14 @@ void AppLayerHtpPrintStats(void)
*/
static AppLayerGetFileState HTPGetTxFiles(void *state, void *txv, uint8_t direction)
{
AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
HtpState *s = state;
AppLayerGetFileState files = { .fc = NULL, .cfg = &htp_sbcfg };
htp_tx_t *tx = (htp_tx_t *)txv;
HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
if (tx_ud) {
if (direction & STREAM_TOCLIENT) {
files.fc = &tx_ud->files_tc;
files.cfg = &s->cfg->response.sbcfg;
} else {
files.fc = &tx_ud->files_ts;
files.cfg = &s->cfg->request.sbcfg;
}
}
return files;

@ -149,7 +149,6 @@ typedef struct HTPCfgDir_ {
uint32_t body_limit;
uint32_t inspect_min_size;
uint32_t inspect_window;
StreamingBufferConfig sbcfg;
} HTPCfgDir;
/** Need a linked list in order to keep track of these */

Loading…
Cancel
Save