suricata
decode-sctp.c
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  * \ingroup decode
20  *
21  * @{
22  */
23 
24 
25 /**
26  * \file
27  *
28  * \author Eric Leblond <eric@regit.org>
29  *
30  * Decode SCTP
31  */
32 
33 #include "suricata-common.h"
34 #include "decode.h"
35 #include "decode-sctp.h"
36 #include "decode-events.h"
37 #include "util-unittest.h"
38 #include "util-debug.h"
39 #include "util-optimize.h"
40 #include "flow.h"
41 
42 static int DecodeSCTPPacket(ThreadVars *tv, Packet *p, const uint8_t *pkt, uint16_t len)
43 {
44  if (unlikely(len < SCTP_HEADER_LEN)) {
46  return -1;
47  }
48 
49  p->sctph = (SCTPHdr *)pkt;
50 
51  SET_SCTP_SRC_PORT(p,&p->sp);
52  SET_SCTP_DST_PORT(p,&p->dp);
53 
54  p->payload = (uint8_t *)pkt + sizeof(SCTPHdr);
55  p->payload_len = len - sizeof(SCTPHdr);
56 
57  p->proto = IPPROTO_SCTP;
58 
59  return 0;
60 }
61 
63  const uint8_t *pkt, uint16_t len, PacketQueue *pq)
64 {
65  StatsIncr(tv, dtv->counter_sctp);
66 
67  if (unlikely(DecodeSCTPPacket(tv, p,pkt,len) < 0)) {
68  p->sctph = NULL;
69  return TM_ECODE_FAILED;
70  }
71 
72 #ifdef DEBUG
73  SCLogDebug("SCTP sp: %" PRIu32 " -> dp: %" PRIu32,
75 #endif
76 
77  FlowSetupPacket(p);
78 
79  return TM_ECODE_OK;
80 }
81 /**
82  * @}
83  */
#define SCTP_GET_DST_PORT(p)
Definition: decode-sctp.h:35
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to incidate workers should do a flow look...
Definition: flow-hash.c:407
#define SCLogDebug(...)
Definition: util-debug.h:335
#define SET_SCTP_DST_PORT(pkt, prt)
Definition: decode.h:207
#define unlikely(expr)
Definition: util-optimize.h:35
Port sp
Definition: decode.h:416
Port dp
Definition: decode.h:424
SCTPHdr * sctph
Definition: decode.h:527
uint8_t proto
Definition: decode.h:431
int DecodeSCTP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len, PacketQueue *pq)
Definition: decode-sctp.c:62
Structure to hold thread specific data for all decode modules.
Definition: decode.h:633
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:168
uint16_t counter_sctp
Definition: decode.h:657
#define SET_SCTP_SRC_PORT(pkt, prt)
Definition: decode.h:203
#define SCTP_HEADER_LEN
Definition: decode-sctp.h:28
#define SCTP_GET_SRC_PORT(p)
Definition: decode-sctp.h:34
uint8_t len
Per thread variable structure.
Definition: threadvars.h:57
uint16_t payload_len
Definition: decode.h:542
uint8_t * payload
Definition: decode.h:541
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1001