summaryrefslogtreecommitdiffstats
path: root/src/decode-gre.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
commita0aa2307322cd47bbf416810ac0292925e03be87 (patch)
tree37076262a026c4b48c8a0e84f44ff9187556ca35 /src/decode-gre.h
parentInitial commit. (diff)
downloadsuricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz
suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/decode-gre.h')
-rw-r--r--src/decode-gre.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/decode-gre.h b/src/decode-gre.h
new file mode 100644
index 0000000..adf576f
--- /dev/null
+++ b/src/decode-gre.h
@@ -0,0 +1,88 @@
+/* Copyright (C) 2007-2010 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file decode-gre.h
+ *
+ * \author Breno Silva <breno.silva@gmail.com>
+ *
+ * Generic Route Encapsulation (GRE) from RFC 1701.
+ */
+
+#ifndef __DECODE_GRE_H__
+#define __DECODE_GRE_H__
+
+#ifndef IPPROTO_GRE
+#define IPPROTO_GRE 47
+#endif
+
+
+typedef struct GREHdr_
+{
+ uint8_t flags; /**< GRE packet flags */
+ uint8_t version; /**< GRE version */
+ uint16_t ether_type; /**< ether type of the encapsulated traffic */
+
+} __attribute__((__packed__)) GREHdr;
+
+/* Enhanced GRE header - https://tools.ietf.org/html/rfc2637#section-4.1 */
+typedef struct GREPPtPHdr_ {
+ GREHdr greh; /** base GRE packet header */
+ uint16_t payload_length; /** PPP payload length */
+ uint16_t call_id; /** PPP peer id */
+} __attribute__((__packed__)) GREPPtPHd;
+
+/* Generic Routing Encapsulation Source Route Entries (SREs).
+ * The header is followed by a variable amount of Routing Information.
+ */
+typedef struct GRESreHdr_
+{
+ uint16_t af; /**< Address family */
+ uint8_t sre_offset;
+ uint8_t sre_length;
+} __attribute__((__packed__)) GRESreHdr;
+
+#define GRE_VERSION_0 0x0000
+#define GRE_VERSION_1 0x0001
+
+#define GRE_HDR_LEN 4
+#define GRE_CHKSUM_LEN 2
+#define GRE_OFFSET_LEN 2
+#define GRE_KEY_LEN 4
+#define GRE_SEQ_LEN 4
+#define GRE_SRE_HDR_LEN 4
+#define GRE_PROTO_PPP 0x880b
+
+#define GRE_FLAG_ISSET_CHKSUM(r) (r->flags & 0x80)
+#define GRE_FLAG_ISSET_ROUTE(r) (r->flags & 0x40)
+#define GRE_FLAG_ISSET_KY(r) (r->flags & 0x20)
+#define GRE_FLAG_ISSET_SQ(r) (r->flags & 0x10)
+#define GRE_FLAG_ISSET_SSR(r) (r->flags & 0x08)
+#define GRE_FLAG_ISSET_RECUR(r) (r->flags & 0x07)
+#define GRE_GET_VERSION(r) (r->version & 0x07)
+#define GRE_GET_FLAGS(r) (r->version & 0xF8)
+#define GRE_GET_PROTO(r) SCNtohs(r->ether_type)
+
+#define GREV1_HDR_LEN 8
+#define GREV1_ACK_LEN 4
+#define GREV1_FLAG_ISSET_FLAGS(r) (r->version & 0x78)
+#define GREV1_FLAG_ISSET_ACK(r) (r->version & 0x80)
+
+void DecodeGRERegisterTests(void);
+
+#endif /* __DECODE_GRE_H__ */
+