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_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)->tcpvars.ts_val)
 
#define TCP_GET_TSECR(p)   ((p)->tcpvars.ts_ecr)
 
#define TCP_HAS_WSCALE(p)   ((p)->tcpvars.ws.type == TCP_OPT_WS)
 
#define TCP_HAS_SACK(p)   ((p)->tcpvars.sack.type == TCP_OPT_SACK)
 
#define TCP_HAS_SACKOK(p)   ((p)->tcpvars.sackok.type == TCP_OPT_SACKOK)
 
#define TCP_HAS_TS(p)   ((p)->tcpvars.ts_set)
 
#define TCP_HAS_MSS(p)   ((p)->tcpvars.mss.type == TCP_OPT_MSS)
 
#define TCP_HAS_TFO(p)   ((p)->tcpvars.tfo.type == TCP_OPT_TFO)
 
#define TCP_GET_WSCALE(p)
 
#define TCP_GET_SACKOK(p)   (TCP_HAS_SACKOK((p)) ? 1 : 0)
 
#define TCP_GET_SACK_PTR(p)   TCP_HAS_SACK((p)) ? (p)->tcpvars.sack.data : NULL
 
#define TCP_GET_SACK_CNT(p)   (TCP_HAS_SACK((p)) ? (((p)->tcpvars.sack.len - 2) / 8) : 0)
 
#define TCP_GET_MSS(p)   SCNtohs(*(uint16_t *)((p)->tcpvars.mss.data))
 
#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_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)
 
#define CLEAR_TCP_PACKET(p)
 

Typedefs

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

Functions

struct TCPHdr_ __attribute__ ((__packed__)) TCPHdr
 DNP3 link header. More...
 
void DecodeTCPRegisterTests (void)
 

Variables

uint16_t th_sport
 
uint16_t th_dport
 
uint32_t th_seq
 
uint32_t th_ack
 
uint8_t th_offx2
 
uint8_t th_flags
 
uint16_t th_win
 
uint16_t th_sum
 
uint16_t th_urp
 

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

◆ CLEAR_TCP_PACKET

#define CLEAR_TCP_PACKET (   p)
Value:
{ \
(p)->level4_comp_csum = -1; \
PACKET_CLEAR_L4VARS((p)); \
(p)->tcph = NULL; \
}

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

◆ TCP_GET_ACK

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

Definition at line 116 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 114 of file decode-tcp.h.

◆ TCP_GET_FLAGS

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

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

◆ TCP_GET_HLEN

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

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

◆ TCP_GET_MSS

#define TCP_GET_MSS (   p)    SCNtohs(*(uint16_t *)((p)->tcpvars.mss.data))

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

◆ TCP_GET_OFFSET

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

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

◆ TCP_GET_RAW_ACK

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

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

◆ TCP_GET_RAW_DST_PORT

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

Definition at line 75 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 80 of file decode-tcp.h.

◆ TCP_GET_RAW_SRC_PORT

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

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

◆ TCP_GET_RAW_SUM

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

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

◆ TCP_GET_RAW_URG_POINTER

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

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

◆ TCP_GET_RAW_WINDOW

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

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

◆ TCP_GET_RAW_X2

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

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

◆ TCP_GET_SACK_CNT

#define TCP_GET_SACK_CNT (   p)    (TCP_HAS_SACK((p)) ? (((p)->tcpvars.sack.len - 2) / 8) : 0)

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

◆ TCP_GET_SACK_PTR

#define TCP_GET_SACK_PTR (   p)    TCP_HAS_SACK((p)) ? (p)->tcpvars.sack.data : NULL

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

◆ TCP_GET_SACKOK

#define TCP_GET_SACKOK (   p)    (TCP_HAS_SACKOK((p)) ? 1 : 0)

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

◆ TCP_GET_SEQ

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

Definition at line 115 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 113 of file decode-tcp.h.

◆ TCP_GET_SUM

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

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

◆ TCP_GET_TSECR

#define TCP_GET_TSECR (   p)    ((p)->tcpvars.ts_ecr)

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

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

◆ TCP_GET_TSVAL

#define TCP_GET_TSVAL (   p)    ((p)->tcpvars.ts_val)

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

Definition at line 88 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 118 of file decode-tcp.h.

◆ TCP_GET_WINDOW

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

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

◆ TCP_GET_WSCALE

#define TCP_GET_WSCALE (   p)
Value:
(TCP_HAS_WSCALE((p)) ? \
(((*(uint8_t *)(p)->tcpvars.ws.data) <= TCP_WSCALE_MAX) ? \
(*(uint8_t *)((p)->tcpvars.ws.data)) : 0) : 0)

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 111 of file decode-tcp.h.

◆ TCP_HAS_MSS

#define TCP_HAS_MSS (   p)    ((p)->tcpvars.mss.type == TCP_OPT_MSS)

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

◆ TCP_HAS_SACK

#define TCP_HAS_SACK (   p)    ((p)->tcpvars.sack.type == TCP_OPT_SACK)

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

◆ TCP_HAS_SACKOK

#define TCP_HAS_SACKOK (   p)    ((p)->tcpvars.sackok.type == TCP_OPT_SACKOK)

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

◆ TCP_HAS_TFO

#define TCP_HAS_TFO (   p)    ((p)->tcpvars.tfo.type == TCP_OPT_TFO)

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

◆ TCP_HAS_TS

#define TCP_HAS_TS (   p)    ((p)->tcpvars.ts_set)

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

◆ TCP_HAS_WSCALE

#define TCP_HAS_WSCALE (   p)    ((p)->tcpvars.ws.type == TCP_OPT_WS)

Definition at line 93 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 126 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_FIN

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

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

◆ TCP_ISSET_FLAG_PUSH

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

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 129 of file decode-tcp.h.

◆ TCP_ISSET_FLAG_RES2

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

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

◆ TCP_ISSET_FLAG_RST

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

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

◆ TCP_ISSET_FLAG_SYN

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

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

◆ TCP_ISSET_FLAG_URG

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

Definition at line 127 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 77 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 78 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

◆ TCPOpt

typedef struct TCPOpt_ TCPOpt

◆ TCPOptSackRecord

◆ TCPVars

typedef struct TCPVars_ TCPVars

Function Documentation

◆ DecodeTCPRegisterTests()

void DecodeTCPRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

Variable Documentation

◆ th_ack

uint32_t th_ack

acknowledgement number

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

◆ th_dport

uint16_t th_dport

destination port

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

◆ th_flags

uint8_t th_flags

pkt flags

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

◆ th_offx2

uint8_t th_offx2

offset and reserved

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

◆ th_seq

uint32_t th_seq

sequence number

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

◆ th_sport

uint16_t th_sport

source port

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

◆ th_sum

uint16_t th_sum

checksum

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

◆ th_urp

uint16_t th_urp

urgent pointer

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

◆ th_win

uint16_t th_win

pkt window

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

TCP_WSCALE_MAX
#define TCP_WSCALE_MAX
Definition: decode-tcp.h:69
TCP_HAS_WSCALE
#define TCP_HAS_WSCALE(p)
Definition: decode-tcp.h:92