/src/suricata7/src/decode-sctp.c
Line | Count | Source |
1 | | /* Copyright (C) 2011-2021 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 | | |
38 | | #include "util-validate.h" |
39 | | #include "util-unittest.h" |
40 | | #include "util-debug.h" |
41 | | #include "util-optimize.h" |
42 | | #include "flow.h" |
43 | | |
44 | | static int DecodeSCTPPacket(ThreadVars *tv, Packet *p, const uint8_t *pkt, uint16_t len) |
45 | 5.14k | { |
46 | 5.14k | DEBUG_VALIDATE_BUG_ON(pkt == NULL); |
47 | | |
48 | 5.14k | if (unlikely(len < SCTP_HEADER_LEN)) { |
49 | 1.01k | ENGINE_SET_INVALID_EVENT(p, SCTP_PKT_TOO_SMALL); |
50 | 1.01k | return -1; |
51 | 1.01k | } |
52 | | |
53 | 4.13k | p->sctph = (SCTPHdr *)pkt; |
54 | | |
55 | 4.13k | SET_SCTP_SRC_PORT(p,&p->sp); |
56 | 4.13k | SET_SCTP_DST_PORT(p,&p->dp); |
57 | | |
58 | 4.13k | p->payload = (uint8_t *)pkt + sizeof(SCTPHdr); |
59 | 4.13k | p->payload_len = len - sizeof(SCTPHdr); |
60 | | |
61 | 4.13k | p->proto = IPPROTO_SCTP; |
62 | | |
63 | 4.13k | return 0; |
64 | 5.14k | } |
65 | | |
66 | | int DecodeSCTP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, |
67 | | const uint8_t *pkt, uint16_t len) |
68 | 5.14k | { |
69 | 5.14k | StatsIncr(tv, dtv->counter_sctp); |
70 | | |
71 | 5.14k | if (unlikely(DecodeSCTPPacket(tv, p,pkt,len) < 0)) { |
72 | 1.01k | CLEAR_SCTP_PACKET(p); |
73 | 1.01k | return TM_ECODE_FAILED; |
74 | 1.01k | } |
75 | | |
76 | | #ifdef DEBUG |
77 | | SCLogDebug("SCTP sp: %" PRIu32 " -> dp: %" PRIu32, |
78 | | SCTP_GET_SRC_PORT(p), SCTP_GET_DST_PORT(p)); |
79 | | #endif |
80 | | |
81 | 4.13k | FlowSetupPacket(p); |
82 | | |
83 | 4.13k | return TM_ECODE_OK; |
84 | 5.14k | } |
85 | | /** |
86 | | * @} |
87 | | */ |