suricata
detect-csum.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 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 Anoop Saldanha <anoopsaldanha@gmail.com>
22  *
23  * Implements checksum keyword.
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 
29 #include "detect.h"
30 #include "detect-parse.h"
31 
32 #include "detect-csum.h"
33 
34 #include "util-unittest.h"
35 #include "util-debug.h"
36 
37 #include "pkt-var.h"
38 #include "host.h"
39 #include "util-profiling.h"
40 #include "detect-engine-build.h"
41 
42 #define DETECT_CSUM_VALID "valid"
43 #define DETECT_CSUM_INVALID "invalid"
44 
45 typedef struct DetectCsumData_ {
46  /* Indicates if the csum-<protocol> keyword in a rule holds the
47  keyvalue "valid" or "invalid" */
48  int16_t valid;
50 
51 /* prototypes for the "ipv4-csum" rule keyword */
52 static int DetectIPV4CsumMatch(DetectEngineThreadCtx *,
53  Packet *, const Signature *, const SigMatchCtx *);
54 static int DetectIPV4CsumSetup(DetectEngineCtx *, Signature *, const char *);
55 static void DetectIPV4CsumFree(DetectEngineCtx *, void *);
56 
57 /* prototypes for the "tcpv4-csum" rule keyword */
58 static int DetectTCPV4CsumMatch(DetectEngineThreadCtx *,
59  Packet *, const Signature *, const SigMatchCtx *);
60 static int DetectTCPV4CsumSetup(DetectEngineCtx *, Signature *, const char *);
61 static void DetectTCPV4CsumFree(DetectEngineCtx *, void *);
62 
63 /* prototypes for the "tcpv6-csum" rule keyword */
64 static int DetectTCPV6CsumMatch(DetectEngineThreadCtx *,
65  Packet *, const Signature *, const SigMatchCtx *);
66 static int DetectTCPV6CsumSetup(DetectEngineCtx *, Signature *, const char *);
67 static void DetectTCPV6CsumFree(DetectEngineCtx *, void *);
68 
69 /* prototypes for the "udpv4-csum" rule keyword */
70 static int DetectUDPV4CsumMatch(DetectEngineThreadCtx *,
71  Packet *, const Signature *, const SigMatchCtx *);
72 static int DetectUDPV4CsumSetup(DetectEngineCtx *, Signature *, const char *);
73 static void DetectUDPV4CsumFree(DetectEngineCtx *, void *);
74 
75 /* prototypes for the "udpv6-csum" rule keyword */
76 static int DetectUDPV6CsumMatch(DetectEngineThreadCtx *,
77  Packet *, const Signature *, const SigMatchCtx *);
78 static int DetectUDPV6CsumSetup(DetectEngineCtx *, Signature *, const char *);
79 static void DetectUDPV6CsumFree(DetectEngineCtx *de_ctx, void *);
80 
81 /* prototypes for the "icmpv4-csum" rule keyword */
82 static int DetectICMPV4CsumMatch(DetectEngineThreadCtx *,
83  Packet *, const Signature *, const SigMatchCtx *);
84 static int DetectICMPV4CsumSetup(DetectEngineCtx *, Signature *, const char *);
85 static void DetectICMPV4CsumFree(DetectEngineCtx *, void *);
86 
87 /* prototypes for the "icmpv6-csum" rule keyword */
88 static int DetectICMPV6CsumMatch(DetectEngineThreadCtx *,
89  Packet *, const Signature *, const SigMatchCtx *);
90 static int DetectICMPV6CsumSetup(DetectEngineCtx *, Signature *, const char *);
91 static void DetectICMPV6CsumFree(DetectEngineCtx *, void *);
92 
93 #ifdef UNITTESTS
94 static void DetectCsumRegisterTests(void);
95 #endif
96 
97 /**
98  * \brief Registers handlers for all the checksum keywords. The checksum
99  * keywords that are registered are ipv4-sum, tcpv4-csum, tcpv6-csum,
100  * udpv4-csum, udpv6-csum, icmpv4-csum and icmpv6-csum.
101  *
102  * Each of the checksum keywords implemented here takes 2 arguments -
103  * "valid" or "invalid". If the rule keyword in the signature is
104  * specified as "valid", the Match function would return TRUE if the
105  * checksum for that particular packet and protocol is valid. Similarly
106  * for "invalid".
107  *
108  * The Setup functions takes 4 arguments -
109  *
110  * DetectEngineCtx * (de_ctx) - A pointer to the detection engine context
111  * Signature *(s) - Pointer to signature for the current Signature being
112  * parsed from the rules
113  * SigMatchCtx * (m) - Pointer to the head of the SigMatchs added to the
114  * current Signature being parsed
115  * char * (csum_str) - Pointer to a string holding the keyword value
116  *
117  * The Setup function returns 0 if it successfully parses the keyword
118  * value, and -1 otherwise.
119  *
120  * The Match function takes 5 arguments -
121  *
122  * ThreadVars * (t) - Pointer to the tv for the detection module instance
123  * DetectEngineThreadCtx * (det_ctx) - Pointer to the detection engine
124  * thread context
125  * Packet * (p) - Pointer to the Packet currently being handled
126  * Signature * (s) - Pointer to the Signature, the packet is being
127  * currently matched with
128  * SigMatchCtx * (m) - Pointer to the keyword structure from the above
129  * Signature, the Packet is being currently matched
130  * with
131  *
132  * The Match function returns 1 if the Packet contents match the keyword,
133  * and 0 otherwise
134  *
135  * The Free function takes a single argument -
136  *
137  * void * (ptr) - Pointer to the DetectCsumData for a keyword
138  */
140 {
141  sigmatch_table[DETECT_IPV4_CSUM].name = "ipv4-csum";
142  sigmatch_table[DETECT_IPV4_CSUM].Match = DetectIPV4CsumMatch;
143  sigmatch_table[DETECT_IPV4_CSUM].Setup = DetectIPV4CsumSetup;
144  sigmatch_table[DETECT_IPV4_CSUM].Free = DetectIPV4CsumFree;
145 #ifdef UNITTESTS
146  sigmatch_table[DETECT_IPV4_CSUM].RegisterTests = DetectCsumRegisterTests;
147 #endif
148 
149  sigmatch_table[DETECT_TCPV4_CSUM].name = "tcpv4-csum";
150  sigmatch_table[DETECT_TCPV4_CSUM].Match = DetectTCPV4CsumMatch;
151  sigmatch_table[DETECT_TCPV4_CSUM].Setup = DetectTCPV4CsumSetup;
152  sigmatch_table[DETECT_TCPV4_CSUM].Free = DetectTCPV4CsumFree;
153 
154  sigmatch_table[DETECT_TCPV6_CSUM].name = "tcpv6-csum";
155  sigmatch_table[DETECT_TCPV6_CSUM].Match = DetectTCPV6CsumMatch;
156  sigmatch_table[DETECT_TCPV6_CSUM].Setup = DetectTCPV6CsumSetup;
157  sigmatch_table[DETECT_TCPV6_CSUM].Free = DetectTCPV6CsumFree;
158 
159  sigmatch_table[DETECT_UDPV4_CSUM].name = "udpv4-csum";
160  sigmatch_table[DETECT_UDPV4_CSUM].Match = DetectUDPV4CsumMatch;
161  sigmatch_table[DETECT_UDPV4_CSUM].Setup = DetectUDPV4CsumSetup;
162  sigmatch_table[DETECT_UDPV4_CSUM].Free = DetectUDPV4CsumFree;
163 
164  sigmatch_table[DETECT_UDPV6_CSUM].name = "udpv6-csum";
165  sigmatch_table[DETECT_UDPV6_CSUM].Match = DetectUDPV6CsumMatch;
166  sigmatch_table[DETECT_UDPV6_CSUM].Setup = DetectUDPV6CsumSetup;
167  sigmatch_table[DETECT_UDPV6_CSUM].Free = DetectUDPV6CsumFree;
168 
169  sigmatch_table[DETECT_ICMPV4_CSUM].name = "icmpv4-csum";
170  sigmatch_table[DETECT_ICMPV4_CSUM].Match = DetectICMPV4CsumMatch;
171  sigmatch_table[DETECT_ICMPV4_CSUM].Setup = DetectICMPV4CsumSetup;
172  sigmatch_table[DETECT_ICMPV4_CSUM].Free = DetectICMPV4CsumFree;
173 
174  sigmatch_table[DETECT_ICMPV6_CSUM].name = "icmpv6-csum";
175  sigmatch_table[DETECT_ICMPV6_CSUM].Match = DetectICMPV6CsumMatch;
176  sigmatch_table[DETECT_ICMPV6_CSUM].Setup = DetectICMPV6CsumSetup;
177  sigmatch_table[DETECT_ICMPV6_CSUM].Free = DetectICMPV6CsumFree;
178 }
179 
180 /**
181  * \brief Validates and parses the argument supplied with the checksum keyword.
182  * Accepts strings both with and without quotes, i.e. valid, \"valid\",
183  * invalid and \"invalid\"
184  *
185  * \param key Pointer to a const character string holding the csum keyword value
186  * \param cd Pointer to the DetectCsumData structure that holds the keyword
187  * value sent as argument
188  *
189  * \retval 1 the keyvalue has been parsed successfully
190  * \retval 0 error
191  */
192 static int DetectCsumParseArg(const char *key, DetectCsumData *cd)
193 {
194  char *str;
195 
196  if (key[0] == '\"' && key[strlen(key) - 1] == '\"') {
197  str = SCStrdup(key + 1);
198  if (unlikely(str == NULL)) {
199  goto error;
200  }
201  str[strlen(key) - 2] = '\0';
202  } else {
203  str = SCStrdup(key);
204  if (unlikely(str == NULL)) {
205  goto error;
206  }
207  }
208 
209  if (strcasecmp(str, DETECT_CSUM_VALID) == 0 ||
210  strcasecmp(str, DETECT_CSUM_INVALID) == 0) {
211  cd->valid = (strcasecmp(key, DETECT_CSUM_VALID) == 0);
212  SCFree(str);
213  return 1;
214  }
215 
216 error:
217  if (str != NULL)
218  SCFree(str);
219  return 0;
220 }
221 
222 /**
223  * \brief Checks if the packet sent as the argument, has a valid or invalid
224  * ipv4 checksum, based on whether ipv4-csum option for this rule
225  * has been supplied with "valid" or "invalid" argument
226  *
227  * \param t Pointer to the tv for this detection module instance
228  * \param det_ctx Pointer to the detection engine thread context
229  * \param p Pointer to the Packet currently being matched
230  * \param s Pointer to the Signature, the packet is being currently
231  * matched with
232  * \param m Pointer to the keyword_structure(SigMatch) from the above
233  * Signature, the Packet is being currently matched with
234  *
235  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
236  */
237 static int DetectIPV4CsumMatch(DetectEngineThreadCtx *det_ctx,
238  Packet *p, const Signature *s, const SigMatchCtx *ctx)
239 {
240  const DetectCsumData *cd = (const DetectCsumData *)ctx;
241 
242  if (p->ip4h == NULL || PKT_IS_PSEUDOPKT(p))
243  return 0;
244 
245  if (p->flags & PKT_IGNORE_CHECKSUM) {
246  return cd->valid;
247  }
248 
249  if (p->level3_comp_csum == -1)
250  p->level3_comp_csum = IPV4Checksum((uint16_t *)p->ip4h,
251  IPV4_GET_HLEN(p),
252  p->ip4h->ip_csum);
253 
254  if (p->level3_comp_csum == 0 && cd->valid == 1)
255  return 1;
256  else if (p->level3_comp_csum != 0 && cd->valid == 0)
257  return 1;
258  else
259  return 0;
260 }
261 
262 /**
263  * \brief Creates a SigMatch for the ipv4-csum keyword being sent as argument,
264  * and appends it to the Signature(s). Accepts 2 values for the
265  * keyword - "valid" and "invalid", both with and without quotes
266  *
267  * \param de_ctx Pointer to the detection engine context
268  * \param s Pointer to signature for the current Signature being parsed
269  * from the rules
270  * \param csum_str Pointer to the string holding the keyword value
271  *
272  * \retval 0 on success, -1 on failure
273  */
274 static int DetectIPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
275 {
276  DetectCsumData *cd = NULL;
277 
278  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
279 
280  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
281  goto error;
282 
283  if (DetectCsumParseArg(csum_str, cd) == 0)
284  goto error;
285 
288  goto error;
289  }
290 
291  return 0;
292 
293 error:
294  if (cd != NULL)
295  DetectIPV4CsumFree(de_ctx, cd);
296 
297  return -1;
298 }
299 
300 static void DetectIPV4CsumFree(DetectEngineCtx *de_ctx, void *ptr)
301 {
302  DetectCsumData *cd = (DetectCsumData *)ptr;
303 
304  if (cd != NULL)
305  SCFree(cd);
306 
307  return;
308 }
309 
310 /**
311  * \brief Checks if the packet sent as the argument, has a valid or invalid
312  * tcpv4 checksum, based on whether tcpv4-csum option for this rule
313  * has been supplied with "valid" or "invalid" argument
314  *
315  * \param t Pointer to the tv for this detection module instance
316  * \param det_ctx Pointer to the detection engine thread context
317  * \param p Pointer to the Packet currently being matched
318  * \param s Pointer to the Signature, the packet is being currently
319  * matched with
320  * \param m Pointer to the keyword_structure(SigMatch) from the above
321  * Signature, the Packet is being currently matched with
322  *
323  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
324  */
325 static int DetectTCPV4CsumMatch(DetectEngineThreadCtx *det_ctx,
326  Packet *p, const Signature *s, const SigMatchCtx *ctx)
327 {
328  const DetectCsumData *cd = (const DetectCsumData *)ctx;
329 
330  if (p->ip4h == NULL || p->tcph == NULL || p->proto != IPPROTO_TCP || PKT_IS_PSEUDOPKT(p))
331  return 0;
332 
333  if (p->flags & PKT_IGNORE_CHECKSUM) {
334  return cd->valid;
335  }
336 
337  if (p->level4_comp_csum == -1)
338  p->level4_comp_csum = TCPChecksum(p->ip4h->s_ip_addrs,
339  (uint16_t *)p->tcph,
340  (p->payload_len +
341  TCP_GET_HLEN(p)),
342  p->tcph->th_sum);
343 
344  if (p->level4_comp_csum == 0 && cd->valid == 1)
345  return 1;
346  else if (p->level4_comp_csum != 0 && cd->valid == 0)
347  return 1;
348  else
349  return 0;
350 }
351 
352 /**
353  * \brief Creates a SigMatch for the tcpv4-csum keyword being sent as argument,
354  * and appends it to the Signature(s). Accepts 2 values for the
355  * keyword - "valid" and "invalid", both with and without quotes
356  *
357  * \param de_ctx Pointer to the detection engine context
358  * \param s Pointer to signature for the current Signature being parsed
359  * from the rules
360  * \param csum_str Pointer to the string holding the keyword value
361  *
362  * \retval 0 on success, -1 on failure
363  */
364 static int DetectTCPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
365 {
366  DetectCsumData *cd = NULL;
367 
368  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
369 
370  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
371  goto error;
372 
373  if (DetectCsumParseArg(csum_str, cd) == 0)
374  goto error;
375 
378  goto error;
379  }
380 
381  return 0;
382 
383 error:
384  if (cd != NULL)
385  DetectTCPV4CsumFree(de_ctx, cd);
386 
387  return -1;
388 }
389 
390 static void DetectTCPV4CsumFree(DetectEngineCtx *de_ctx, void *ptr)
391 {
392  DetectCsumData *cd = (DetectCsumData *)ptr;
393 
394  if (cd != NULL)
395  SCFree(cd);
396 
397  return;
398 }
399 
400 /**
401  * \brief Checks if the packet sent as the argument, has a valid or invalid
402  * tcpv6 checksum, based on whether tcpv6-csum option for this rule
403  * has been supplied with "valid" or "invalid" argument
404  *
405  * \param t Pointer to the tv for this detection module instance
406  * \param det_ctx Pointer to the detection engine thread context
407  * \param p Pointer to the Packet currently being matched
408  * \param s Pointer to the Signature, the packet is being currently
409  * matched with
410  * \param m Pointer to the keyword_structure(SigMatch) from the above
411  * Signature, the Packet is being currently matched with
412  *
413  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
414  */
415 static int DetectTCPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
416  Packet *p, const Signature *s, const SigMatchCtx *ctx)
417 {
418  const DetectCsumData *cd = (const DetectCsumData *)ctx;
419 
420  if (p->ip6h == NULL || p->tcph == NULL || p->proto != IPPROTO_TCP || PKT_IS_PSEUDOPKT(p))
421  return 0;
422 
423  if (p->flags & PKT_IGNORE_CHECKSUM) {
424  return cd->valid;
425  }
426 
427  if (p->level4_comp_csum == -1)
428  p->level4_comp_csum = TCPV6Checksum(p->ip6h->s_ip6_addrs,
429  (uint16_t *)p->tcph,
430  (p->payload_len +
431  TCP_GET_HLEN(p)),
432  p->tcph->th_sum);
433 
434  if (p->level4_comp_csum == 0 && cd->valid == 1)
435  return 1;
436  else if (p->level4_comp_csum != 0 && cd->valid == 0)
437  return 1;
438  else
439  return 0;
440 }
441 
442 /**
443  * \brief Creates a SigMatch for the tcpv6-csum keyword being sent as argument,
444  * and appends it to the Signature(s). Accepts 2 values for the
445  * keyword - "valid" and "invalid", both with and without quotes
446  *
447  * \param de_ctx Pointer to the detection engine context
448  * \param s Pointer to signature for the current Signature being parsed
449  * from the rules
450  * \param csum_str Pointer to the string holding the keyword value
451  *
452  * \retval 0 on success, -1 on failure
453  */
454 static int DetectTCPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
455 {
456  DetectCsumData *cd = NULL;
457 
458  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
459 
460  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
461  goto error;
462 
463  if (DetectCsumParseArg(csum_str, cd) == 0)
464  goto error;
465 
468  goto error;
469  }
470 
471  return 0;
472 
473 error:
474  if (cd != NULL)
475  DetectTCPV6CsumFree(de_ctx, cd);
476 
477  return -1;
478 }
479 
480 static void DetectTCPV6CsumFree(DetectEngineCtx *de_ctx, void *ptr)
481 {
482  DetectCsumData *cd = (DetectCsumData *)ptr;
483 
484  if (cd != NULL)
485  SCFree(cd);
486 
487  return;
488 }
489 
490 /**
491  * \brief Checks if the packet sent as the argument, has a valid or invalid
492  * udpv4 checksum, based on whether udpv4-csum option for this rule
493  * has been supplied with "valid" or "invalid" argument
494  *
495  * \param t Pointer to the tv for this detection module instance
496  * \param det_ctx Pointer to the detection engine thread context
497  * \param p Pointer to the Packet currently being matched
498  * \param s Pointer to the Signature, the packet is being currently
499  * matched with
500  * \param m Pointer to the keyword_structure(SigMatch) from the above
501  * Signature, the Packet is being currently matched with
502  *
503  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
504  */
505 static int DetectUDPV4CsumMatch(DetectEngineThreadCtx *det_ctx,
506  Packet *p, const Signature *s, const SigMatchCtx *ctx)
507 {
508  const DetectCsumData *cd = (const DetectCsumData *)ctx;
509 
510  if (p->ip4h == NULL || p->udph == NULL || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p) || p->udph->uh_sum == 0)
511  return 0;
512 
513  if (p->flags & PKT_IGNORE_CHECKSUM) {
514  return cd->valid;
515  }
516 
517  if (p->level4_comp_csum == -1)
518  p->level4_comp_csum = UDPV4Checksum(p->ip4h->s_ip_addrs,
519  (uint16_t *)p->udph,
520  (p->payload_len +
522  p->udph->uh_sum);
523 
524  if (p->level4_comp_csum == 0 && cd->valid == 1)
525  return 1;
526  else if (p->level4_comp_csum != 0 && cd->valid == 0)
527  return 1;
528  else
529  return 0;
530 }
531 
532 /**
533  * \brief Creates a SigMatch for the udpv4-csum keyword being sent as argument,
534  * and appends it to the Signature(s). Accepts 2 values for the
535  * keyword - "valid" and "invalid", both with and without quotes
536  *
537  * \param de_ctx Pointer to the detection engine context
538  * \param s Pointer to signature for the current Signature being parsed
539  * from the rules
540  * \param csum_str Pointer to the string holding the keyword value
541  *
542  * \retval 0 on success, -1 on failure
543  */
544 static int DetectUDPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
545 {
546  DetectCsumData *cd = NULL;
547 
548  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
549 
550  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
551  goto error;
552 
553  if (DetectCsumParseArg(csum_str, cd) == 0)
554  goto error;
555 
558  goto error;
559  }
560 
561  return 0;
562 
563 error:
564  if (cd != NULL)
565  DetectUDPV4CsumFree(de_ctx, cd);
566 
567  return -1;
568 }
569 
570 static void DetectUDPV4CsumFree(DetectEngineCtx *de_ctx, void *ptr)
571 {
572  DetectCsumData *cd = (DetectCsumData *)ptr;
573 
574  if (cd != NULL)
575  SCFree(cd);
576 
577  return;
578 }
579 
580 /**
581  * \brief Checks if the packet sent as the argument, has a valid or invalid
582  * udpv6 checksum, based on whether udpv6-csum option for this rule
583  * has been supplied with "valid" or "invalid" argument
584  *
585  * \param t Pointer to the tv for this detection module instance
586  * \param det_ctx Pointer to the detection engine thread context
587  * \param p Pointer to the Packet currently being matched
588  * \param s Pointer to the Signature, the packet is being currently
589  * matched with
590  * \param m Pointer to the keyword_structure(SigMatch) from the above
591  * Signature, the Packet is being currently matched with
592  *
593  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
594  */
595 static int DetectUDPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
596  Packet *p, const Signature *s, const SigMatchCtx *ctx)
597 {
598  const DetectCsumData *cd = (const DetectCsumData *)ctx;
599 
600  if (p->ip6h == NULL || p->udph == NULL || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p))
601  return 0;
602 
603  if (p->flags & PKT_IGNORE_CHECKSUM) {
604  return cd->valid;
605  }
606 
607  if (p->level4_comp_csum == -1)
608  p->level4_comp_csum = UDPV6Checksum(p->ip6h->s_ip6_addrs,
609  (uint16_t *)p->udph,
610  (p->payload_len +
612  p->udph->uh_sum);
613 
614  if (p->level4_comp_csum == 0 && cd->valid == 1)
615  return 1;
616  else if (p->level4_comp_csum != 0 && cd->valid == 0)
617  return 1;
618  else
619  return 0;
620 }
621 
622 /**
623  * \brief Creates a SigMatch for the udpv6-csum keyword being sent as argument,
624  * and appends it to the Signature(s). Accepts 2 values for the
625  * keyword - "valid" and "invalid", both with and without quotes
626  *
627  * \param de_ctx Pointer to the detection engine context
628  * \param s Pointer to signature for the current Signature being parsed
629  * from the rules
630  * \param csum_str Pointer to the string holding the keyword value
631  *
632  * \retval 0 on success, -1 on failure
633  */
634 static int DetectUDPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
635 {
636  DetectCsumData *cd = NULL;
637 
638  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
639 
640  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
641  goto error;
642 
643  if (DetectCsumParseArg(csum_str, cd) == 0)
644  goto error;
645 
648  goto error;
649  }
650 
651  return 0;
652 
653 error:
654  if (cd != NULL)
655  DetectUDPV6CsumFree(de_ctx, cd);
656 
657  return -1;
658 }
659 
660 static void DetectUDPV6CsumFree(DetectEngineCtx *de_ctx, void *ptr)
661 {
662  DetectCsumData *cd = (DetectCsumData *)ptr;
663 
664  if (cd != NULL)
665  SCFree(cd);
666 
667  return;
668 }
669 
670 /**
671  * \brief Checks if the packet sent as the argument, has a valid or invalid
672  * icmpv4 checksum, based on whether icmpv4-csum option for this rule
673  * has been supplied with "valid" or "invalid" argument
674  *
675  * \param t Pointer to the tv for this detection module instance
676  * \param det_ctx Pointer to the detection engine thread context
677  * \param p Pointer to the Packet currently being matched
678  * \param s Pointer to the Signature, the packet is being currently
679  * matched with
680  * \param m Pointer to the keyword_structure(SigMatch) from the above
681  * Signature, the Packet is being currently matched with
682  *
683  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
684  */
685 static int DetectICMPV4CsumMatch(DetectEngineThreadCtx *det_ctx,
686  Packet *p, const Signature *s, const SigMatchCtx *ctx)
687 {
688  const DetectCsumData *cd = (const DetectCsumData *)ctx;
689 
690  if (p->ip4h == NULL || p->icmpv4h == NULL || p->proto != IPPROTO_ICMP || PKT_IS_PSEUDOPKT(p))
691  return 0;
692 
693  if (p->flags & PKT_IGNORE_CHECKSUM) {
694  return cd->valid;
695  }
696 
697  if (p->level4_comp_csum == -1)
698  p->level4_comp_csum = ICMPV4CalculateChecksum((uint16_t *)p->icmpv4h,
700  IPV4_GET_RAW_HLEN(p->ip4h) * 4);
701 
702  if (p->level4_comp_csum == p->icmpv4h->checksum && cd->valid == 1)
703  return 1;
704  else if (p->level4_comp_csum != p->icmpv4h->checksum && cd->valid == 0)
705  return 1;
706  else
707  return 0;
708 }
709 
710 /**
711  * \brief Creates a SigMatch for the icmpv4-csum keyword being sent as argument,
712  * and appends it to the Signature(s). Accepts 2 values for the
713  * keyword - "valid" and "invalid", both with and without quotes
714  *
715  * \param de_ctx Pointer to the detection engine context
716  * \param s Pointer to signature for the current Signature being parsed
717  * from the rules
718  * \param csum_str Pointer to the string holding the keyword value
719  *
720  * \retval 0 on success, -1 on failure
721  */
722 static int DetectICMPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
723 {
724  DetectCsumData *cd = NULL;
725 
726  //printf("DetectCsumSetup: \'%s\'\n", csum_str);
727 
728  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
729  goto error;
730 
731  if (DetectCsumParseArg(csum_str, cd) == 0)
732  goto error;
733 
736  goto error;
737  }
738 
739  return 0;
740 
741 error:
742  if (cd != NULL)
743  DetectICMPV4CsumFree(de_ctx, cd);
744 
745  return -1;
746 }
747 
748 static void DetectICMPV4CsumFree(DetectEngineCtx *de_ctx, void *ptr)
749 {
750  DetectCsumData *cd = (DetectCsumData *)ptr;
751 
752  if (cd != NULL)
753  SCFree(cd);
754 
755  return;
756 }
757 
758 /**
759  * \brief Checks if the packet sent as the argument, has a valid or invalid
760  * icmpv6 checksum, based on whether icmpv6-csum option for this rule
761  * has been supplied with "valid" or "invalid" argument
762  *
763  * \param t Pointer to the tv for this detection module instance
764  * \param det_ctx Pointer to the detection engine thread context
765  * \param p Pointer to the Packet currently being matched
766  * \param s Pointer to the Signature, the packet is being currently
767  * matched with
768  * \param m Pointer to the keyword_structure(SigMatch) from the above
769  * Signature, the Packet is being currently matched with
770  *
771  * \retval 1 if the Packet contents match the keyword option; 0 otherwise
772  */
773 static int DetectICMPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
774  Packet *p, const Signature *s, const SigMatchCtx *ctx)
775 {
776  const DetectCsumData *cd = (const DetectCsumData *)ctx;
777 
778  if (p->ip6h == NULL || p->icmpv6h == NULL || p->proto != IPPROTO_ICMPV6 || PKT_IS_PSEUDOPKT(p) ||
779  (GET_PKT_LEN(p) - ((uint8_t *)p->icmpv6h - GET_PKT_DATA(p))) <= 0) {
780  return 0;
781  }
782 
783  if (p->flags & PKT_IGNORE_CHECKSUM) {
784  return cd->valid;
785  }
786 
787  if (p->level4_comp_csum == -1) {
788  uint16_t len = IPV6_GET_RAW_PLEN(p->ip6h) -
789  (uint16_t)((uint8_t *)p->icmpv6h - (uint8_t *)p->ip6h - IPV6_HEADER_LEN);
790  p->level4_comp_csum = ICMPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
791  (uint16_t *)p->icmpv6h,
792  len);
793  }
794 
795  if (p->level4_comp_csum == p->icmpv6h->csum && cd->valid == 1)
796  return 1;
797  else if (p->level4_comp_csum != p->icmpv6h->csum && cd->valid == 0)
798  return 1;
799  else
800  return 0;
801 }
802 
803 /**
804  * \brief Creates a SigMatch for the icmpv6-csum keyword being sent as argument,
805  * and appends it to the Signature(s). Accepts 2 values for the
806  * keyword - "valid" and "invalid", both with and without quotes
807  *
808  * \param de_ctx Pointer to the detection engine context
809  * \param s Pointer to signature for the current Signature being parsed
810  * from the rules
811  * \param csum_str Pointer to the string holding the keyword value
812  *
813  * \retval 0 on success, -1 on failure
814  */
815 static int DetectICMPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, const char *csum_str)
816 {
817  DetectCsumData *cd = NULL;
818 
819  if ((cd = SCCalloc(1, sizeof(DetectCsumData))) == NULL)
820  goto error;
821 
822  if (DetectCsumParseArg(csum_str, cd) == 0)
823  goto error;
824 
827  goto error;
828  }
829 
830  return 0;
831 
832 error:
833  if (cd != NULL)
834  DetectICMPV6CsumFree(de_ctx, cd);
835 
836  return -1;
837 }
838 
839 static void DetectICMPV6CsumFree(DetectEngineCtx *de_ctx, void *ptr)
840 {
841  DetectCsumData *cd = (DetectCsumData *)ptr;
842 
843  if (cd != NULL)
844  SCFree(cd);
845 
846  return;
847 }
848 
849 /* ---------------------------------- Unit Tests --------------------------- */
850 
851 #ifdef UNITTESTS
852 #include "util-unittest-helper.h"
853 #include "detect-engine.h"
854 #include "detect-engine-alert.h"
855 #include "packet.h"
856 
857 #define mystr(s) #s
858 #define TEST1(kwstr) {\
859  DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
860  FAIL_IF_NULL(de_ctx);\
861  de_ctx->flags = DE_QUIET;\
862  \
863  Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
864  FAIL_IF_NULL(s);\
865  s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:invalid; sid:2;)");\
866  FAIL_IF_NULL(s);\
867  s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:vaLid; sid:3;)");\
868  FAIL_IF_NULL(s);\
869  s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:VALID; sid:4;)");\
870  FAIL_IF_NULL(s);\
871  s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:iNvaLid; sid:5;)");\
872  FAIL_IF_NULL(s);\
873  DetectEngineCtxFree(de_ctx);\
874 }
875 
876 
877 static int DetectCsumValidArgsTestParse01(void)
878 {
879  TEST1(ipv4);
880  TEST1(tcpv4);
881  TEST1(tcpv6);
882  TEST1(udpv4);
883  TEST1(udpv6);
884  TEST1(icmpv4);
885  TEST1(icmpv6);
886  PASS;
887 }
888 #undef TEST1
889 
890 #define TEST2(kwstr) \
891  { \
892  DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
893  FAIL_IF_NULL(de_ctx); \
894  Signature *s = DetectEngineAppendSig( \
895  de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxx; sid:1;)"); \
896  FAIL_IF(s); \
897  s = DetectEngineAppendSig( \
898  de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxxxxxx; sid:2;)"); \
899  FAIL_IF(s); \
900  s = DetectEngineAppendSig( \
901  de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxxxx; sid:3;)"); \
902  FAIL_IF(s); \
903  s = DetectEngineAppendSig( \
904  de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:XXXXXX; sid:4;)"); \
905  FAIL_IF(s); \
906  s = DetectEngineAppendSig( \
907  de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:XxXxXxX; sid:5;)"); \
908  FAIL_IF(s); \
909  DetectEngineCtxFree(de_ctx); \
910  }
911 
912 static int DetectCsumInvalidArgsTestParse02(void)
913 {
914  TEST2(ipv4);
915  TEST2(tcpv4);
916  TEST2(tcpv6);
917  TEST2(udpv4);
918  TEST2(udpv6);
919  TEST2(icmpv4);
920  TEST2(icmpv6);
921  PASS;
922 }
923 #undef TEST2
924 
925 #define TEST3(kwstr, kwtype) { \
926  DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
927  FAIL_IF_NULL(de_ctx);\
928  Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
929  FAIL_IF_NULL(s);\
930  SigMatch *sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
931  FAIL_IF_NULL(sm);\
932  FAIL_IF_NULL(sm->ctx);\
933  FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 1);\
934  s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:INVALID; sid:2;)");\
935  FAIL_IF_NULL(s);\
936  sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
937  FAIL_IF_NULL(sm);\
938  FAIL_IF_NULL(sm->ctx);\
939  FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 0);\
940  DetectEngineCtxFree(de_ctx);\
941 }
942 
943 static int DetectCsumValidArgsTestParse03(void)
944 {
945  TEST3(ipv4, DETECT_IPV4_CSUM);
946  TEST3(tcpv4, DETECT_TCPV4_CSUM);
947  TEST3(tcpv6, DETECT_TCPV6_CSUM);
948  TEST3(udpv4, DETECT_UDPV4_CSUM);
949  TEST3(udpv6, DETECT_UDPV6_CSUM);
950  TEST3(icmpv4, DETECT_ICMPV4_CSUM);
951  TEST3(icmpv6, DETECT_ICMPV6_CSUM);
952  PASS;
953 }
954 #undef TEST3
955 #undef mystr
956 
957 #include "stream-tcp.h"
958 
959 static int DetectCsumICMPV6Test01(void)
960 {
961  DetectEngineCtx *de_ctx = NULL;
962  Signature *s = NULL;
963  ThreadVars tv;
964  DetectEngineThreadCtx *det_ctx = NULL;
966 
967  Packet *p = PacketGetFromAlloc();
968  FAIL_IF_NULL(p);
969 
970  uint8_t pkt[] = {
971  0x00, 0x30, 0x18, 0xa8, 0x7c, 0x23, 0x2c, 0x41,
972  0x38, 0xa7, 0xea, 0xeb, 0x86, 0xdd, 0x60, 0x00,
973  0x00, 0x00, 0x00, 0x40, 0x3c, 0x40, 0xad, 0xa1,
974  0x09, 0x80, 0x00, 0x01, 0xd6, 0xf3, 0x20, 0x01,
975  0xf4, 0xbe, 0xea, 0x3c, 0x00, 0x01, 0x00, 0x00,
976  0x00, 0x00, 0x32, 0xb2, 0x00, 0x01, 0x32, 0xb2,
977  0x09, 0x80, 0x20, 0x01, 0x00, 0x00, 0x3c, 0x00,
978  0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
979  0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
980  0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
981  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
982  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
983  0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00,
984  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
985  0x63, 0xc2, 0x00, 0x00, 0x00, 0x00 };
986 
987  PacketCopyData(p, pkt, sizeof(pkt));
988 
989  memset(&tv, 0, sizeof(tv));
990  memset(&dtv, 0, sizeof(dtv));
991 
992  StreamTcpInitConfig(true);
994 
998  de_ctx->flags |= DE_QUIET;
999 
1000  s = de_ctx->sig_list = SigInit(de_ctx, "alert ip any any -> any any "
1001  "(icmpv6-csum:valid; sid:1;)");
1002  FAIL_IF_NULL(s);
1004 
1005  DecodeEthernet(&tv, &dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p));
1006 
1007  DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);
1008 
1009  SigMatchSignatures(&tv, de_ctx, det_ctx, p);
1010 
1011  FAIL_IF(!PacketAlertCheck(p, 1));
1012 
1013  DetectEngineThreadCtxDeinit(&tv, det_ctx);
1015 
1016  StreamTcpFreeConfig(true);
1017  PacketRecycle(p);
1018  FlowShutdown();
1019  SCFree(p);
1020  PASS;
1021 }
1022 
1023 static void DetectCsumRegisterTests(void)
1024 {
1025  UtRegisterTest("DetectCsumValidArgsTestParse01",
1026  DetectCsumValidArgsTestParse01);
1027  UtRegisterTest("DetectCsumInvalidArgsTestParse02",
1028  DetectCsumInvalidArgsTestParse02);
1029  UtRegisterTest("DetectCsumValidArgsTestParse03",
1030  DetectCsumValidArgsTestParse03);
1031 
1032  UtRegisterTest("DetectCsumICMPV6Test01",
1033  DetectCsumICMPV6Test01);
1034 }
1035 #endif /* UNITTESTS */
host.h
Packet_::proto
uint8_t proto
Definition: decode.h:459
len
uint8_t len
Definition: app-layer-dnp3.h:2
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
IPV6_GET_RAW_PLEN
#define IPV6_GET_RAW_PLEN(ip6h)
Definition: decode-ipv6.h:66
DETECT_CSUM_VALID
#define DETECT_CSUM_VALID
Definition: detect-csum.c:42
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1283
PacketCopyData
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Definition: decode.c:348
SigTableElmt_::name
const char * name
Definition: detect.h:1293
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1075
stream-tcp.h
DETECT_ICMPV4_CSUM
@ DETECT_ICMPV4_CSUM
Definition: detect-engine-register.h:97
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
ICMPV6Hdr_::csum
uint16_t csum
Definition: decode-icmpv6.h:147
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:141
Packet_::flags
uint32_t flags
Definition: decode.h:474
PacketRecycle
void PacketRecycle(Packet *p)
Definition: packet.c:169
DETECT_UDPV6_CSUM
@ DETECT_UDPV6_CSUM
Definition: detect-engine-register.h:96
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:836
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2533
DetectCsumData
struct DetectCsumData_ DetectCsumData
DE_QUIET
#define DE_QUIET
Definition: detect.h:321
mpm_default_matcher
uint8_t mpm_default_matcher
Definition: util-mpm.c:48
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1884
DETECT_CSUM_INVALID
#define DETECT_CSUM_INVALID
Definition: detect-csum.c:43
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1278
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:587
util-unittest.h
util-unittest-helper.h
DETECT_TCPV4_CSUM
@ DETECT_TCPV4_CSUM
Definition: detect-engine-register.h:93
Packet_::level3_comp_csum
int32_t level3_comp_csum
Definition: decode.h:541
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:537
StreamTcpInitConfig
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
Definition: stream-tcp.c:463
decode.h
Packet_::level4_comp_csum
int32_t level4_comp_csum
Definition: decode.h:543
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1092
TCPHdr_::th_sum
uint16_t th_sum
Definition: decode-tcp.h:150
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:221
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
pkt-var.h
IPV4_GET_RAW_HLEN
#define IPV4_GET_RAW_HLEN(ip4h)
Definition: decode-ipv4.h:96
DetectEngineCtx_::mpm_matcher
uint8_t mpm_matcher
Definition: detect.h:839
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:111
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2314
util-profiling.h
Packet_::icmpv6h
ICMPV6Hdr * icmpv6h
Definition: decode.h:577
Packet_
Definition: decode.h:437
detect-engine-build.h
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:220
detect-engine-alert.h
Packet_::ip4h
IPV4Hdr * ip4h
Definition: decode.h:545
PKT_IGNORE_CHECKSUM
#define PKT_IGNORE_CHECKSUM
Definition: decode.h:1038
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1261
DETECT_IPV4_CSUM
@ DETECT_IPV4_CSUM
Definition: detect-engine-register.h:92
DetectCsumData_::valid
int16_t valid
Definition: detect-csum.c:48
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2149
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:33
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:342
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3244
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
StreamTcpFreeConfig
void StreamTcpFreeConfig(bool quiet)
Definition: stream-tcp.c:794
ICMPV4Hdr_::checksum
uint16_t checksum
Definition: decode-icmpv4.h:168
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:414
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3454
Packet_::tcph
TCPHdr * tcph
Definition: decode.h:567
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:685
packet.h
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:127
DetectCsumRegister
void DetectCsumRegister(void)
Registers handlers for all the checksum keywords. The checksum keywords that are registered are ipv4-...
Definition: detect-csum.c:139
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:844
Packet_::icmpv4h
ICMPV4Hdr * icmpv4h
Definition: decode.h:575
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:229
IPV4_GET_HLEN
#define IPV4_GET_HLEN(p)
Definition: decode-ipv4.h:124
DetectCsumData_
Definition: detect-csum.c:45
str
#define str(s)
Definition: suricata-common.h:291
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:685
DETECT_ICMPV6_CSUM
@ DETECT_ICMPV6_CSUM
Definition: detect-engine-register.h:98
TEST1
#define TEST1(kwstr)
Definition: detect-csum.c:858
detect-parse.h
Signature_
Signature container.
Definition: detect.h:593
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2494
IPV4Hdr_::ip_csum
uint16_t ip_csum
Definition: decode-ipv4.h:80
TCP_GET_HLEN
#define TCP_GET_HLEN(p)
Definition: decode-tcp.h:111
TEST3
#define TEST3(kwstr, kwtype)
Definition: detect-csum.c:925
Packet_::udph
UDPHdr * udph
Definition: decode.h:569
UDP_HEADER_LEN
#define UDP_HEADER_LEN
Definition: decode-udp.h:27
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:42
TEST2
#define TEST2(kwstr)
Definition: detect-csum.c:890
IPV6_HEADER_LEN
#define IPV6_HEADER_LEN
Definition: decode-ipv6.h:27
IPV4_GET_RAW_IPLEN
#define IPV4_GET_RAW_IPLEN(ip4h)
Definition: decode-ipv4.h:98
detect-csum.h
SigMatchAppendSMToList
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:447
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:838
Packet_::ip6h
IPV6Hdr * ip6h
Definition: decode.h:547
DETECT_TCPV6_CSUM
@ DETECT_TCPV6_CSUM
Definition: detect-engine-register.h:94
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DecodeEthernet
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ethernet.c:42
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1285
DETECT_UDPV4_CSUM
@ DETECT_UDPV4_CSUM
Definition: detect-engine-register.h:95
UDPHdr_::uh_sum
uint16_t uh_sum
Definition: decode-udp.h:46