suricata
decode-null.c
Go to the documentation of this file.
1 /* Copyright (C) 2015-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  * \file
26  *
27  * \author Victor Julien <victor@inliniac.net>
28  *
29  * Decode linktype null:
30  * http://www.tcpdump.org/linktypes.html
31  */
32 
33 #include "suricata-common.h"
34 #include "decode.h"
35 #include "decode-raw.h"
36 #include "decode-events.h"
37 
38 #include "util-validate.h"
39 #include "util-debug.h"
40 
41 #define HDR_SIZE 4
42 
43 #define AF_INET6_BSD 24
44 #define AF_INET6_FREEBSD 28
45 #define AF_INET6_DARWIN 30
46 #define AF_INET6_LINUX 10
47 #define AF_INET6_SOLARIS 26
48 #define AF_INET6_WINSOCK 23
49 
51  const uint8_t *pkt, uint32_t len)
52 {
53  DEBUG_VALIDATE_BUG_ON(pkt == NULL);
54 
56 
57  if (unlikely(len < HDR_SIZE)) {
59  return TM_ECODE_FAILED;
60  }
61 
62 #if __BYTE_ORDER__ == __BIG_ENDIAN
63  uint32_t type = pkt[0] | pkt[1] << 8 | pkt[2] << 16 | pkt[3] << 24;
64 #else
65  uint32_t type = *((uint32_t *)pkt);
66 #endif
67  switch(type) {
68  case AF_INET:
69  SCLogDebug("IPV4 Packet");
70  if (GET_PKT_LEN(p) - HDR_SIZE > USHRT_MAX) {
71  return TM_ECODE_FAILED;
72  }
73  DecodeIPV4(
74  tv, dtv, p, GET_PKT_DATA(p) + HDR_SIZE, (uint16_t)(GET_PKT_LEN(p) - HDR_SIZE));
75  break;
76  case AF_INET6_BSD:
77  case AF_INET6_FREEBSD:
78  case AF_INET6_DARWIN:
79  case AF_INET6_LINUX:
80  case AF_INET6_SOLARIS:
81  case AF_INET6_WINSOCK:
82  SCLogDebug("IPV6 Packet");
84  break;
85  default:
86  SCLogDebug("Unknown Null packet type version %" PRIu32 "", type);
88  break;
89  }
90  return TM_ECODE_OK;
91 }
92 
93 /**
94  * @}
95  */
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1231
decode-raw.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
type
uint8_t type
Definition: decode-sctp.h:0
p
Packet * p
Definition: fuzz_dataset.c:30
HDR_SIZE
#define HDR_SIZE
Definition: decode-null.c:41
AF_INET6_BSD
#define AF_INET6_BSD
Definition: decode-null.c:43
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
DecodeNull
int DecodeNull(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-null.c:50
AF_INET6_WINSOCK
#define AF_INET6_WINSOCK
Definition: decode-null.c:48
decode.h
util-debug.h
AF_INET6_SOLARIS
#define AF_INET6_SOLARIS
Definition: decode-null.c:47
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:210
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
StatsCounterIncr
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
Definition: counters.c:163
Packet_
Definition: decode.h:516
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:209
AF_INET6_LINUX
#define AF_INET6_LINUX
Definition: decode-null.c:46
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ipv6.c:551
decode-events.h
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:35
LTNULL_PKT_TOO_SMALL
@ LTNULL_PKT_TOO_SMALL
Definition: decode-events.h:171
suricata-common.h
DecodeThreadVars_::counter_null
StatsCounterId counter_null
Definition: decode.h:1028
LTNULL_UNSUPPORTED_TYPE
@ LTNULL_UNSUPPORTED_TYPE
Definition: decode-events.h:172
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
util-validate.h
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:995
AF_INET6_FREEBSD
#define AF_INET6_FREEBSD
Definition: decode-null.c:44
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1239
DecodeIPV4
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv4.c:515
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
AF_INET6_DARWIN
#define AF_INET6_DARWIN
Definition: decode-null.c:45