suricata
decode-tcp.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  * \ingroup decode
20  *
21  * @{
22  */
23 
24 
25 /**
26  * \file
27  *
28  * \author Victor Julien <victor@inliniac.net>
29  *
30  * Decode TCP
31  */
32 
33 #include "suricata-common.h"
34 #include "decode-tcp.h"
35 #include "decode.h"
36 #include "decode-events.h"
37 #include "util-debug.h"
38 #include "flow.h"
39 
40 static inline uint16_t DecodeTCPGetU16(const uint8_t *d)
41 {
42  return (uint16_t)(((uint16_t)d[0] << 8) | (uint16_t)d[1]);
43 }
44 
45 static void DecodeTCPOptions(Packet *p, const uint8_t *pkt, uint16_t pktlen)
46 {
47  uint8_t tcp_opt_cnt = 0;
48  TCPOpt tcp_opts[TCP_OPTMAX];
49 
50  const TCPHdr *tcph = PacketGetTCP(p);
51  uint16_t plen = pktlen;
52  while (plen)
53  {
54  const uint8_t type = *pkt;
55 
56  /* single byte options */
57  if (type == TCP_OPT_EOL) {
58  break;
59  } else if (type == TCP_OPT_NOP) {
60  pkt++;
61  plen--;
62 
63  /* multibyte options */
64  } else {
65  if (plen < 2) {
66  break;
67  }
68 
69  const uint8_t olen = *(pkt+1);
70 
71  /* we already know that the total options len is valid,
72  * so here the len of the specific option must be bad.
73  * Also check for invalid lengths 0 and 1. */
74  if (unlikely(olen > plen || olen < 2)) {
76  return;
77  }
78 
79  tcp_opts[tcp_opt_cnt].type = type;
80  tcp_opts[tcp_opt_cnt].len = olen;
81 
82  /* we are parsing the most commonly used opts to prevent
83  * us from having to walk the opts list for these all the
84  * time. */
85  switch (type) {
86  case TCP_OPT_WS:
87  if (olen != TCP_OPT_WS_LEN) {
89  } else {
90  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
91  if (p->l4.vars.tcp.wscale_set != 0) {
93  } else {
94  p->l4.vars.tcp.wscale_set = 1;
95  const uint8_t wscale = *(tcp_opts[tcp_opt_cnt].data);
96  if (wscale <= TCP_WSCALE_MAX) {
97  p->l4.vars.tcp.wscale = wscale;
98  } else {
99  // RFC 7323 2.3 states
100  // If a Window Scale option is received with a shift.cnt value
101  // larger than 14, the TCP SHOULD log the error but MUST use 14
102  // instead of the specified value
105  }
106  }
107  }
108  break;
109  case TCP_OPT_MSS:
110  if (olen != TCP_OPT_MSS_LEN) {
112  } else {
113  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
114  if (p->l4.vars.tcp.mss_set) {
116  } else {
117  p->l4.vars.tcp.mss_set = true;
118  p->l4.vars.tcp.mss = DecodeTCPGetU16(tcp_opts[tcp_opt_cnt].data);
119  }
120  }
121  break;
122  case TCP_OPT_SACKOK:
123  if (olen != TCP_OPT_SACKOK_LEN) {
125  } else {
126  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
127  if (TCP_GET_SACKOK(p)) {
129  } else {
130  p->l4.vars.tcp.sack_ok = true;
131  }
132  }
133  break;
134  case TCP_OPT_TS:
135  if (olen != TCP_OPT_TS_LEN) {
137  } else {
138  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
139  if (p->l4.vars.tcp.ts_set) {
141  } else {
142  uint32_t values[2];
143  memcpy(&values, tcp_opts[tcp_opt_cnt].data, sizeof(values));
144  p->l4.vars.tcp.ts_val = SCNtohl(values[0]);
145  p->l4.vars.tcp.ts_ecr = SCNtohl(values[1]);
146  p->l4.vars.tcp.ts_set = true;
147  }
148  }
149  break;
150  case TCP_OPT_SACK:
151  SCLogDebug("SACK option, len %u", olen);
152  if (olen == 2) {
153  /* useless, but common empty SACK record */
154  } else if (olen < TCP_OPT_SACK_MIN_LEN || olen > TCP_OPT_SACK_MAX_LEN ||
155  !((olen - 2) % 8 == 0)) {
157  } else {
158  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
159  if (p->l4.vars.tcp.sack_set) {
161  } else {
162  ptrdiff_t diff = tcp_opts[tcp_opt_cnt].data - (uint8_t *)tcph;
163  DEBUG_VALIDATE_BUG_ON(diff > UINT16_MAX);
164  p->l4.vars.tcp.sack_set = true;
165  p->l4.vars.tcp.sack_cnt = (olen - 2) / 8;
166  p->l4.vars.tcp.sack_offset = (uint16_t)diff;
167  }
168  }
169  break;
170  case TCP_OPT_TFO:
171  SCLogDebug("TFO option, len %u", olen);
172  if ((olen != 2) && (olen < TCP_OPT_TFO_MIN_LEN || olen > TCP_OPT_TFO_MAX_LEN ||
173  !(((olen - 2) & 0x1) == 0))) {
175  } else {
176  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
177  if (p->l4.vars.tcp.tfo_set) {
179  } else {
180  p->l4.vars.tcp.tfo_set = true;
181  }
182  }
183  break;
184  /* experimental options, could be TFO */
185  case TCP_OPT_EXP1:
186  case TCP_OPT_EXP2:
187  SCLogDebug("TCP EXP option, len %u", olen);
188  if (olen == 4 || olen == 12) {
189  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
190  uint16_t magic = DecodeTCPGetU16(tcp_opts[tcp_opt_cnt].data);
191  if (magic == 0xf989) {
192  if (p->l4.vars.tcp.tfo_set) {
194  } else {
195  p->l4.vars.tcp.tfo_set = true;
196  }
197  }
198  } else {
200  }
201  break;
202  /* RFC 2385 MD5 option */
203  case TCP_OPT_MD5:
204  SCLogDebug("MD5 option, len %u", olen);
205  if (olen != 18) {
207  } else {
208  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
209  /* we can't validate the option as the key is out of band */
210  p->l4.vars.tcp.md5_option_present = true;
211  }
212  break;
213  /* RFC 5925 AO option */
214  case TCP_OPT_AO:
215  SCLogDebug("AU option, len %u", olen);
216  if (olen < 4) {
218  } else {
219  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
220  /* we can't validate the option as the key is out of band */
221  p->l4.vars.tcp.ao_option_present = true;
222  }
223  break;
224  default:
225  if (olen > 2) {
226  tcp_opts[tcp_opt_cnt].data = (pkt + 2);
227  } else {
228 
229  tcp_opts[tcp_opt_cnt].data = NULL;
230  }
231  }
232 
233  pkt += olen;
234  plen -= olen;
235  tcp_opt_cnt++;
236  }
237  }
238 }
239 
240 static int DecodeTCPPacket(
241  ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
242 {
243  if (unlikely(len < TCP_HEADER_LEN)) {
245  return -1;
246  }
247 
248  TCPHdr *tcph = PacketSetTCP(p, pkt);
249 
250  uint8_t hlen = TCP_GET_RAW_HLEN(tcph);
251  if (unlikely(len < hlen)) {
253  return -1;
254  }
255 
256  uint8_t tcp_opt_len = hlen - TCP_HEADER_LEN;
257  if (unlikely(tcp_opt_len > TCP_OPTLENMAX)) {
259  return -1;
260  }
261 
262  if (likely(tcp_opt_len > 0)) {
263  DecodeTCPOptions(p, pkt + TCP_HEADER_LEN, tcp_opt_len);
264  }
265 
266  p->sp = TCP_GET_RAW_SRC_PORT(tcph);
267  p->dp = TCP_GET_RAW_DST_PORT(tcph);
268 
269  p->proto = IPPROTO_TCP;
270 
271  p->payload = (uint8_t *)pkt + hlen;
272  p->payload_len = len - hlen;
273 
274  /* update counters */
275  if ((tcph->th_flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) {
277  } else if (tcph->th_flags & (TH_SYN)) {
279  }
280  if (tcph->th_flags & (TH_RST)) {
282  }
283  if (tcph->th_flags & (TH_URG)) {
285  }
286 
287 #ifdef DEBUG
288  SCLogDebug("TCP sp: %u -> dp: %u - HLEN: %" PRIu32 " LEN: %" PRIu32 " %s%s%s%s%s%s", p->sp,
289  p->dp, TCP_GET_RAW_HLEN(tcph), len, TCP_GET_SACKOK(p) ? "SACKOK " : "",
290  TCP_HAS_SACK(p) ? "SACK " : "", TCP_HAS_WSCALE(p) ? "WS " : "",
291  TCP_HAS_TS(p) ? "TS " : "", TCP_HAS_MSS(p) ? "MSS " : "", TCP_HAS_TFO(p) ? "TFO " : "");
292 #endif
293  return 0;
294 }
295 
296 int DecodeTCP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
297 {
299 
300  if (unlikely(DecodeTCPPacket(tv, dtv, p, pkt, len) < 0)) {
301  SCLogDebug("invalid TCP packet");
302  PacketClearL4(p);
303  return TM_ECODE_FAILED;
304  }
305 
307 
308  return TM_ECODE_OK;
309 }
310 
311 #ifdef UNITTESTS
312 #include "util-unittest-helper.h"
313 #include "packet.h"
314 
315 static int TCPCalculateValidChecksumtest01(void)
316 {
317  uint16_t csum = 0;
318 
319  uint8_t raw_ipshdr[] = {
320  0x40, 0x8e, 0x7e, 0xb2, 0xc0, 0xa8, 0x01, 0x03};
321 
322  uint8_t raw_tcp[] = {
323  0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
324  0xcf, 0x0d, 0x21, 0x80, 0xa0, 0x12, 0x16, 0xa0,
325  0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
326  0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
327  0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 02};
328 
329  csum = *( ((uint16_t *)raw_tcp) + 8);
330 
331  FAIL_IF(TCPChecksum((uint16_t *)raw_ipshdr,
332  (uint16_t *)raw_tcp, sizeof(raw_tcp), csum) != 0);
333  PASS;
334 }
335 
336 static int TCPCalculateInvalidChecksumtest02(void)
337 {
338  uint16_t csum = 0;
339 
340  uint8_t raw_ipshdr[] = {
341  0x40, 0x8e, 0x7e, 0xb2, 0xc0, 0xa8, 0x01, 0x03};
342 
343  uint8_t raw_tcp[] = {
344  0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
345  0xcf, 0x0d, 0x21, 0x80, 0xa0, 0x12, 0x16, 0xa0,
346  0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
347  0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
348  0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 03};
349 
350  csum = *( ((uint16_t *)raw_tcp) + 8);
351 
352  FAIL_IF(TCPChecksum((uint16_t *) raw_ipshdr,
353  (uint16_t *)raw_tcp, sizeof(raw_tcp), csum) == 0);
354  PASS;
355 }
356 
357 static int TCPV6CalculateValidChecksumtest03(void)
358 {
359  uint16_t csum = 0;
360 
361  static uint8_t raw_ipv6[] = {
362  0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
363  0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
364  0x00, 0x00, 0x00, 0x20, 0x06, 0x40, 0x3f, 0xfe,
365  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
366  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
367  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
368  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0x03, 0xfe,
369  0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d, 0x0c, 0x7a,
370  0x08, 0x77, 0x80, 0x10, 0x21, 0x5c, 0xc2, 0xf1,
371  0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08,
372  0xca, 0x5a, 0x00, 0x01, 0x69, 0x27};
373 
374  csum = *( ((uint16_t *)(raw_ipv6 + 70)));
375 
376  FAIL_IF(TCPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
377  (uint16_t *)(raw_ipv6 + 54), 32, csum) != 0);
378  PASS;
379 }
380 
381 static int TCPV6CalculateInvalidChecksumtest04(void)
382 {
383  uint16_t csum = 0;
384 
385  static uint8_t raw_ipv6[] = {
386  0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
387  0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
388  0x00, 0x00, 0x00, 0x20, 0x06, 0x40, 0x3f, 0xfe,
389  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
390  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
391  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
392  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0x03, 0xfe,
393  0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d, 0x0c, 0x7a,
394  0x08, 0x77, 0x80, 0x10, 0x21, 0x5c, 0xc2, 0xf1,
395  0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08,
396  0xca, 0x5a, 0x00, 0x01, 0x69, 0x28};
397 
398  csum = *( ((uint16_t *)(raw_ipv6 + 70)));
399 
400  FAIL_IF(TCPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
401  (uint16_t *)(raw_ipv6 + 54), 32, csum) == 0);
402  PASS;
403 }
404 
405 /** \test Get the wscale of 2 */
406 static int TCPGetWscaleTest01(void)
407 {
408  static uint8_t raw_tcp[] = {0xda, 0xc1, 0x00, 0x50, 0xb6, 0x21, 0x7f, 0x58,
409  0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0xd0,
410  0x8a, 0xaf, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
411  0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28,
412  0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02};
414  FAIL_IF_NULL(p);
415  IPV4Hdr ip4h;
416  ThreadVars tv;
418  memset(&tv, 0, sizeof(ThreadVars));
419  memset(&dtv, 0, sizeof(DecodeThreadVars));
420  memset(&ip4h, 0, sizeof(IPV4Hdr));
421 
422  p->src.family = AF_INET;
423  p->dst.family = AF_INET;
424  UTHSetIPV4Hdr(p, &ip4h);
425 
427  DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp));
428  FAIL_IF_NOT(PacketIsTCP(p));
429 
430  uint8_t wscale = TCP_GET_WSCALE(p);
431  FAIL_IF(wscale != 2);
432 
433  PacketFree(p);
434  FlowShutdown();
435  PASS;
436 }
437 
438 /** \test Get the wscale of 15, so see if return TCP_WSCALE_MAX properly */
439 static int TCPGetWscaleTest02(void)
440 {
441  static uint8_t raw_tcp[] = {0xda, 0xc1, 0x00, 0x50, 0xb6, 0x21, 0x7f, 0x58,
442  0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0xd0,
443  0x8a, 0xaf, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
444  0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28,
445  0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x0f};
447  FAIL_IF_NULL(p);
448  IPV4Hdr ip4h;
449  ThreadVars tv;
451 
452  memset(&tv, 0, sizeof(ThreadVars));
453  memset(&dtv, 0, sizeof(DecodeThreadVars));
454  memset(&ip4h, 0, sizeof(IPV4Hdr));
455 
456  p->src.family = AF_INET;
457  p->dst.family = AF_INET;
458  UTHSetIPV4Hdr(p, &ip4h);
459 
461  DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp));
462  FAIL_IF_NOT(PacketIsTCP(p));
463 
464  uint8_t wscale = TCP_GET_WSCALE(p);
465  FAIL_IF(wscale != TCP_WSCALE_MAX);
466 
467  PacketFree(p);
468  FlowShutdown();
469  PASS;
470 }
471 
472 /** \test Get the wscale, but it's missing, so see if return 0 properly */
473 static int TCPGetWscaleTest03(void)
474 {
475  static uint8_t raw_tcp[] = {0xda, 0xc1, 0x00, 0x50, 0xb6, 0x21, 0x7f, 0x59,
476  0xdd, 0xa3, 0x6f, 0xf8, 0x80, 0x10, 0x05, 0xb4,
477  0x7c, 0x70, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
478  0x00, 0x62, 0x88, 0x9e, 0x00, 0x00, 0x00, 0x00};
480  FAIL_IF_NULL(p);
481  IPV4Hdr ip4h;
482  ThreadVars tv;
484  memset(&tv, 0, sizeof(ThreadVars));
485  memset(&dtv, 0, sizeof(DecodeThreadVars));
486  memset(&ip4h, 0, sizeof(IPV4Hdr));
487 
488  p->src.family = AF_INET;
489  p->dst.family = AF_INET;
490  UTHSetIPV4Hdr(p, &ip4h);
491 
493  DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp));
494  FAIL_IF_NOT(PacketIsTCP(p));
495 
496  uint8_t wscale = TCP_GET_WSCALE(p);
497  FAIL_IF(wscale != 0);
498 
499  PacketFree(p);
500  FlowShutdown();
501  PASS;
502 }
503 
504 static int TCPGetSackTest01(void)
505 {
506  static uint8_t raw_tcp[] = {
507  0x00, 0x50, 0x06, 0xa6, 0xfa, 0x87, 0x0b, 0xf5,
508  0xf1, 0x59, 0x02, 0xe0, 0xa0, 0x10, 0x3e, 0xbc,
509  0x1d, 0xe7, 0x00, 0x00, 0x01, 0x01, 0x05, 0x12,
510  0xf1, 0x59, 0x13, 0xfc, 0xf1, 0x59, 0x1f, 0x64,
511  0xf1, 0x59, 0x08, 0x94, 0xf1, 0x59, 0x0e, 0x48 };
512  static uint8_t raw_tcp_sack[] = {
513  0xf1, 0x59, 0x13, 0xfc, 0xf1, 0x59, 0x1f, 0x64,
514  0xf1, 0x59, 0x08, 0x94, 0xf1, 0x59, 0x0e, 0x48 };
516  FAIL_IF_NULL(p);
517 
518  IPV4Hdr ip4h;
519  ThreadVars tv;
521  memset(&tv, 0, sizeof(ThreadVars));
522  memset(&dtv, 0, sizeof(DecodeThreadVars));
523  memset(&ip4h, 0, sizeof(IPV4Hdr));
524 
525  p->src.family = AF_INET;
526  p->dst.family = AF_INET;
527  UTHSetIPV4Hdr(p, &ip4h);
528 
530  DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp));
531 
532  FAIL_IF_NOT(PacketIsTCP(p));
533 
535 
536  int sack = TCP_GET_SACK_CNT(p);
537  FAIL_IF(sack != 2);
538 
539  const TCPHdr *tcph = PacketGetTCP(p);
540  const uint8_t *sackptr = TCP_GET_SACK_PTR(p, tcph);
541  FAIL_IF_NULL(sackptr);
542 
543  FAIL_IF(memcmp(sackptr, raw_tcp_sack, 16) != 0);
544 
545  PacketFree(p);
546  FlowShutdown();
547  PASS;
548 }
549 #endif /* UNITTESTS */
550 
552 {
553 #ifdef UNITTESTS
554  UtRegisterTest("TCPCalculateValidChecksumtest01",
555  TCPCalculateValidChecksumtest01);
556  UtRegisterTest("TCPCalculateInvalidChecksumtest02",
557  TCPCalculateInvalidChecksumtest02);
558  UtRegisterTest("TCPV6CalculateValidChecksumtest03",
559  TCPV6CalculateValidChecksumtest03);
560  UtRegisterTest("TCPV6CalculateInvalidChecksumtest04",
561  TCPV6CalculateInvalidChecksumtest04);
562  UtRegisterTest("TCPGetWscaleTest01", TCPGetWscaleTest01);
563  UtRegisterTest("TCPGetWscaleTest02", TCPGetWscaleTest02);
564  UtRegisterTest("TCPGetWscaleTest03", TCPGetWscaleTest03);
565  UtRegisterTest("TCPGetSackTest01", TCPGetSackTest01);
566 #endif /* UNITTESTS */
567 }
568 /**
569  * @}
570  */
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1240
decode-tcp.h
TCPVars_::ao_option_present
uint8_t ao_option_present
Definition: decode-tcp.h:165
Packet_::proto
uint8_t proto
Definition: decode.h:550
len
uint8_t len
Definition: app-layer-dnp3.h:2
TCPOpt_
Definition: decode-tcp.h:137
TCP_OPT_WS_LEN
#define TCP_OPT_WS_LEN
Definition: decode-tcp.h:60
TCP_OPT_MD5
#define TCP_OPT_MD5
Definition: decode-tcp.h:56
TCP_OPT_SACKOK
#define TCP_OPT_SACKOK
Definition: decode-tcp.h:50
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
TCPVars_::mss_set
uint8_t mss_set
Definition: decode-tcp.h:168
TCP_HAS_TFO
#define TCP_HAS_TFO(p)
Definition: decode-tcp.h:97
TCPVars_::ts_set
uint8_t ts_set
Definition: decode-tcp.h:166
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:101
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
TCP_OPT_DUPLICATE
@ TCP_OPT_DUPLICATE
Definition: decode-events.h:104
TCP_HEADER_LEN
#define TCP_HEADER_LEN
Definition: decode-tcp.h:28
Packet_::payload
uint8_t * payload
Definition: decode.h:640
type
uint8_t type
Definition: decode-sctp.h:0
TH_RST
#define TH_RST
Definition: decode-tcp.h:36
TCP_WSCALE_MAX
#define TCP_WSCALE_MAX
Definition: decode-tcp.h:69
UTHSetIPV4Hdr
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)
Definition: util-unittest-helper.c:251
TCP_OPT_SACKOK_LEN
#define TCP_OPT_SACKOK_LEN
Definition: decode-tcp.h:59
TCP_GET_RAW_HLEN
#define TCP_GET_RAW_HLEN(tcph)
Definition: decode-tcp.h:72
DecodeThreadVars_::counter_tcp_syn
StatsCounterId counter_tcp_syn
Definition: decode.h:1034
TCP_OPT_EXP2
#define TCP_OPT_EXP2
Definition: decode-tcp.h:55
TCP_HAS_MSS
#define TCP_HAS_MSS(p)
Definition: decode-tcp.h:96
TCPVars_::sack_ok
uint8_t sack_ok
Definition: decode-tcp.h:167
p
Packet * p
Definition: fuzz_dataset.c:30
TCP_GET_SACKOK
#define TCP_GET_SACKOK(p)
Definition: decode-tcp.h:102
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:641
TCP_OPT_EOL
#define TCP_OPT_EOL
Definition: decode-tcp.h:46
TCPOpt_::data
const uint8_t * data
Definition: decode-tcp.h:140
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
DecodeThreadVars_::counter_tcp
StatsCounterId counter_tcp
Definition: decode.h:1033
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
TCP_GET_WSCALE
#define TCP_GET_WSCALE(p)
Definition: decode-tcp.h:100
TCP_INVALID_OPTLEN
@ TCP_INVALID_OPTLEN
Definition: decode-events.h:100
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:574
TCPHdr_::th_flags
uint8_t th_flags
Definition: decode-tcp.h:155
decode.h
TCPVars_::ts_ecr
uint32_t ts_ecr
Definition: decode-tcp.h:177
TCPOpt_::type
uint8_t type
Definition: decode-tcp.h:138
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
TCP_OPT_MSS
#define TCP_OPT_MSS
Definition: decode-tcp.h:48
TCP_OPT_WS
#define TCP_OPT_WS
Definition: decode-tcp.h:49
TCPVars_::sack_offset
uint16_t sack_offset
Definition: decode-tcp.h:178
TCP_OPT_SACK_MAX_LEN
#define TCP_OPT_SACK_MAX_LEN
Definition: decode-tcp.h:64
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
PacketL4::L4Vars::tcp
TCPVars tcp
Definition: decode.h:503
Packet_::sp
Port sp
Definition: decode.h:535
TCP_GET_RAW_SRC_PORT
#define TCP_GET_RAW_SRC_PORT(tcph)
Definition: decode-tcp.h:74
StatsCounterIncr
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
Definition: counters.c:163
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:231
DecodeThreadVars_::counter_tcp_urg
StatsCounterId counter_tcp_urg
Definition: decode.h:1037
TH_ACK
#define TH_ACK
Definition: decode-tcp.h:38
Packet_
Definition: decode.h:528
TCP_GET_SACK_CNT
#define TCP_GET_SACK_CNT(p)
Definition: decode-tcp.h:104
TCP_OPT_WSCALE_OVER_MAX
@ TCP_OPT_WSCALE_OVER_MAX
Definition: decode-events.h:105
Packet_::l4
struct PacketL4 l4
Definition: decode.h:636
TCP_HAS_SACK
#define TCP_HAS_SACK(p)
Definition: decode-tcp.h:94
TCP_OPT_NOP
#define TCP_OPT_NOP
Definition: decode-tcp.h:47
TCP_HAS_TS
#define TCP_HAS_TS(p)
Definition: decode-tcp.h:95
TCPOpt_::len
uint8_t len
Definition: decode-tcp.h:139
TCP_GET_SACK_PTR
#define TCP_GET_SACK_PTR(p, tcph)
Definition: decode-tcp.h:103
DecodeTCPRegisterTests
void DecodeTCPRegisterTests(void)
Definition: decode-tcp.c:551
DecodeThreadVars_::counter_tcp_rst
StatsCounterId counter_tcp_rst
Definition: decode.h:1036
TCPVars_::tfo_set
uint8_t tfo_set
Definition: decode-tcp.h:169
TH_URG
#define TH_URG
Definition: decode-tcp.h:39
TCPVars_::wscale
uint8_t wscale
Definition: decode-tcp.h:172
decode-events.h
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:35
DecodeTCP
int DecodeTCP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-tcp.c:296
IPV4Hdr_
Definition: decode-ipv4.h:72
TCP_OPT_EXP1
#define TCP_OPT_EXP1
Definition: decode-tcp.h:54
TCPVars_::ts_val
uint32_t ts_val
Definition: decode-tcp.h:176
TCP_HLEN_TOO_SMALL
@ TCP_HLEN_TOO_SMALL
Definition: decode-events.h:99
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
TH_SYN
#define TH_SYN
Definition: decode-tcp.h:35
suricata-common.h
DecodeThreadVars_::counter_tcp_synack
StatsCounterId counter_tcp_synack
Definition: decode.h:1035
TCP_OPTMAX
#define TCP_OPTMAX
Definition: decode-tcp.h:30
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:718
packet.h
TCPVars_::md5_option_present
uint8_t md5_option_present
Definition: decode-tcp.h:164
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
TCP_OPT_SACK
#define TCP_OPT_SACK
Definition: decode-tcp.h:51
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:270
TCP_OPT_INVALID_LEN
@ TCP_OPT_INVALID_LEN
Definition: decode-events.h:103
TCP_GET_RAW_DST_PORT
#define TCP_GET_RAW_DST_PORT(tcph)
Definition: decode-tcp.h:75
SCNtohl
#define SCNtohl(x)
Definition: suricata-common.h:435
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:1015
TCP_OPTLENMAX
#define TCP_OPTLENMAX
Definition: decode-tcp.h:29
Address_::family
char family
Definition: decode.h:131
Packet_::dst
Address dst
Definition: decode.h:533
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1248
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
TCP_HAS_WSCALE
#define TCP_HAS_WSCALE(p)
Definition: decode-tcp.h:93
TCP_OPT_AO
#define TCP_OPT_AO
Definition: decode-tcp.h:57
likely
#define likely(expr)
Definition: util-optimize.h:32
TCPVars_::sack_cnt
uint8_t sack_cnt
Definition: decode-tcp.h:173
TCP_OPT_MSS_LEN
#define TCP_OPT_MSS_LEN
Definition: decode-tcp.h:62
TCP_OPT_TFO_MAX_LEN
#define TCP_OPT_TFO_MAX_LEN
Definition: decode-tcp.h:66
flow.h
Packet_::dp
Port dp
Definition: decode.h:543
TCP_OPT_TS_LEN
#define TCP_OPT_TS_LEN
Definition: decode-tcp.h:61
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
FlowSetupPacket
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to indicate workers should do a flow look...
Definition: flow-hash.c:528
TCPHdr_
Definition: decode-tcp.h:149
Packet_::src
Address src
Definition: decode.h:532
TCPVars_::sack_set
uint8_t sack_set
Definition: decode-tcp.h:171
PacketL4::vars
union PacketL4::L4Vars vars
TCP_PKT_TOO_SMALL
@ TCP_PKT_TOO_SMALL
Definition: decode-events.h:98
TCP_OPT_TFO
#define TCP_OPT_TFO
Definition: decode-tcp.h:53
TCPVars_::mss
uint16_t mss
Definition: decode-tcp.h:174
TCP_OPT_TS
#define TCP_OPT_TS
Definition: decode-tcp.h:52
TCPVars_::wscale_set
uint8_t wscale_set
Definition: decode-tcp.h:170