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 /**
26  * \file
27  *
28  * \author Victor Julien <victor@inliniac.net>
29  *
30  * Decode linkype null:
31  * http://www.tcpdump.org/linktypes.html
32  */
33 
34 #include "suricata-common.h"
35 #include "decode.h"
36 #include "decode-raw.h"
37 #include "decode-events.h"
38 
39 #include "util-validate.h"
40 #include "util-unittest.h"
41 #include "util-debug.h"
42 
43 #include "pkt-var.h"
44 #include "util-profiling.h"
45 #include "host.h"
46 
47 #define HDR_SIZE 4
48 
49 #define AF_INET6_BSD 24
50 #define AF_INET6_FREEBSD 28
51 #define AF_INET6_DARWIN 30
52 #define AF_INET6_LINUX 10
53 #define AF_INET6_SOLARIS 26
54 #define AF_INET6_WINSOCK 23
55 
57  const uint8_t *pkt, uint32_t len)
58 {
59  DEBUG_VALIDATE_BUG_ON(pkt == NULL);
60 
62 
63  if (unlikely(len < HDR_SIZE)) {
65  return TM_ECODE_FAILED;
66  }
67 
68  if (unlikely(GET_PKT_LEN(p) > HDR_SIZE + USHRT_MAX)) {
69  return TM_ECODE_FAILED;
70  }
71 #if __BYTE_ORDER__ == __BIG_ENDIAN
72  uint32_t type = pkt[0] | pkt[1] << 8 | pkt[2] << 16 | pkt[3] << 24;
73 #else
74  uint32_t type = *((uint32_t *)pkt);
75 #endif
76  switch(type) {
77  case AF_INET:
78  SCLogDebug("IPV4 Packet");
80  break;
81  case AF_INET6_BSD:
82  case AF_INET6_FREEBSD:
83  case AF_INET6_DARWIN:
84  case AF_INET6_LINUX:
85  case AF_INET6_SOLARIS:
86  case AF_INET6_WINSOCK:
87  SCLogDebug("IPV6 Packet");
89  break;
90  default:
91  SCLogDebug("Unknown Null packet type version %" PRIu32 "", type);
93  break;
94  }
95  return TM_ECODE_OK;
96 }
97 
98 #ifdef UNITTESTS
99 
100 #endif /* UNITTESTS */
101 
102 /**
103  * \brief Registers Null unit tests
104  */
106 {
107 #ifdef UNITTESTS
108 #endif /* UNITTESTS */
109 }
110 /**
111  * @}
112  */
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1036
host.h
decode-raw.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:169
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
HDR_SIZE
#define HDR_SIZE
Definition: decode-null.c:47
AF_INET6_BSD
#define AF_INET6_BSD
Definition: decode-null.c:49
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
util-unittest.h
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
DecodeNull
int DecodeNull(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-null.c:56
AF_INET6_WINSOCK
#define AF_INET6_WINSOCK
Definition: decode-null.c:54
decode.h
util-debug.h
type
uint8_t type
Definition: decode-icmpv4.h:0
AF_INET6_SOLARIS
#define AF_INET6_SOLARIS
Definition: decode-null.c:53
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:233
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
pkt-var.h
util-profiling.h
Packet_
Definition: decode.h:414
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv6.c:570
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:232
AF_INET6_LINUX
#define AF_INET6_LINUX
Definition: decode-null.c:52
DecodeNullRegisterTests
void DecodeNullRegisterTests(void)
Registers Null unit tests.
Definition: decode-null.c:105
decode-events.h
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:30
suricata-common.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
LTNULL_UNSUPPORTED_TYPE
@ LTNULL_UNSUPPORTED_TYPE
Definition: decode-events.h:159
util-validate.h
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:638
LTNULL_PKT_TOO_SMALL
@ LTNULL_PKT_TOO_SMALL
Definition: decode-events.h:158
AF_INET6_FREEBSD
#define AF_INET6_FREEBSD
Definition: decode-null.c:50
DecodeThreadVars_::counter_null
uint16_t counter_null
Definition: decode.h:663
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1044
DecodeIPV4
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv4.c:517
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:111
AF_INET6_DARWIN
#define AF_INET6_DARWIN
Definition: decode-null.c:51