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 __DECODE_GRE_H__ 27 #define __DECODE_GRE_H__ 28 29 #ifndef IPPROTO_GRE 30 #define IPPROTO_GRE 47 31 #endif 32 33 #include "decode.h" 34 #include "threadvars.h" 35 36 typedef struct GREHdr_ 37 { 38 uint8_t flags; /**< GRE packet flags */ 39 uint8_t version; /**< GRE version */ 40 uint16_t ether_type; /**< ether type of the encapsulated traffic */ 41 42 } __attribute__((__packed__)) GREHdr; 43 44 /* Generic Routing Encapsulation Source Route Entries (SREs). 45 * The header is followed by a variable amount of Routing Information. 46 */ 47 typedef struct GRESreHdr_ 48 { 49 uint16_t af; /**< Address family */ 50 uint8_t sre_offset; 51 uint8_t sre_length; 52 } __attribute__((__packed__)) GRESreHdr; 53 54 #define GRE_VERSION_0 0x0000 55 #define GRE_VERSION_1 0x0001 56 57 #define GRE_HDR_LEN 4 58 #define GRE_CHKSUM_LEN 2 59 #define GRE_OFFSET_LEN 2 60 #define GRE_KEY_LEN 4 61 #define GRE_SEQ_LEN 4 62 #define GRE_SRE_HDR_LEN 4 63 #define GRE_PROTO_PPP 0x880b 64 65 #define GRE_FLAG_ISSET_CHKSUM(r) (r->flags & 0x80) 66 #define GRE_FLAG_ISSET_ROUTE(r) (r->flags & 0x40) 67 #define GRE_FLAG_ISSET_KY(r) (r->flags & 0x20) 68 #define GRE_FLAG_ISSET_SQ(r) (r->flags & 0x10) 69 #define GRE_FLAG_ISSET_SSR(r) (r->flags & 0x08) 70 #define GRE_FLAG_ISSET_RECUR(r) (r->flags & 0x07) 71 #define GRE_GET_VERSION(r) (r->version & 0x07) 72 #define GRE_GET_FLAGS(r) (r->version & 0xF8) 73 #define GRE_GET_PROTO(r) SCNtohs(r->ether_type) 74 75 #define GREV1_HDR_LEN 8 76 #define GREV1_ACK_LEN 4 77 #define GREV1_FLAG_ISSET_FLAGS(r) (r->version & 0x78) 78 #define GREV1_FLAG_ISSET_ACK(r) (r->version & 0x80) 79 80 void DecodeGRERegisterTests(void); 81 82 #endif /* __DECODE_GRE_H__ */ 83 84