suricata
decode-tcp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TCPOpt_
 
struct  TCPOptSackRecord_
 
struct  TCPHdr_
 
struct  TCPVars_
 

Macros

#define TCP_HEADER_LEN   20
 
#define TCP_OPTLENMAX   40
 
#define TCP_OPTMAX
 
#define TH_FIN   0x01
 
#define TH_SYN   0x02
 
#define TH_RST   0x04
 
#define TH_PUSH   0x08
 
#define TH_ACK   0x10
 
#define TH_URG   0x20
 
#define TH_ECN   0x40
 
#define TH_CWR   0x80
 
#define TCP_OPT_EOL   0x00
 
#define TCP_OPT_NOP   0x01
 
#define TCP_OPT_MSS   0x02
 
#define TCP_OPT_WS   0x03
 
#define TCP_OPT_SACKOK   0x04
 
#define TCP_OPT_SACK   0x05
 
#define TCP_OPT_TS   0x08
 
#define TCP_OPT_TFO   0x22 /* TCP Fast Open */
 
#define TCP_OPT_EXP1   0xfd /* Experimental, could be TFO */
 
#define TCP_OPT_EXP2   0xfe /* Experimental, could be TFO */
 
#define TCP_OPT_MD5   0x13 /* 19: RFC 2385 TCP MD5 option */
 
#define TCP_OPT_AO   0x1d /* 29: RFC 5925 TCP AO option */
 
#define TCP_OPT_SACKOK_LEN   2
 
#define TCP_OPT_WS_LEN   3
 
#define TCP_OPT_TS_LEN   10
 
#define TCP_OPT_MSS_LEN   4
 
#define TCP_OPT_SACK_MIN_LEN   10 /* hdr 2, 1 pair 8 = 10 */
 
#define TCP_OPT_SACK_MAX_LEN   34 /* hdr 2, 4 pair 32= 34 */
 
#define TCP_OPT_TFO_MIN_LEN   4 /* kind, len, 2 bytes cookie: 4 */
 
#define TCP_OPT_TFO_MAX_LEN   18 /* kind, len, 18 */
 
#define TCP_WSCALE_MAX   14
 
#define TCP_GET_RAW_OFFSET(tcph)   (((tcph)->th_offx2 & 0xf0) >> 4)
 
#define TCP_GET_RAW_HLEN(tcph)   ((uint8_t)(TCP_GET_RAW_OFFSET((tcph)) << 2))
 
#define TCP_GET_RAW_X2(tcph)   (unsigned char)((tcph)->th_offx2 & 0x0f)
 
#define TCP_GET_RAW_SRC_PORT(tcph)   SCNtohs((tcph)->th_sport)
 
#define TCP_GET_RAW_DST_PORT(tcph)   SCNtohs((tcph)->th_dport)
 
#define TCP_SET_RAW_TCP_OFFSET(tcph, value)   ((tcph)->th_offx2 = (unsigned char)(((tcph)->th_offx2 & 0x0f) | (value << 4)))
 
#define TCP_SET_RAW_TCP_X2(tcph, value)   ((tcph)->th_offx2 = (unsigned char)(((tcph)->th_offx2 & 0xf0) | (value & 0x0f)))
 
#define TCP_GET_RAW_SEQ(tcph)   SCNtohl((tcph)->th_seq)
 
#define TCP_GET_RAW_ACK(tcph)   SCNtohl((tcph)->th_ack)
 
#define TCP_GET_RAW_WINDOW(tcph)   SCNtohs((tcph)->th_win)
 
#define TCP_GET_RAW_URG_POINTER(tcph)   SCNtohs((tcph)->th_urp)
 
#define TCP_GET_RAW_SUM(tcph)   SCNtohs((tcph)->th_sum)
 
#define TCP_GET_TSVAL(p)   ((p)->l4.vars.tcp.ts_val)
 
#define TCP_GET_TSECR(p)   ((p)->l4.vars.tcp.ts_ecr)
 
