]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Basic MPLS decoder.
authorJason Ish <jason.ish@emulex.com>
Tue, 15 Jul 2014 19:48:34 +0000 (13:48 -0600)
committerJason Ish <jason.ish@emulex.com>
Mon, 20 Oct 2014 21:15:05 +0000 (15:15 -0600)
src/Makefile.am
src/decode-ethernet.c
src/decode-mpls.c [new file with mode: 0644]
src/decode-mpls.h [new file with mode: 0644]
src/decode.h

index 1bc2d8d9ea12ce874df5e1cb6e29833aa6ace5c7..8213892f1805d5f9296165788e3a6cf3e97559ad 100644 (file)
@@ -55,6 +55,7 @@ decode-tcp.c decode-tcp.h \
 decode-teredo.c decode-teredo.h \
 decode-udp.c decode-udp.h \
 decode-vlan.c decode-vlan.h \
+decode-mpls.c decode-mpls.h \
 defrag-config.c defrag-config.h \
 defrag.c defrag.h \
 defrag-hash.c defrag-hash.h \
index 6f34f947c9a35667870c345c0cd87b2e92d8ed6f..e5a920d1693216be7423096ff0b25708be8ecf66 100644 (file)
@@ -80,6 +80,11 @@ int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
             DecodeVLAN(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
                                  len - ETHERNET_HEADER_LEN, pq);
             break;
+        case ETHERNET_TYPE_MPLS_UNICAST:
+        case ETHERNET_TYPE_MPLS_MULTICAST:
+            DecodeMPLS(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
+                       len - ETHERNET_HEADER_LEN, pq);
+            break;
         default:
             SCLogDebug("p %p pkt %p ether type %04x not supported", p,
                        pkt, ntohs(p->ethh->eth_type));
diff --git a/src/decode-mpls.c b/src/decode-mpls.c
new file mode 100644 (file)
index 0000000..f8f6993
--- /dev/null
@@ -0,0 +1,63 @@
+/* Copyright (C) 2014 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
+ *
+ * \author Jason Ish <jason.ish@emulex.com>
+ *
+ * MPLS decoder.
+ */
+
+#include "suricata-common.h"
+#include "decode.h"
+
+#define MPLS_HEADER_LEN    4
+#define MPLS_BOTTOM(shim)  ((ntohl(shim) >> 8) & 0x1)
+#define MPLS_PROTO_IPV4    4
+#define MPLS_PROTO_IPV6    6
+
+int DecodeMPLS(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
+    uint16_t len, PacketQueue *pq)
+{
+    if (len < MPLS_HEADER_LEN) {
+        return TM_ECODE_FAILED;
+    }
+
+    uint32_t shim;
+    do {
+        shim = *(uint32_t *)pkt;
+        pkt += MPLS_HEADER_LEN;
+        len -= MPLS_HEADER_LEN;
+    } while (MPLS_BOTTOM(shim) == 0);
+
+    /* Best guess at inner packet. */
+    uint8_t ip_ver = pkt[0] >> 4;
+
+    switch (ip_ver) {
+    case MPLS_PROTO_IPV4:
+        return DecodeIPV4(tv, dtv, p, pkt, len, pq);
+        break;
+    case MPLS_PROTO_IPV6:
+        return DecodeIPV6(tv, dtv, p, pkt, len, pq);
+        break;
+    default:
+        break;
+    }
+
+    return TM_ECODE_FAILED;
+}
diff --git a/src/decode-mpls.h b/src/decode-mpls.h
new file mode 100644 (file)
index 0000000..0f2ad32
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (C) 2014 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
+ *
+ * \author Jason Ish <jason.ish@emulex.com>
+ *
+ * MPLS decoder.
+ */
+
+#ifndef __DECODE_MPLS_H__
+#define __DECODE_MPLS_H__
+
+#define ETHERNET_TYPE_MPLS_UNICAST   0x8847
+#define ETHERNET_TYPE_MPLS_MULTICAST 0x8848
+
+#endif /* !__DECODE_MPLS_H__ */
index 47535ab967573de14b3cb62e165514aa7a3040dd..ce2f42d3149ed93a3b5cb4591349419810b1a8d6 100644 (file)
@@ -79,6 +79,7 @@ enum PktSrcEnum {
 #include "decode-sctp.h"
 #include "decode-raw.h"
 #include "decode-vlan.h"
+#include "decode-mpls.h"
 
 #include "detect-reference.h"
 
@@ -855,6 +856,7 @@ int DecodeUDP(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, P
 int DecodeSCTP(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
 int DecodeGRE(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
 int DecodeVLAN(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
+int DecodeMPLS(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
 
 void AddressDebugPrint(Address *);