suricata
decode-gre.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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  * \file decode-gre.h
20  *
21  * \author Breno Silva <breno.silva@gmail.com>
22  *
23  * Generic Route Encapsulation (GRE) from RFC 1701.
24  */
25 
26 #ifndef SURICATA_DECODE_GRE_H
27 #define SURICATA_DECODE_GRE_H
28 
29 #ifndef IPPROTO_GRE
30 #define IPPROTO_GRE 47
31 #endif
32 
33 
34 typedef struct GREHdr_
35 {
36  uint8_t flags; /**< GRE packet flags */
37  uint8_t version; /**< GRE version */
38  uint16_t ether_type; /**< ether type of the encapsulated traffic */
39 
40 } __attribute__((__packed__)) GREHdr;
41 
42 /* Enhanced GRE header - https://tools.ietf.org/html/rfc2637#section-4.1 */
43 typedef struct GREPPtPHdr_ {
44  GREHdr greh; /** base GRE packet header */
45  uint16_t payload_length; /** PPP payload length */
46  uint16_t call_id; /** PPP peer id */
47 } __attribute__((__packed__)) GREPPtPHd;
48 
49 /* Generic Routing Encapsulation Source Route Entries (SREs).
50  * The header is followed by a variable amount of Routing Information.
51  */
52 typedef struct GRESreHdr_
53 {
54  uint16_t af; /**< Address family */
55  uint8_t sre_offset;
56  uint8_t sre_length;
57 } __attribute__((__packed__)) GRESreHdr;
58 
59 #define GRE_VERSION_0 0x0000
60 #define GRE_VERSION_1 0x0001
61 
62 #define GRE_HDR_LEN 4
63 #define GRE_CHKSUM_LEN 2
64 #define GRE_OFFSET_LEN 2
65 #define GRE_KEY_LEN 4
66 #define GRE_SEQ_LEN 4
67 #define GRE_SRE_HDR_LEN 4
68 #define GRE_PROTO_PPP 0x880b
69 
70 #define GRE_FLAG_ISSET_CHKSUM(r) (r->flags & 0x80)
71 #define GRE_FLAG_ISSET_ROUTE(r) (r->flags & 0x40)
72 #define GRE_FLAG_ISSET_KY(r) (r->flags & 0x20)
73 #define GRE_FLAG_ISSET_SQ(r) (r->flags & 0x10)
74 #define GRE_FLAG_ISSET_SSR(r) (r->flags & 0x08)
75 #define GRE_FLAG_ISSET_RECUR(r) (r->flags & 0x07)
76 #define GRE_GET_VERSION(r) (r->version & 0x07)
77 #define GRE_GET_FLAGS(r) (r->version & 0xF8)
78 #define GRE_GET_PROTO(r) SCNtohs(r->ether_type)
79 
80 #define GREV1_HDR_LEN 8
81 #define GREV1_ACK_LEN 4
82 #define GREV1_FLAG_ISSET_FLAGS(r) (r->version & 0x78)
83 #define GREV1_FLAG_ISSET_ACK(r) (r->version & 0x80)
84 
85 void DecodeGRERegisterTests(void);
86 
87 #endif /* SURICATA_DECODE_GRE_H */
DecodeGRERegisterTests
void DecodeGRERegisterTests(void)
this function registers unit tests for GRE decoder
Definition: decode-gre.c:395
GRESreHdr_::af
uint16_t af
Definition: decode-gre.h:54
GRESreHdr_::sre_length
uint8_t sre_length
Definition: decode-gre.h:56
GREHdr_::version
uint8_t version
Definition: decode-gre.h:37
__attribute__
struct GREHdr_ __attribute__((__packed__)) GREHdr
DNP3 link header.
Definition: decode-vlan.c:103
GREPPtPHdr_::greh
GREHdr greh
Definition: decode-gre.h:44
GRESreHdr_::sre_offset
uint8_t sre_offset
Definition: decode-gre.h:55
GREHdr_::ether_type
uint16_t ether_type
Definition: decode-gre.h:38
GREHdr_::flags
uint8_t flags
Definition: decode-gre.h:36
GREHdr_
Definition: decode-gre.h:35
GREPPtPHdr_::payload_length
uint16_t payload_length
Definition: decode-gre.h:45
GREPPtPHdr_
Definition: decode-gre.h:43
GRESreHdr_
Definition: decode-gre.h:53
GREPPtPHdr_::call_id
uint16_t call_id
Definition: decode-gre.h:46