#define TCP_HAS_WSCALE(p)   ((p)->l4.vars.tcp.wscale_set)
 
#define TCP_HAS_SACK(p)   (p)->l4.vars.tcp.sack_set
 
#define TCP_HAS_TS(p)   ((p)->l4.vars.tcp.ts_set)
 
#define TCP_HAS_MSS(p)   ((p)->l4.vars.tcp.mss_set)
 
#define TCP_HAS_TFO(p)   ((p)->l4.vars.tcp.tfo_set)
 
#define TCP_GET_WSCALE(p)   (p)->l4.vars.tcp.wscale
 
#define TCP_GET_SACKOK(p)   (p)->l4.vars.tcp.sack_ok
 
#define TCP_GET_SACK_PTR(p, tcph)   ((uint8_t *)(tcph)) + (p)->l4.vars.tcp.sack_offset
 
#define TCP_GET_SACK_CNT(p)   (p)->l4.vars.tcp.sack_cnt
 
#define TCP_GET_MSS(p)   (p)->l4.vars.tcp.mss
 
#define TCP_GET_OFFSET(p)   TCP_GET_RAW_OFFSET((p)->tcph)
 
#define TCP_GET_X2(p)   TCP_GET_RAW_X2((p)->tcph)
 
#define TCP_GET_HLEN(p)   ((uint8_t)(TCP_GET_OFFSET((p)) << 2))
 
#define TCP_GET_SRC_PORT(p)   TCP_GET_RAW_SRC_PORT((p)->tcph)
 
#define TCP_GET_DST_PORT(p)   TCP_GET_RAW_DST_PORT((p)->tcph)
 
#define TCP_GET_SEQ(p)   TCP_GET_RAW_SEQ((p)->tcph)
 
#define TCP_GET_ACK(p)   TCP_GET_RAW_ACK((p)->tcph)
 
#define TCP_GET_WINDOW(p)   TCP_GET_RAW_WINDOW((p)->tcph)
 
#define TCP_GET_URG_POINTER(p)   TCP_GET_RAW_URG_POINTER((p)->tcph)
 
#define TCP_GET_SUM(p)   TCP_GET_RAW_SUM((p)->tcph)
 
#define TCP_GET_FLAGS(p)   (p)->tcph->th_flags
 
#define TCP_ISSET_FLAG_RAW_FIN(p)   ((tcph)->th_flags & TH_FIN)
 
#define TCP_ISSET_FLAG_RAW_SYN(p)   ((tcph)->th_flags & TH_SYN)
 
#define TCP_ISSET_FLAG_RAW_RST(p)   ((tcph)->th_flags & TH_RST)
 
#define TCP_ISSET_FLAG_RAW_PUSH(p)   ((tcph)->th_flags & TH_PUSH)
 
#define TCP_ISSET_FLAG_RAW_ACK(p)   ((tcph)->th_flags & TH_ACK)
 
#define TCP_ISSET_FLAG_RAW_URG(p)   ((tcph)->th_flags & TH_URG)
 
#define TCP_ISSET_FLAG_RAW_RES2(p)   ((tcph)->th_flags & TH_RES2)
 
#define TCP_ISSET_FLAG_RAW_RES1(p)   ((tcph)->th_flags & TH_RES1)
 
#define TCP_ISSET_FLAG_FIN(p)   ((p)->tcph->th_flags & TH_FIN)
 
#define TCP_ISSET_FLAG_SYN(p)   ((p)->tcph->th_flags & TH_SYN)
 
#define TCP_ISSET_FLAG_RST(p)   ((p)->tcph->th_flags & TH_RST)
 
#define TCP_ISSET_FLAG_PUSH(p)   ((p)->tcph->th_flags & TH_PUSH)
 
#define TCP_ISSET_FLAG_ACK(p)   ((p)->tcph->th_flags & TH_ACK)
 
#define TCP_ISSET_FLAG_URG(p)   ((p)->tcph->th_flags & TH_URG)
 
