suricata
detect-engine-frame.c
Go to the documentation of this file.
1 /* Copyright (C) 2021-2023 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  */
24 
25 #include "suricata-common.h"
26 #include "suricata.h"
27 
28 #include "app-layer-parser.h"
29 #include "rust.h"
30 #include "app-layer-frames.h"
31 
32 #include "detect-engine.h"
35 #include "detect-engine-mpm.h"
36 #include "detect-engine-frame.h"
37 
38 #include "stream-tcp.h"
39 
40 #include "util-profiling.h"
41 #include "util-validate.h"
42 #include "util-print.h"
43 
45  // shared between prefilter and inspect
48  const Frame *frame;
49  int list_id;
50  uint32_t idx; /**< multi buffer idx, incremented for each stream chunk */
51 
52  // inspection only
54  const Signature *s;
55  int inspect_result; // DETECT_ENGINE_INSPECT_SIG_MATCH / DETECT_ENGINE_INSPECT_SIG_NO_MATCH
57 
58  // prefilter only
59  const MpmCtx *mpm_ctx;
60 
62 };
63 
64 static bool SetupStreamCallbackData(struct FrameStreamData *dst, const TcpSession *ssn,
65  const TcpStream *stream, DetectEngineThreadCtx *det_ctx,
66  const DetectEngineTransforms *transforms, const Frames *_frames, const Frame *frame,
67  const int list_id, const bool eof);
68 
69 static bool BufferSetup(struct FrameStreamData *fsd, InspectionBuffer *buffer, const uint8_t *input,
70  const uint32_t input_len, const uint64_t input_offset);
71 static void BufferSetupUdp(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer,
72  const Frame *frame, const Packet *p, const DetectEngineTransforms *transforms);
73 
75  const Frames *frames, const Frame *frame, const AppProto alproto)
76 {
77  SCLogDebug("pcap_cnt %" PRIu64, p->pcap_cnt);
78  PrefilterEngine *engine = sgh->frame_engines;
79  do {
80  if ((engine->alproto == alproto || engine->alproto == ALPROTO_UNKNOWN) &&
81  (engine->ctx.frame_type == frame->type ||
82  engine->ctx.frame_type == FRAME_ANY_TYPE)) {
83  SCLogDebug("frame %p engine %p", frame, engine);
85  engine->cb.PrefilterFrame(det_ctx, engine->pectx, p, frames, frame);
86  PREFILTER_PROFILING_END(det_ctx, engine->gid);
87  }
88  if (engine->is_last)
89  break;
90  engine++;
91  } while (1);
92 }
93 
94 /* generic mpm for frame engines */
95 
96 // TODO same as Generic?
97 typedef struct PrefilterMpmFrameCtx {
98  int list_id;
99  const MpmCtx *mpm_ctx;
102 
103 static int FrameStreamDataPrefilterFunc(
104  void *cb_data, const uint8_t *input, const uint32_t input_len, const uint64_t input_offset)
105 {
106  struct FrameStreamData *fsd = cb_data;
107  SCLogDebug("prefilter: fsd %p { det_ctx:%p, transforms:%p, frame:%p, list_id:%d, idx:%u, "
108  "data_offset:%" PRIu64 "}, input: %p, input_len:%u, input_offset:%" PRIu64,
109  fsd, fsd->det_ctx, fsd->transforms, fsd->frame, fsd->list_id, fsd->idx,
110  fsd->requested_stream_offset, input, input_len, input_offset);
111  // PrintRawDataFp(stdout, input, input_len);
112 
113  InspectionBuffer *buffer =
115  if (buffer == NULL) {
116  return 0;
117  }
118  SCLogDebug("buffer %p idx %u", buffer, fsd->idx);
119 
120  const int more_chunks = BufferSetup(fsd, buffer, input, input_len, input_offset);
121 
122  const uint32_t data_len = buffer->inspect_len;
123  const uint8_t *data = buffer->inspect;
125  const MpmCtx *mpm_ctx = fsd->mpm_ctx;
126 
127  if (data != NULL && data_len >= mpm_ctx->minlen) {
128  // PrintRawDataFp(stdout, data, data_len);
129 
131  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
132  SCLogDebug("det_ctx->pmq.rule_id_array_cnt %u", det_ctx->pmq.rule_id_array_cnt);
134  }
135  return more_chunks;
136 }
137 
138 /** \brief Generic Mpm prefilter callback
139  *
140  * \param det_ctx detection engine thread ctx
141  * \param frames container for the frames
142  * \param frame frame to inspect
143  * \param pectx inspection context
144  */
145 static void PrefilterMpmFrame(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
146  const Frames *frames, const Frame *frame)
147 {
148  SCEnter();
149 
150  const PrefilterMpmFrameCtx *ctx = (const PrefilterMpmFrameCtx *)pectx;
151  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
152 
153  SCLogDebug("packet:%" PRIu64 ", prefilter running on list %d -> frame field type %u",
154  p->pcap_cnt, ctx->list_id, frame->type);
155  if (p->proto == IPPROTO_UDP) {
156  // TODO can we use single here? Could it conflict with TCP?
158  if (buffer == NULL)
159  return;
161  if (frame->offset >= p->payload_len)
162  return;
163 
164  BufferSetupUdp(det_ctx, buffer, frame, p, ctx->transforms);
165  const uint32_t data_len = buffer->inspect_len;
166  const uint8_t *data = buffer->inspect;
167 
168  // PrintRawDataFp(stdout, data, data_len);
169 
170  if (data != NULL && data_len >= mpm_ctx->minlen) {
172  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
173  SCLogDebug("det_ctx->pmq.rule_id_array_cnt %u", det_ctx->pmq.rule_id_array_cnt);
175  }
176  } else if (p->proto == IPPROTO_TCP) {
178  TcpSession *ssn = p->flow->protoctx;
179  TcpStream *stream;
180  if (PKT_IS_TOSERVER(p)) {
181  stream = &ssn->client;
182  } else {
183  stream = &ssn->server;
184  }
185  const bool eof = ssn->state == TCP_CLOSED || PKT_IS_PSEUDOPKT(p);
186 
187  struct FrameStreamData fsd;
188  memset(&fsd, 0, sizeof(fsd));
189  fsd.mpm_ctx = mpm_ctx;
190 
191  if (SetupStreamCallbackData(&fsd, ssn, stream, det_ctx, ctx->transforms, frames, frame,
192  ctx->list_id, eof)) {
193  StreamReassembleForFrame(ssn, stream, FrameStreamDataPrefilterFunc, &fsd,
194  fsd.requested_stream_offset, eof);
195  }
196  } else {
198  }
199  SCLogDebug("packet:%" PRIu64
200  ", prefilter done running on list %d -> frame field type %u; have %u matches",
202 }
203 
204 static void PrefilterMpmFrameFree(void *ptr)
205 {
206  SCFree(ptr);
207 }
208 
210  const DetectBufferMpmRegistry *mpm_reg, int list_id)
211 {
212  SCEnter();
213  PrefilterMpmFrameCtx *pectx = SCCalloc(1, sizeof(*pectx));
214  if (pectx == NULL)
215  return -1;
216  pectx->list_id = list_id;
217  BUG_ON(mpm_reg->frame_v1.alproto == ALPROTO_UNKNOWN);
218  pectx->mpm_ctx = mpm_ctx;
219  pectx->transforms = &mpm_reg->transforms;
220 
221  int r = PrefilterAppendFrameEngine(de_ctx, sgh, PrefilterMpmFrame, mpm_reg->frame_v1.alproto,
222  mpm_reg->frame_v1.type, pectx, PrefilterMpmFrameFree, mpm_reg->pname);
223  if (r != 0) {
224  SCFree(pectx);
225  }
226  return r;
227 }
228 
230  Flow *f, Packet *p, const Frames *frames, const Frame *frame)
231 {
233 
234  SCLogDebug("inspecting rule %u against frame %p/%" PRIi64 "/%s", s->id, frame, frame->id,
236 
237  for (DetectEngineFrameInspectionEngine *e = s->frame_inspect; e != NULL; e = e->next) {
238  if (frame->type == e->type) {
239  // TODO check alproto, direction?
240 
241  // TODO there should be only one inspect engine for this frame, ever?
242 
243  if (e->v1.Callback(det_ctx, e, s, p, frames, frame)) {
244  SCLogDebug("sid %u: e %p Callback returned true", s->id, e);
245  return true;
246  }
247  SCLogDebug("sid %u: e %p Callback returned false", s->id, e);
248  } else {
249  SCLogDebug(
250  "sid %u: e %p not for frame type %u (want %u)", s->id, e, frame->type, e->type);
251  }
252  }
253  return false;
254 }
255 
256 static void BufferSetupUdp(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer,
257  const Frame *frame, const Packet *p, const DetectEngineTransforms *transforms)
258 {
259  uint8_t ci_flags = DETECT_CI_FLAGS_START;
260  uint32_t frame_len;
261  if (frame->len == -1) {
262  frame_len = (uint32_t)(p->payload_len - frame->offset);
263  } else {
264  frame_len = (uint32_t)frame->len;
265  }
266  if (frame->offset + frame_len > p->payload_len) {
267  frame_len = (uint32_t)(p->payload_len - frame->offset);
268  } else {
269  ci_flags |= DETECT_CI_FLAGS_END;
270  }
271  const uint8_t *data = p->payload + frame->offset;
272  const uint32_t data_len = frame_len;
273 
274  SCLogDebug("packet %" PRIu64 " -> frame %p/%" PRIi64 "/%s offset %" PRIu64
275  " type %u len %" PRIi64,
276  p->pcap_cnt, frame, frame->id,
278  frame->offset, frame->type, frame->len);
279 
280  InspectionBufferSetupMulti(det_ctx, buffer, transforms, data, data_len);
281  buffer->inspect_offset = 0;
282  buffer->flags = ci_flags;
283 }
284 
285 /** \internal
286  * \brief setup buffer based on frame in UDP payload
287  */
288 static int DetectFrameInspectUdp(DetectEngineThreadCtx *det_ctx,
289  const DetectEngineFrameInspectionEngine *engine, const Signature *s,
290  const DetectEngineTransforms *transforms, Packet *p, const Frames *_frames,
291  const Frame *frame, const int list_id)
292 {
293  SCLogDebug("packet:%" PRIu64 ", inspect: s:%p s->id:%u, transforms:%p", p->pcap_cnt, s, s->id,
294  transforms);
295 
296  // TODO can we use single here? Could it conflict with TCP?
298  if (buffer == NULL)
300 
302  if (frame->offset >= p->payload_len)
304 
305  if (!buffer->initialized)
306  BufferSetupUdp(det_ctx, buffer, frame, p, transforms);
308  if (buffer->inspect == NULL)
310 
311  const bool match = DetectEngineContentInspection(det_ctx->de_ctx, det_ctx, s, engine->smd, p,
312  p->flow, buffer->inspect, buffer->inspect_len, 0, buffer->flags,
314  if (match) {
315  SCLogDebug("match!");
317  } else {
319  }
320 }
321 
322 /**
323  * \retval bool true if callback should run again */
324 static bool BufferSetup(struct FrameStreamData *fsd, InspectionBuffer *buffer, const uint8_t *input,
325  const uint32_t input_len, const uint64_t input_offset)
326 {
327  const Frame *frame = fsd->frame;
328  /* so: relative to start of stream */
329  const uint64_t so_input_re = input_offset + input_len;
330  const uint64_t so_frame_re =
331  frame->offset + (uint64_t)frame->len; // TODO if eof, set to available data?
332  SCLogDebug("frame offset:%" PRIu64, frame->offset);
333  const uint8_t *data = input;
334  uint8_t ci_flags = 0;
335  uint32_t data_len;
336 
337  /* fo: frame offset; offset relative to start of the frame */
338  uint64_t fo_inspect_offset = 0;
339 
340  if (frame->offset == 0 && input_offset == 0) {
341  ci_flags |= DETECT_CI_FLAGS_START;
342  SCLogDebug("have frame data start");
343 
344  if (frame->len >= 0) {
345  data_len = MIN(input_len, (uint32_t)frame->len);
346  if (data_len == frame->len) {
347  ci_flags |= DETECT_CI_FLAGS_END;
348  SCLogDebug("have frame data end");
349  }
350  } else {
351  data_len = input_len;
352  }
353  } else {
354  const uint64_t so_frame_inspect_offset = frame->inspect_progress + frame->offset;
355  const uint64_t so_inspect_offset = MAX(input_offset, so_frame_inspect_offset);
356  fo_inspect_offset = so_inspect_offset - frame->offset;
357 
358  if (frame->offset >= input_offset) {
359  ci_flags |= DETECT_CI_FLAGS_START;
360  SCLogDebug("have frame data start");
361  }
362  if (frame->len >= 0) {
363  if (fo_inspect_offset >= (uint64_t)frame->len) {
364  SCLogDebug("data entirely past frame (%" PRIu64 " > %" PRIi64 ")",
365  fo_inspect_offset, frame->len);
367  return false;
368  }
369 
370  /* in: relative to start of input data */
371  DEBUG_VALIDATE_BUG_ON(so_inspect_offset < input_offset);
372  DEBUG_VALIDATE_BUG_ON(so_inspect_offset - input_offset > UINT32_MAX);
373  const uint32_t in_data_offset = (uint32_t)(so_inspect_offset - input_offset);
374  data += in_data_offset;
375 
376  uint32_t in_data_excess = 0;
377  if (so_input_re >= so_frame_re) {
378  ci_flags |= DETECT_CI_FLAGS_END;
379  SCLogDebug("have frame data end");
380  DEBUG_VALIDATE_BUG_ON(so_input_re - so_frame_re > UINT32_MAX);
381  in_data_excess = (uint32_t)(so_input_re - so_frame_re);
382  }
383  data_len = input_len - in_data_offset - in_data_excess;
384  } else {
385  /* in: relative to start of input data */
386  DEBUG_VALIDATE_BUG_ON(so_inspect_offset < input_offset);
387  DEBUG_VALIDATE_BUG_ON(so_inspect_offset - input_offset > UINT32_MAX);
388  const uint32_t in_data_offset = (uint32_t)(so_inspect_offset - input_offset);
389  data += in_data_offset;
390  data_len = input_len - in_data_offset;
391  }
392  }
393  // PrintRawDataFp(stdout, data, data_len);
394  SCLogDebug("fsd->transforms %p", fsd->transforms);
395  InspectionBufferSetupMulti(fsd->det_ctx, buffer, fsd->transforms, data, data_len);
396  SCLogDebug("inspect_offset %" PRIu64, fo_inspect_offset);
397  buffer->inspect_offset = fo_inspect_offset;
398  buffer->flags = ci_flags;
399 
400  if (frame->len >= 0 && so_input_re >= so_frame_re) {
401  SCLogDebug("have the full frame, we can set progress accordingly (%" PRIu64 " > %" PRIu64
402  ")",
403  so_input_re, so_frame_re);
405  MAX(fo_inspect_offset + data_len, fsd->det_ctx->frame_inspect_progress);
406  } else {
408  MAX(fo_inspect_offset + data_len, fsd->det_ctx->frame_inspect_progress);
409  /* in IPS mode keep a sliding window */
410  const bool ips = StreamTcpInlineMode();
411  if (ips) {
412  if (fsd->det_ctx->frame_inspect_progress < 2500)
414  else
415  fsd->det_ctx->frame_inspect_progress -= 2500;
416  }
417  SCLogDebug("ips %s inspect_progress %" PRIu64, BOOL2STR(ips),
419  }
420 
421  /* keep going as long as there is possibly still data for this frame */
422  const bool ret = (frame->len >= 0 && so_input_re >= so_frame_re);
423  SCLogDebug("buffer set up, more to do: %s", BOOL2STR(ret));
424  return ret;
425 }
426 
427 static int FrameStreamDataInspectFunc(
428  void *cb_data, const uint8_t *input, const uint32_t input_len, const uint64_t input_offset)
429 {
430  struct FrameStreamData *fsd = cb_data;
431  SCLogDebug("inspect: fsd %p { det_ctx:%p, transforms:%p, s:%p, s->id:%u, frame:%p, list_id:%d, "
432  "idx:%u, "
433  "requested_stream_offset:%" PRIu64
434  "}, input: %p, input_len:%u, input_offset:%" PRIu64,
435  fsd, fsd->det_ctx, fsd->transforms, fsd->s, fsd->s->id, fsd->frame, fsd->list_id,
436  fsd->idx, fsd->requested_stream_offset, input, input_len, input_offset);
437  // PrintRawDataFp(stdout, input, input_len);
438 
439  InspectionBuffer *buffer =
441  if (buffer == NULL) {
442  return 0;
443  }
444  SCLogDebug("buffer %p idx %u", buffer, fsd->idx);
445 
446  /* if we've not done so already, set up the buffer */
447  int more_chunks = 1;
448  if (!buffer->initialized) {
449  more_chunks = BufferSetup(fsd, buffer, input, input_len, input_offset);
450  }
452  if (buffer->inspect == NULL) {
453  return more_chunks;
454  }
455 
456  const uint32_t data_len = buffer->inspect_len;
457  const uint8_t *data = buffer->inspect;
458  const uint64_t data_offset = buffer->inspect_offset;
460 
462  const Signature *s = fsd->s;
463  Packet *p = fsd->p;
464 
465 #ifdef DEBUG
466  const uint8_t ci_flags = buffer->flags;
467  SCLogDebug("frame %p offset %" PRIu64 " type %u len %" PRIi64
468  " ci_flags %02x (start:%s, end:%s)",
469  fsd->frame, fsd->frame->offset, fsd->frame->type, fsd->frame->len, ci_flags,
470  (ci_flags & DETECT_CI_FLAGS_START) ? "true" : "false",
471  (ci_flags & DETECT_CI_FLAGS_END) ? "true" : "false");
472  SCLogDebug("buffer %p offset %" PRIu64 " len %u ci_flags %02x (start:%s, end:%s)", buffer,
473  buffer->inspect_offset, buffer->inspect_len, ci_flags,
474  (ci_flags & DETECT_CI_FLAGS_START) ? "true" : "false",
475  (ci_flags & DETECT_CI_FLAGS_END) ? "true" : "false");
476  // PrintRawDataFp(stdout, data, data_len);
477  // PrintRawDataFp(stdout, data, MIN(64, data_len));
478 #endif
479  DEBUG_VALIDATE_BUG_ON(fsd->frame->len > 0 && (int64_t)data_len > fsd->frame->len);
480 
481  const bool match = DetectEngineContentInspection(det_ctx->de_ctx, det_ctx, s, engine->smd, p,
482  p->flow, data, data_len, data_offset, buffer->flags,
484  if (match) {
485  SCLogDebug("DETECT_ENGINE_INSPECT_SIG_MATCH");
487  } else {
488  SCLogDebug("DETECT_ENGINE_INSPECT_SIG_NO_MATCH");
489  }
490  return more_chunks;
491 }
492 
493 static bool SetupStreamCallbackData(struct FrameStreamData *dst, const TcpSession *ssn,
494  const TcpStream *stream, DetectEngineThreadCtx *det_ctx,
495  const DetectEngineTransforms *transforms, const Frames *_frames, const Frame *frame,
496  const int list_id, const bool eof)
497 {
498  SCLogDebug("frame %" PRIi64 ", len %" PRIi64 ", offset %" PRIu64 ", inspect_progress %" PRIu64,
500 
501  const uint64_t frame_offset = frame->offset;
502  const uint64_t usable = StreamDataRightEdge(stream, eof);
503  if (usable <= frame_offset)
504  return false;
505 
506  uint64_t want = frame->inspect_progress;
507  if (frame->len == -1) {
508  if (eof) {
509  want = usable;
510  } else {
511  want += 2500;
512  }
513  } else {
514  /* don't have the full frame yet */
515  if (frame->offset + frame->len > usable) {
516  want += 2500;
517  } else {
518  want = frame->offset + frame->len;
519  }
520  }
521 
522  const bool ips = StreamTcpInlineMode();
523 
524  const uint64_t have = usable;
525  if (!ips && have < want) {
526  SCLogDebug("wanted %" PRIu64 " bytes, got %" PRIu64, want, have);
527  return false;
528  }
529 
530  const uint64_t available_data = usable - STREAM_BASE_OFFSET(stream);
531  SCLogDebug("check inspection for having 2500 bytes: %" PRIu64, available_data);
532  if (!ips && !eof && available_data < 2500 &&
533  (frame->len < 0 || frame->len > (int64_t)available_data)) {
534  SCLogDebug("skip inspection until we have 2500 bytes (have %" PRIu64 ")", available_data);
535  return false;
536  }
537 
538  const uint64_t offset =
540 
541  dst->det_ctx = det_ctx;
542  dst->transforms = transforms;
543  dst->frame = frame;
544  dst->list_id = list_id;
545  dst->requested_stream_offset = offset;
546  return true;
547 }
548 
549 /**
550  * \brief Do the content inspection & validation for a signature
551  *
552  * \param de_ctx Detection engine context
553  * \param det_ctx Detection engine thread context
554  * \param s Signature to inspect
555  * \param p Packet
556  * \param frame stream frame to inspect
557  *
558  * \retval 0 no match.
559  * \retval 1 match.
560  */
562  const DetectEngineFrameInspectionEngine *engine, const Signature *s, Packet *p,
563  const Frames *frames, const Frame *frame)
564 {
565  /* if prefilter didn't already run, we need to consider transformations */
566  const DetectEngineTransforms *transforms = NULL;
567  if (!engine->mpm) {
568  transforms = engine->v1.transforms;
569  }
570  const int list_id = engine->sm_list;
571  SCLogDebug("running inspect on %d", list_id);
572 
573  if (p->proto == IPPROTO_UDP) {
574  return DetectFrameInspectUdp(det_ctx, engine, s, transforms, p, frames, frame, list_id);
575  }
576  DEBUG_VALIDATE_BUG_ON(p->proto != IPPROTO_TCP);
577 
578  SCLogDebug("packet:%" PRIu64 ", frame->id:%" PRIu64
579  ", list:%d, transforms:%p, s:%p, s->id:%u, engine:%p",
580  p->pcap_cnt, frame->id, engine->sm_list, engine->v1.transforms, s, s->id, engine);
581 
583  TcpSession *ssn = p->flow->protoctx;
584  TcpStream *stream;
585  if (PKT_IS_TOSERVER(p)) {
586  stream = &ssn->client;
587  } else {
588  stream = &ssn->server;
589  }
590  const bool eof = ssn->state == TCP_CLOSED || PKT_IS_PSEUDOPKT(p);
591 
592  struct FrameStreamData fsd;
593  memset(&fsd, 0, sizeof(fsd));
594  fsd.inspect_engine = engine;
595  fsd.s = s;
597  fsd.p = p;
598 
599  if (!SetupStreamCallbackData(
600  &fsd, ssn, stream, det_ctx, transforms, frames, frame, list_id, eof)) {
602  }
604  ssn, stream, FrameStreamDataInspectFunc, &fsd, fsd.requested_stream_offset, eof);
605 
606  return fsd.inspect_result;
607 }
PrefilterMpmFrameCtx
struct PrefilterMpmFrameCtx PrefilterMpmFrameCtx
PrefilterMpmFrameCtx::list_id
int list_id
Definition: detect-engine-frame.c:98
Packet_::proto
uint8_t proto
Definition: decode.h:523
TcpStream_
Definition: stream-tcp-private.h:106
Frame::inspect_progress
uint64_t inspect_progress
Definition: app-layer-frames.h:53
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:97
detect-engine.h
PrefilterEngine_::ctx
union PrefilterEngine_::@110 ctx
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
DETECT_CI_FLAGS_START
#define DETECT_CI_FLAGS_START
Definition: detect-engine-content-inspection.h:40
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1323
PREFILTER_PROFILING_END
#define PREFILTER_PROFILING_END(ctx, profile_id)
Definition: util-profiling.h:276
InspectionBuffer::initialized
bool initialized
Definition: detect-engine-inspect-buffer.h:38
stream-tcp.h
PrefilterRuleStore_::rule_id_array_cnt
uint32_t rule_id_array_cnt
Definition: util-prefilter.h:40
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1627
StreamTcpInlineMode
bool StreamTcpInlineMode(void)
See if stream engine is operating in inline mode.
Definition: stream-tcp.c:7221
DetectEngineTransforms
Definition: detect.h:391
FrameStreamData::requested_stream_offset
uint64_t requested_stream_offset
Definition: detect-engine-frame.c:61
FrameStreamData::frame
const Frame * frame
Definition: detect-engine-frame.c:48
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:626
Flow_::proto
uint8_t proto
Definition: flow.h:370
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
Packet_::payload
uint8_t * payload
Definition: decode.h:605
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
Frame::offset
uint64_t offset
Definition: app-layer-frames.h:49
FrameStreamData::list_id
int list_id
Definition: detect-engine-frame.c:49
Frame
Definition: app-layer-frames.h:43
Flow_
Flow data structure.
Definition: flow.h:348
PREFILTER_PROFILING_START
#define PREFILTER_PROFILING_START(det_ctx)
Definition: util-profiling.h:260
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1347
ctx
struct Thresholds ctx
DetectEngineFrameInspectionEngine::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:518
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
DetectEngineFrameInspectionEngine::mpm
bool mpm
Definition: detect.h:512
Frame::id
int64_t id
Definition: app-layer-frames.h:51
FrameStreamData::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-frame.c:59
FrameStreamData::det_ctx
DetectEngineThreadCtx * det_ctx
Definition: detect-engine-frame.c:46
PrefilterMpmFrameCtx::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-frame.c:99
rust.h
MIN
#define MIN(x, y)
Definition: suricata-common.h:408
Frames
Definition: app-layer-frames.h:58
DetectBufferMpmRegistry_
one time registration of keywords at start up
Definition: detect.h:762
InspectionBuffer::flags
uint8_t flags
Definition: detect-engine-inspect-buffer.h:39
detect-engine-frame.h
FrameStreamData::inspect_engine
const DetectEngineFrameInspectionEngine * inspect_engine
Definition: detect-engine-frame.c:53
PrefilterGenericMpmFrameRegister
int PrefilterGenericMpmFrameRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-frame.c:209
MAX
#define MAX(x, y)
Definition: suricata-common.h:412
DetectRunFrameInspectRule
bool DetectRunFrameInspectRule(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, const Frames *frames, const Frame *frame)
Definition: detect-engine-frame.c:229
Flow_::protoctx
void * protoctx
Definition: flow.h:433
PrefilterAppendFrameEngine
int PrefilterAppendFrameEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterFrameFn PrefilterFrameFunc, AppProto alproto, uint8_t frame_type, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:389
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:775
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:606
detect-engine-prefilter.h
DetectRunPrefilterFrame
void DetectRunPrefilterFrame(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const Frames *frames, const Frame *frame, const AppProto alproto)
Definition: detect-engine-frame.c:74
Signature_::frame_inspect
DetectEngineFrameInspectionEngine * frame_inspect
Definition: detect.h:727
DetectEngineFrameInspectionEngine::v1
struct DetectEngineFrameInspectionEngine::@92 v1
FRAME_ANY_TYPE
#define FRAME_ANY_TYPE
Definition: app-layer-frames.h:28
PrefilterMpmFrameCtx::transforms
const DetectEngineTransforms * transforms
Definition: detect-engine-frame.c:100
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:238
AppLayerParserGetFrameNameById
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
Definition: app-layer-parser.c:1622
FrameStreamData::idx
uint32_t idx
Definition: detect-engine-frame.c:50
DetectEngineThreadCtx_
Definition: detect.h:1244
PrefilterEngine_
Definition: detect.h:1562
STREAM_BASE_OFFSET
#define STREAM_BASE_OFFSET(stream)
Definition: stream-tcp-private.h:144
BOOL2STR
#define BOOL2STR(b)
Definition: util-debug.h:539
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:281
detect-engine-mpm.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
DetectEngineFrameInspectionEngine::sm_list
uint16_t sm_list
Definition: detect.h:513
DETECT_ENGINE_INSPECT_SIG_MATCH
#define DETECT_ENGINE_INSPECT_SIG_MATCH
Definition: detect-engine-state.h:41
TcpSession_::state
uint8_t state
Definition: stream-tcp-private.h:285
FrameStreamData::transforms
const DetectEngineTransforms * transforms
Definition: detect-engine-frame.c:47
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect-engine-inspect-buffer.h:36
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:106
DetectEngineContentInspection
bool DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, const uint32_t buffer_len, const uint64_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
Definition: detect-engine-content-inspection.c:749
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
util-profiling.h
PrefilterEngine_::alproto
AppProto alproto
Definition: detect.h:1566
Packet_
Definition: decode.h:501
DETECT_CI_FLAGS_END
#define DETECT_CI_FLAGS_END
Definition: detect-engine-content-inspection.h:42
DetectEngineFrameInspectionEngine
Definition: detect.h:508
Frame::len
int64_t len
Definition: app-layer-frames.h:50
PrefilterEngine_::PrefilterFrame
PrefilterFrameFn PrefilterFrame
Definition: detect.h:1589
PrefilterEngine_::frame_type
uint8_t frame_type
Definition: detect.h:1576
PrefilterEngine_::cb
union PrefilterEngine_::@111 cb
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:180
SigGroupHead_::frame_engines
PrefilterEngine * frame_engines
Definition: detect.h:1640
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1343
detect-engine-content-inspection.h
TCP_CLOSED
@ TCP_CLOSED
Definition: stream-tcp-private.h:162
DetectBufferMpmRegistry_::frame_v1
struct DetectBufferMpmRegistry_::@96::@100 frame_v1
PrefilterMpmFrameCtx
Definition: detect-engine-frame.c:97
PREFILTER_PROFILING_ADD_BYTES
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
Definition: util-profiling.h:286
app-layer-frames.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:546
Frame::type
uint8_t type
Definition: app-layer-frames.h:44
suricata-common.h
DETECT_ENGINE_CONTENT_INSPECTION_MODE_FRAME
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_FRAME
Definition: detect-engine-content-inspection.h:35
DetectEngineFrameInspectionEngine::next
struct DetectEngineFrameInspectionEngine * next
Definition: detect.h:521
DetectEngineInspectFrameBufferGeneric
int DetectEngineInspectFrameBufferGeneric(DetectEngineThreadCtx *det_ctx, const DetectEngineFrameInspectionEngine *engine, const Signature *s, Packet *p, const Frames *frames, const Frame *frame)
Do the content inspection & validation for a signature.
Definition: detect-engine-frame.c:561
DetectEngineThreadCtx_::frame_inspect_progress
uint64_t frame_inspect_progress
Definition: detect.h:1320
FrameStreamData::inspect_result
int inspect_result
Definition: detect-engine-frame.c:55
PrefilterEngine_::gid
uint32_t gid
Definition: detect.h:1595
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:297
DETECT_ENGINE_INSPECT_SIG_NO_MATCH
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
Definition: detect-engine-state.h:40
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
util-validate.h
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect-engine-inspect-buffer.h:37
PrefilterEngine_::pectx
void * pectx
Definition: detect.h:1584
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect-engine-inspect-buffer.h:35
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Signature_::id
uint32_t id
Definition: detect.h:713
Signature_
Signature container.
Definition: detect.h:668
FrameStreamData::s
const Signature * s
Definition: detect-engine-frame.c:54
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
StreamDataRightEdge
uint64_t StreamDataRightEdge(const TcpStream *stream, const bool eof)
Definition: stream-tcp-reassemble.c:417
PrefilterEngine_::is_last
bool is_last
Definition: detect.h:1579
DetectEngineThreadCtx_::de_ctx
DetectEngineCtx * de_ctx
Definition: detect.h:1362
InspectionBufferSetupMultiEmpty
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
Definition: detect-engine-inspect-buffer.c:144
suricata.h
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
MpmCtx_
Definition: util-mpm.h:95
TcpSession_
Definition: stream-tcp-private.h:283
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:442
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
FrameStreamData::p
Packet * p
Definition: detect-engine-frame.c:56
StreamReassembleForFrame
int StreamReassembleForFrame(TcpSession *ssn, TcpStream *stream, StreamReassembleRawFunc Callback, void *cb_data, const uint64_t offset, const bool eof)
Definition: stream-tcp-reassemble.c:1892
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
InspectionBufferSetupMulti
void InspectionBufferSetupMulti(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine-inspect-buffer.c:157
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine-inspect-buffer.c:76
DetectBufferMpmRegistry_::pname
char pname[32]
Definition: detect.h:764
DetectEngineFrameInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:520
FrameStreamData
Definition: detect-engine-frame.c:44