suricata
decode-sctp.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 Eric Leblond <eric@regit.org>
22  */
23 
24 #ifndef SURICATA_DECODE_SCTP_H
25 #define SURICATA_DECODE_SCTP_H
26 
27 /** size of the packet header without any chunk headers */
28 #define SCTP_HEADER_LEN 12
29 
30 /** size of a chunk header (type + flags + length) */
31 #define SCTP_CHUNK_HDR_LEN 4
32 
33 /** max number of chunks tracked per packet for detection/logging */
34 /** value chosen to keep per-packet overhead low while still allowing
35  * some room to track chunks.
36  * SCTP has no hard limit on the number of chunks per packet.
37  * A packet can carry as many chunks as fit within the MTU,
38  * though in practice most packets contain only a few chunks. */
39 #define SCTP_MAX_TRACKED_CHUNKS 16
40 
41 /** max number of DATA chunk payloads tracked per packet */
42 #define SCTP_MAX_DATA_CHUNKS 16
43 
44 /** DATA chunk overhead before user data (chunk hdr + TSN + SID + SSN + PPID) */
45 #define SCTP_DATA_CHUNK_HDR_LEN 16
46 
47 /* SCTP chunk types (RFC 4960 sec 3.2) */
48 #define SCTP_CHUNK_TYPE_DATA 0x00
49 #define SCTP_CHUNK_TYPE_INIT 0x01
50 #define SCTP_CHUNK_TYPE_INIT_ACK 0x02
51 #define SCTP_CHUNK_TYPE_SACK 0x03
52 #define SCTP_CHUNK_TYPE_HEARTBEAT 0x04
53 #define SCTP_CHUNK_TYPE_HB_ACK 0x05
54 #define SCTP_CHUNK_TYPE_ABORT 0x06
55 #define SCTP_CHUNK_TYPE_SHUTDOWN 0x07
56 #define SCTP_CHUNK_TYPE_SHUTDOWN_ACK 0x08
57 #define SCTP_CHUNK_TYPE_ERROR 0x09
58 #define SCTP_CHUNK_TYPE_COOKIE_ECHO 0x0A
59 #define SCTP_CHUNK_TYPE_COOKIE_ACK 0x0B
60 #define SCTP_CHUNK_TYPE_ECNE 0x0C
61 #define SCTP_CHUNK_TYPE_CWR 0x0D
62 #define SCTP_CHUNK_TYPE_SHUTDOWN_COMPLETE 0x0E
63 #define SCTP_CHUNK_TYPE_FORWARD_TSN 0xC0
64 
65 typedef struct SCTPHdr_ {
66  uint16_t sh_sport; /* source port */
67  uint16_t sh_dport; /* destination port */
68  uint32_t sh_vtag; /* verification tag, defined per flow */
69  uint32_t sh_sum; /* checksum, computed via crc32 */
70 } __attribute__((__packed__)) SCTPHdr;
71 
72 typedef struct SCTPChunkHdr_ {
73  uint8_t type;
74  uint8_t flags;
75  uint16_t length;
76 } __attribute__((__packed__)) SCTPChunkHdr;
77 
78 typedef struct SCTPVars_ {
79  uint16_t hlen; /**< total header length (common header + chunks) */
80  uint16_t chunk_cnt; /**< number of chunks parsed */
81  uint8_t tracked_chunk_cnt; /**< number of chunks tracked (capped at SCTP_MAX_TRACKED_CHUNKS) */
82  uint8_t chunk_types[SCTP_MAX_TRACKED_CHUNKS]; /**< types of first N chunks */
83  uint8_t data_chunk_cnt; /**< number of DATA chunk payloads tracked */
84  bool has_init : 1;
85  bool has_init_ack : 1;
86  bool has_data : 1;
87  bool has_abort : 1;
88  uint16_t data_offsets[SCTP_MAX_DATA_CHUNKS]; /**< offsets of DATA user data from L4 start */
89  uint16_t data_lens[SCTP_MAX_DATA_CHUNKS]; /**< lengths of DATA user data */
91 
92 #define SCTP_GET_RAW_SRC_PORT(sctph) SCNtohs((sctph)->sh_sport)
93 #define SCTP_GET_RAW_DST_PORT(sctph) SCNtohs((sctph)->sh_dport)
94 #define SCTP_GET_RAW_VTAG(sctph) SCNtohl((sctph)->sh_vtag)
95 #define SCTP_GET_RAW_SUM(sctph) SCNtohl((sctph)->sh_sum)
96 
97 void DecodeSCTPRegisterTests(void);
98 
99 #endif /* SURICATA_DECODE_SCTP_H */
SCTPVars_::chunk_types
uint8_t chunk_types[SCTP_MAX_TRACKED_CHUNKS]
Definition: decode-sctp.h:82
SCTPHdr_
Definition: decode-sctp.h:65
SCTPHdr_::sh_sport
uint16_t sh_sport
Definition: decode-sctp.h:66
SCTPVars_::chunk_cnt
uint16_t chunk_cnt
Definition: decode-sctp.h:80
SCTPChunkHdr_::type
uint8_t type
Definition: decode-sctp.h:73
SCTPVars_::has_init
bool has_init
Definition: decode-sctp.h:84
__attribute__
struct SCTPHdr_ __attribute__((__packed__)) SCTPHdr
DNP3 link header.
Definition: decode-vlan.c:102
SCTPVars_::data_offsets
uint16_t data_offsets[SCTP_MAX_DATA_CHUNKS]
Definition: decode-sctp.h:88
SCTPChunkHdr_::length
uint16_t length
Definition: decode-sctp.h:75
SCTP_MAX_DATA_CHUNKS
#define SCTP_MAX_DATA_CHUNKS
Definition: decode-sctp.h:42
SCTPHdr_::sh_vtag
uint32_t sh_vtag
Definition: decode-sctp.h:68
SCTPHdr_::sh_dport
uint16_t sh_dport
Definition: decode-sctp.h:67
SCTPVars_::has_abort
bool has_abort
Definition: decode-sctp.h:87
SCTP_MAX_TRACKED_CHUNKS
#define SCTP_MAX_TRACKED_CHUNKS
Definition: decode-sctp.h:39
SCTPVars
struct SCTPVars_ SCTPVars
SCTPVars_::tracked_chunk_cnt
uint8_t tracked_chunk_cnt
Definition: decode-sctp.h:81
DecodeSCTPRegisterTests
void DecodeSCTPRegisterTests(void)
Definition: decode-sctp.c:682
SCTPChunkHdr_
Definition: decode-sctp.h:72
SCTPVars_::has_data
bool has_data
Definition: decode-sctp.h:86
SCTPChunkHdr_::flags
uint8_t flags
Definition: decode-sctp.h:74
SCTPVars_::hlen
uint16_t hlen
Definition: decode-sctp.h:79
SCTPVars_::data_lens
uint16_t data_lens[SCTP_MAX_DATA_CHUNKS]
Definition: decode-sctp.h:89
SCTPHdr_::sh_sum
uint32_t sh_sum
Definition: decode-sctp.h:69
SCTPVars_::has_init_ack
bool has_init_ack
Definition: decode-sctp.h:85
SCTPVars_
Definition: decode-sctp.h:78
SCTPVars_::data_chunk_cnt
uint8_t data_chunk_cnt
Definition: decode-sctp.h:83