#define TCP_ISSET_FLAG_RES2(p)   ((p)->tcph->th_flags & TH_RES2)
 
#define TCP_ISSET_FLAG_RES1(p)   ((p)->tcph->th_flags & TH_RES1)
 

Typedefs

typedef struct TCPOpt_ TCPOpt
 
typedef struct TCPOptSackRecord_ TCPOptSackRecord
 
typedef struct TCPHdr_ TCPHdr
 
typedef struct TCPVars_ TCPVars
 

Functions

void DecodeTCPRegisterTests (void)
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t
Todo:
RAW* macro's should be returning the raw value, not the host order

Definition in file decode-tcp.h.

Macro Definition Documentation

◆ TCP_GET_ACK

#define TCP_GET_ACK (   p)    TCP_GET_RAW_ACK((p)->tcph)

Definition at line 114 of file decode-tcp.h.

◆ TCP_GET_DST_PORT

#define TCP_GET_DST_PORT (   p)    TCP_GET_RAW_DST_PORT((p)->tcph)

Definition at line 112 of file decode-tcp.h.

◆ TCP_GET_FLAGS

#define TCP_GET_FLAGS (   p)    (p)->tcph->th_flags

Definition at line 118 of file decode-tcp.h.

◆ TCP_GET_HLEN

#define TCP_GET_HLEN (   p)    ((uint8_t)(TCP_GET_OFFSET((p)) << 2))

Definition at line 110 of file decode-tcp.h.

◆ TCP_GET_MSS

#define TCP_GET_MSS (   p)    (p)->l4.vars.tcp.mss

Definition at line 106 of file decode-tcp.h.

◆ TCP_GET_OFFSET

#define TCP_GET_OFFSET (   p)    TCP_GET_RAW_OFFSET((p)->tcph)

Definition at line 108 of file decode-tcp.h.

◆ TCP_GET_RAW_ACK

#define TCP_GET_RAW_ACK (   tcph)    SCNtohl((tcph)->th_ack)

Definition at line 82 of file decode-tcp.h.

◆ TCP_GET_RAW_DST_PORT

#define TCP_GET_RAW_DST_PORT (   tcph)    SCNtohs((tcph)->th_dport)

Definition at line 76 of file decode-tcp.h.

◆ TCP_GET_RAW_HLEN

#define TCP_GET_RAW_HLEN (   tcph)    ((uint8_t)(TCP_GET_RAW_OFFSET((tcph)) << 2))

Definition at line 73 of file decode-tcp.h.

◆ TCP_GET_RAW_OFFSET

#define TCP_GET_RAW_OFFSET (   tcph)    (((tcph)->th_offx2 & 0xf0) >> 4)

Definition at line 72 of file decode-tcp.h.

◆ TCP_GET_RAW_SEQ

#define TCP_GET_RAW_SEQ (   tcph)    SCNtohl((tcph)->th_seq)

Definition at line 81 of file decode-tcp.h.

◆ TCP_GET_RAW_SRC_PORT

#define TCP_GET_RAW_SRC_PORT (   tcph)    SCNtohs((tcph)->th_sport)

Definition at line 75 of file decode-tcp.h.

◆ TCP_GET_RAW_SUM

#define TCP_GET_RAW_SUM (   tcph)    SCNtohs((tcph)->th_sum)

Definition at line 86 of file decode-tcp.h.

◆ TCP_GET_RAW_URG_POINTER

#define TCP_GET_RAW_URG_POINTER (   tcph)    SCNtohs((tcph)->th_urp)

Definition at line 85 of file decode-tcp.h.

◆ TCP_GET_RAW_WINDOW

#define TCP_GET_RAW_WINDOW (   tcph)    SCNtohs((tcph)->th_win)

Definition at line 84 of file decode-tcp.h.

◆ TCP_GET_RAW_X2

#define TCP_GET_RAW_X2 (   tcph)    (unsigned char)((tcph)->th_offx2 & 0x0f)

Definition at line 74 of file decode-tcp.h.

