suricata
decode-null.c
Go to the documentation of this file.
1 /* Copyright (C) 2015 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-unittest.h"
40 #include "util-debug.h"
41 
42 #include "pkt-var.h"
43 #include "util-profiling.h"
44 #include "host.h"
45 
46 #define HDR_SIZE 4
47 
48 int DecodeNull(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint32_t len, PacketQueue *pq)
49 {
50  StatsIncr(tv, dtv->counter_null);
51 
52  if (unlikely(len < HDR_SIZE)) {
54  return TM_ECODE_FAILED;
55  }
56 
57  if (unlikely(GET_PKT_LEN(p) > HDR_SIZE + USHRT_MAX)) {
58  return TM_ECODE_FAILED;
59  }
60 
61  uint32_t type = *((uint32_t *)pkt);
62  switch(type) {
63  case AF_INET:
64  SCLogDebug("IPV4 Packet");
65  DecodeIPV4(tv, dtv, p, GET_PKT_DATA(p)+HDR_SIZE, GET_PKT_LEN(p)-HDR_SIZE, pq);
66  break;
67  case AF_INET6:
68  SCLogDebug("IPV6 Packet");
69  DecodeIPV6(tv, dtv, p, GET_PKT_DATA(p)+HDR_SIZE, GET_PKT_LEN(p)-HDR_SIZE, pq);
70  break;
71  default:
72  SCLogDebug("Unknown Null packet type version %" PRIu32 "", type);
74  break;
75  }
76  return TM_ECODE_OK;
77 }
78 
79 #ifdef UNITTESTS
80 
81 #endif /* UNITTESTS */
82 
83 /**
84  * \brief Registers Null unit tests
85  */
87 {
88 #ifdef UNITTESTS
89 #endif /* UNITTESTS */
90 }
91 /**
92  * @}
93  */
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:991
#define SCLogDebug(...)
Definition: util-debug.h:335
void DecodeNullRegisterTests(void)
Registers Null unit tests.
Definition: decode-null.c:86
#define unlikely(expr)
Definition: util-optimize.h:35
uint16_t counter_null
Definition: decode.h:657
int DecodeNull(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint32_t len, PacketQueue *pq)
Definition: decode-null.c:48
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
Definition: decode-ipv4.c:532
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
Definition: decode-ipv6.c:584
uint8_t type
Structure to hold thread specific data for all decode modules.
Definition: decode.h:632
#define HDR_SIZE
Definition: decode-null.c:46
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:163
#define GET_PKT_DATA(p)
Definition: decode.h:223
uint8_t len
Per thread variable structure.
Definition: threadvars.h:57
#define GET_PKT_LEN(p)
Definition: decode.h:222
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:999