Skip to content

Commit 81572cb

Browse files
catenacybervictorjulien
authored andcommitted
detect: simplify code for http.header
reuse generic DetectEngineInspectBufferGeneric
1 parent cd0e428 commit 81572cb

1 file changed

Lines changed: 9 additions & 49 deletions

File tree

src/detect-http-header.c

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -162,59 +162,19 @@ static InspectionBuffer *GetBuffer2ForTX(DetectEngineThreadCtx *det_ctx,
162162
return buffer;
163163
}
164164

165-
/** \internal
166-
* \brief custom inspect function to utilize the cached headers
167-
*/
168-
static uint8_t DetectEngineInspectBufferHttpHeader(DetectEngineCtx *de_ctx,
169-
DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine,
170-
const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
165+
static InspectionBuffer *GetData1(DetectEngineThreadCtx *det_ctx,
166+
const DetectEngineTransforms *transforms, Flow *_f, const uint8_t flags, void *txv,
167+
const int list_id)
171168
{
172-
SCEnter();
173-
174-
const int list_id = engine->sm_list;
175169
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
176-
bool eof =
177-
(AppLayerParserGetStateProgress(f->proto, f->alproto, txv, flags) > engine->progress);
178170
if (buffer->inspect == NULL) {
179-
SCLogDebug("setting up inspect buffer %d", list_id);
180-
181-
/* if prefilter didn't already run, we need to consider transformations */
182-
const DetectEngineTransforms *transforms = NULL;
183-
if (!engine->mpm) {
184-
transforms = engine->v2.transforms;
185-
}
186-
187-
uint32_t rawdata_len = 0;
188-
uint8_t *rawdata = GetBufferForTX(txv, det_ctx, flags, &rawdata_len);
189-
if (rawdata_len == 0) {
190-
SCLogDebug("no data");
191-
if (engine->match_on_null && eof) {
192-
return DETECT_ENGINE_INSPECT_SIG_MATCH;
193-
}
194-
goto end;
195-
}
196-
/* setup buffer and apply transforms */
171+
uint32_t data_len = 0;
172+
uint8_t *data = GetBufferForTX(txv, det_ctx, flags, &data_len);
197173
InspectionBufferSetupAndApplyTransforms(
198-
det_ctx, list_id, buffer, rawdata, rawdata_len, transforms);
174+
det_ctx, list_id, buffer, data, data_len, transforms);
199175
}
200176

201-
const uint32_t data_len = buffer->inspect_len;
202-
const uint8_t *data = buffer->inspect;
203-
const uint64_t offset = buffer->inspect_offset;
204-
205-
/* Inspect all the uricontents fetched on each
206-
* transaction at the app layer */
207-
const bool match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
208-
(uint8_t *)data, data_len, offset, DETECT_CI_FLAGS_SINGLE,
209-
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
210-
if (match) {
211-
return DETECT_ENGINE_INSPECT_SIG_MATCH;
212-
}
213-
end:
214-
if (eof) {
215-
return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH;
216-
}
217-
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
177+
return buffer;
218178
}
219179

220180
typedef struct PrefilterMpmHttpHeaderCtx {
@@ -424,13 +384,13 @@ void DetectHttpHeaderRegister(void)
424384
sigmatch_table[DETECT_HTTP_HEADER].flags |= SIGMATCH_INFO_STICKY_BUFFER;
425385

426386
DetectAppLayerInspectEngineRegister("http_header", ALPROTO_HTTP1, SIG_FLAG_TOSERVER,
427-
HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferHttpHeader, NULL);
387+
HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
428388
DetectAppLayerMpmRegister("http_header", SIG_FLAG_TOSERVER, 2,
429389
PrefilterMpmHttpHeaderRequestRegister, NULL, ALPROTO_HTTP1,
430390
0); /* not used, registered twice: HEADERS/TRAILER */
431391

432392
DetectAppLayerInspectEngineRegister("http_header", ALPROTO_HTTP1, SIG_FLAG_TOCLIENT,
433-
HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferHttpHeader, NULL);
393+
HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
434394
DetectAppLayerMpmRegister("http_header", SIG_FLAG_TOCLIENT, 2,
435395
PrefilterMpmHttpHeaderResponseRegister, NULL, ALPROTO_HTTP1,
436396
0); /* not used, registered twice: HEADERS/TRAILER */

0 commit comments

Comments
 (0)