◆ TCP_GET_SACK_CNT

#define TCP_GET_SACK_CNT (   p)    (p)->l4.vars.tcp.sack_cnt

Definition at line 105 of file decode-tcp.h.

◆ TCP_GET_SACK_PTR

#define TCP_GET_SACK_PTR (   p,
  tcph 
)    ((uint8_t *)(tcph)) + (p)->l4.vars.tcp.sack_offset

Definition at line 104 of file decode-tcp.h.

◆ TCP_GET_SACKOK

#define TCP_GET_SACKOK (   p)    (p)->l4.vars.tcp.sack_ok

Definition at line 103 of file decode-tcp.h.

◆ TCP_GET_SEQ

#define TCP_GET_SEQ (   p)    TCP_GET_RAW_SEQ((p)->tcph)

Definition at line 113 of file decode-tcp.h.

◆ TCP_GET_SRC_PORT

#define TCP_GET_SRC_PORT (   p)    TCP_GET_RAW_SRC_PORT((p)->tcph)

Definition at line 111 of file decode-tcp.h.

◆ TCP_GET_SUM

#define TCP_GET_SUM (   p)    TCP_GET_RAW_SUM((p)->tcph)

Definition at line 117 of file decode-tcp.h.

◆ TCP_GET_TSECR

#define TCP_GET_TSECR (   p)    ((p)->l4.vars.tcp.ts_ecr)

macro for getting the second timestamp from the packet in host order.

Definition at line 92 of file decode-tcp.h.

◆ TCP_GET_TSVAL

#define TCP_GET_TSVAL (   p)    ((p)->l4.vars.tcp.ts_val)

macro for getting the first timestamp from the packet in host order

Definition at line 89 of file decode-tcp.h.

◆ TCP_GET_URG_POINTER

#define TCP_GET_URG_POINTER (   p)    TCP_GET_RAW_URG_POINTER((p)->tcph)

Definition at line 116 of file decode-tcp.h.

◆ TCP_GET_WINDOW

#define TCP_GET_WINDOW (   p)    TCP_GET_RAW_WINDOW((p)->tcph)

Definition at line 115 of file decode-tcp.h.

◆ TCP_GET_WSCALE

#define TCP_GET_WSCALE (   p)    (p)->l4.vars.tcp.wscale

macro for getting the wscale from the packet.

Definition at line 101 of file decode-tcp.h.

◆ TCP_GET_X2

#define TCP_GET_X2 (   p)    TCP_GET_RAW_X2((p)->tcph)

Definition at line 109 of file decode-tcp.h.

◆ TCP_HAS_MSS

#define TCP_HAS_MSS (   p)    ((p)->l4.vars.tcp.mss_set)

Definition at line 97 of file decode-tcp.h.

◆ TCP_HAS_SACK

#define TCP_HAS_SACK (   p)    (p)->l4.vars.tcp.sack_set

Definition at line 95 of file decode-tcp.h.

◆ TCP_HAS_TFO

#define TCP_HAS_TFO (   p)    ((p)->l4.vars.tcp.tfo_set)

Definition at line 98 of file decode-tcp.h.

◆ TCP_HAS_TS

#define TCP_HAS_TS (   p)    ((p)->l4.vars.tcp.ts_set)

Definition at line 96 of file decode-tcp.h.

◆ TCP_HAS_WSCALE

#define TCP_HAS_WSCALE (   p)    ((p)->l4.vars.tcp.wscale_set)

Definition at line 94 of file decode-tcp.h.

◆ TCP_HEADER_LEN

#define TCP_HEADER_LEN   20

Definition at line 29 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_ACK

#define TCP_ISSET_FLAG_ACK (   p)    ((p)->tcph->th_flags & TH_ACK)

Definition at line 133 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_FIN

#define TCP_ISSET_FLAG_FIN (   p)    ((p)->tcph->th_flags & TH_FIN)

Definition at line 129 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_PUSH

#define TCP_ISSET_FLAG_PUSH (   p)    ((p)->tcph->th_flags & TH_PUSH)

