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