Definition at line 132 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_ACK

#define TCP_ISSET_FLAG_RAW_ACK (   p)    ((tcph)->th_flags & TH_ACK)

Definition at line 124 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_FIN

#define TCP_ISSET_FLAG_RAW_FIN (   p)    ((tcph)->th_flags & TH_FIN)

Definition at line 120 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_PUSH

#define TCP_ISSET_FLAG_RAW_PUSH (   p)    ((tcph)->th_flags & TH_PUSH)

Definition at line 123 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_RES1

#define TCP_ISSET_FLAG_RAW_RES1 (   p)    ((tcph)->th_flags & TH_RES1)

Definition at line 127 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_RES2

#define TCP_ISSET_FLAG_RAW_RES2 (   p)    ((tcph)->th_flags & TH_RES2)

Definition at line 126 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_RST

#define TCP_ISSET_FLAG_RAW_RST (   p)    ((tcph)->th_flags & TH_RST)

Definition at line 122 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_SYN

#define TCP_ISSET_FLAG_RAW_SYN (   p)    ((tcph)->th_flags & TH_SYN)

Definition at line 121 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RAW_URG

#define TCP_ISSET_FLAG_RAW_URG (   p)    ((tcph)->th_flags & TH_URG)

Definition at line 125 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RES1

#define TCP_ISSET_FLAG_RES1 (   p)    ((p)->tcph->th_flags & TH_RES1)

Definition at line 136 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RES2

#define TCP_ISSET_FLAG_RES2 (   p)    ((p)->tcph->th_flags & TH_RES2)

Definition at line 135 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RST

#define TCP_ISSET_FLAG_RST (   p)    ((p)->tcph->th_flags & TH_RST)

Definition at line 131 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_SYN

#define TCP_ISSET_FLAG_SYN (   p)    ((p)->tcph->th_flags & TH_SYN)

Definition at line 130 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_URG

#define TCP_ISSET_FLAG_URG (   p)    ((p)->tcph->th_flags & TH_URG)

Definition at line 134 of file decode-tcp.h.

◆ TCP_OPT_AO

#define TCP_OPT_AO   0x1d /* 29: RFC 5925 TCP AO option */

Definition at line 58 of file decode-tcp.h.

◆ TCP_OPT_EOL

#define TCP_OPT_EOL   0x00

Definition at line 47 of file decode-tcp.h.

◆ TCP_OPT_EXP1

#define TCP_OPT_EXP1   0xfd /* Experimental, could be TFO */

Definition at line 55 of file decode-tcp.h.

◆ TCP_OPT_EXP2

#define TCP_OPT_EXP2   0xfe /* Experimental, could be TFO */

Definition at line 56 of file decode-tcp.h.

◆ TCP_OPT_MD5

#define TCP_OPT_MD5   0x13 /* 19: RFC 2385 TCP MD5 option */

Definition at line 57 of file decode-tcp.h.

◆ TCP_OPT_MSS

#define TCP_OPT_MSS   0x02

Definition at line 49 of file decode-tcp.h.

◆ TCP_OPT_MSS_LEN

#define TCP_OPT_MSS_LEN   4

Definition at line 63 of file decode-tcp.h.

◆ TCP_OPT_NOP

#define TCP_OPT_NOP   0x01

Definition at line 48 of file decode-tcp.h.

◆ TCP_OPT_SACK

#define TCP_OPT_SACK   0x05

Definition at line 52 of file decode-tcp.h.

◆ TCP_OPT_SACK_MAX_LEN

#define TCP_OPT_SACK_MAX_LEN   34 /* hdr 2, 4 pair 32= 34 */

Definition at line 65 of file decode-tcp.h.

◆ TCP_OPT_SACK_MIN_LEN

#define TCP_OPT_SACK_MIN_LEN   10 /* hdr 2, 1 pair 8 = 10 */

Definition at line 64 of file decode-tcp.h.

◆ TCP_OPT_SACKOK

#define TCP_OPT_SACKOK   0x04

Definition at line 51 of file decode-tcp.h.

◆ TCP_OPT_SACKOK_LEN

#define TCP_OPT_SACKOK_LEN   2

Definition at line 60 of file decode-tcp.h.

◆ TCP_OPT_TFO

#define TCP_OPT_TFO   0x22 /* TCP Fast Open */

Definition at line 54 of file decode-tcp.h.

◆ TCP_OPT_TFO_MAX_LEN

#define TCP_OPT_TFO_MAX_LEN   18 /* kind, len, 18 */

Definition at line 67 of file decode-tcp.h.

◆ TCP_OPT_TFO_MIN_LEN

#define TCP_OPT_TFO_MIN_LEN   4 /* kind, len, 2 bytes cookie: 4 */

Definition at line 66 of file decode-tcp.h.

◆ TCP_OPT_TS

#define TCP_OPT_TS   0x08

Definition at line 53 of file decode-tcp.h.

◆ TCP_OPT_TS_LEN

#define TCP_OPT_TS_LEN   10

Definition at line 62 of file decode-tcp.h.

◆ TCP_OPT_WS

#define TCP_OPT_WS   0x03

Definition at line 50 of file decode-tcp.h.

◆ TCP_OPT_WS_LEN

#define TCP_OPT_WS_LEN   3

Definition at line 61 of file decode-tcp.h.

◆ TCP_OPTLENMAX

#define TCP_OPTLENMAX   40

Definition at line 30 of file decode-tcp.h.

◆ TCP_OPTMAX

#define TCP_OPTMAX
Value:
20 /* every opt is at least 2 bytes
* (type + len), except EOL and NOP */

Definition at line 31 of file decode-tcp.h.

◆ TCP_SET_RAW_TCP_OFFSET

#define TCP_SET_RAW_TCP_OFFSET (   tcph,
  value 
)    ((tcph)->th_offx2 = (unsigned char)(((tcph)->th_offx2 & 0x0f) | (value << 4)))

Definition at line 78 of file decode-tcp.h.

◆ TCP_SET_RAW_TCP_X2

#define TCP_SET_RAW_TCP_X2 (   tcph,
  value 
)    ((tcph)->th_offx2 = (unsigned char)(((tcph)->th_offx2 & 0xf0) | (value & 0x0f)))

Definition at line 79 of file decode-tcp.h.

◆ TCP_WSCALE_MAX

#define TCP_WSCALE_MAX   14

Max valid wscale value.

Definition at line 70 of file decode-tcp.h.

◆ TH_ACK

#define TH_ACK   0x10

Definition at line 39 of file decode-tcp.h.

◆ TH_CWR

#define TH_CWR   0x80

Echo Congestion flag

Definition at line 44 of file decode-tcp.h.

◆ TH_ECN

#define TH_ECN   0x40

Establish a new connection reducing window

Definition at line 42 of file decode-tcp.h.

◆ TH_FIN

#define TH_FIN   0x01

Definition at line 35 of file decode-tcp.h.

◆ TH_PUSH

#define TH_PUSH   0x08

Definition at line 38 of file decode-tcp.h.

◆ TH_RST

#define TH_RST   0x04

Definition at line 37 of file decode-tcp.h.

◆ TH_SYN

#define TH_SYN   0x02

Definition at line 36 of file decode-tcp.h.

◆ TH_URG

#define TH_URG   0x20

Definition at line 40 of file decode-tcp.h.

Typedef Documentation

◆ TCPHdr

typedef struct TCPHdr_ TCPHdr

◆ TCPOpt

typedef struct TCPOpt_ TCPOpt

◆ TCPOptSackRecord

◆ TCPVars

typedef struct TCPVars_ TCPVars

Function Documentation

◆ DecodeTCPRegisterTests()

void DecodeTCPRegisterTests ( void  )

Definition at line 532 of file decode-tcp.c.

References UtRegisterTest().

Here is the call graph for this function: