]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
adding vlah codec. changed directory names
authorJosh <jrosenba@cisco.com>
Thu, 17 Apr 2014 21:03:38 +0000 (17:03 -0400)
committerJosh <jrosenba@cisco.com>
Thu, 17 Apr 2014 21:03:38 +0000 (17:03 -0400)
15 files changed:
src/codecs/CMakeLists.txt
src/codecs/basic/CMakeLists.txt [moved from src/codecs/essential/CMakeLists.txt with 67% similarity]
src/codecs/basic/cd_eth.cc [moved from src/codecs/essential/cd_eth.cc with 100% similarity]
src/codecs/basic/cd_icmp4.cc [moved from src/codecs/essential/cd_icmp4.cc with 100% similarity]
src/codecs/basic/cd_icmp6.cc [moved from src/codecs/essential/cd_icmp6.cc with 100% similarity]
src/codecs/basic/cd_ipv4.cc [moved from src/codecs/essential/cd_ipv4.cc with 100% similarity]
src/codecs/basic/cd_ipv6.cc [moved from src/codecs/essential/cd_ipv6.cc with 100% similarity]
src/codecs/basic/cd_tcp.cc [moved from src/codecs/essential/cd_tcp.cc with 100% similarity]
src/codecs/basic/cd_udp.cc [moved from src/codecs/essential/cd_udp.cc with 100% similarity]
src/codecs/encode.cc
src/codecs/plugins/CMakeLists.txt
src/codecs/plugins/cd_vlan.cc [moved from src/codecs/tmp/prot_vlan.cc with 64% similarity]
src/codecs/tmp/prot_vlan.h [deleted file]
src/codecs/tmp/template.cc
src/network_inspectors/defrag/defrag.cc

index 8cc36982130901dadbca820d69b265c686c44005..5ac8dfd4acc3e63a848e7939bbcc0c4e40cdf219 100644 (file)
@@ -1,6 +1,6 @@
 
 
-add_subdirectory(essential)
+add_subdirectory(basic)
 add_subdirectory(plugins)
 add_subdirectory(chained)
 
@@ -32,7 +32,7 @@ add_library( codecs STATIC
 
 
 target_link_libraries( codecs
-    essential
+    basic_codecs
     codec_plugins
     protocols
     sfip
similarity index 67%
rename from src/codecs/essential/CMakeLists.txt
rename to src/codecs/basic/CMakeLists.txt
index c2de794fb3d29d305b016a96c97cd5342254994c..8887153925a8b4c48b41e4c5bf545ed13cef11f4 100644 (file)
@@ -1,7 +1,7 @@
 
 
 
-add_library( essential
+add_library( basic_codecs
     cd_icmp4.cc
     cd_icmp6.cc
     cd_ipv4.cc
@@ -11,6 +11,6 @@ add_library( essential
     cd_eth.cc
 )
 
-target_link_libraries( essential
+target_link_libraries( basic_codecs
     protocols
 )
index d625c93765c600d7c39dabb6a487961fce99142b..6f05bc5b958261dc5b646f68d3095e9b41e96130 100644 (file)
@@ -105,7 +105,8 @@ typedef struct {
 
 // PKT_MAX is sized to ensure that any reassembled packet
 // can accommodate a full datagram at innermost layer
-#define PKT_MAX (ETHERNET_HEADER_LEN + VLAN_HEADER_LEN + ETHERNET_MTU + IP_MAXPACKET)
+// 4 == VLAN_HEADER
+#define PKT_MAX (ETHERNET_HEADER_LEN + 4 + ETHERNET_MTU + IP_MAXPACKET)
 
 // all layer encoders look like this:
 typedef ENC_STATUS (*Encoder)(EncState*, Buffer* in, Buffer* out);
index c8bce02bc426d522bc4b17d25ccd10dcef2d081b..49a0b717c5663445aceaad4cc80fff9e22a8c045 100644 (file)
@@ -3,6 +3,7 @@ add_library( codec_plugins STATIC
     cd_swipe.cc
     cd_teredo.cc
     cd_gtp.cc
+    cd_vlan.cc
 )
 
 
similarity index 64%
rename from src/codecs/tmp/prot_vlan.cc
rename to src/codecs/plugins/cd_vlan.cc
index 4440289953bb48e930810e6081558dcd2f3f775d..d9d31a637c84441422606c810d36399735a55a1b 100644 (file)
 #include "config.h"
 #endif
 
-#include "generators.h"
-#include "decode.h"  
-#include "static_include.h"
+#include "protocols/packet.h"
+#include "codecs/decode_module.h"
+#include "codecs/codec_events.h"
+#include "codecs/decode.h"
 
 
-#include "decoder_includes.h"
-#include "prot_vlan.h"
-#include "prot_arp.h"
-#include "prot_ipv4.h"
-#include "prot_ipv6.h"
-#include "prot_ethloopback.h"
-#include "prot_pppoepkt.h"
 
 
 #define LEN_VLAN_LLC_OTHER (sizeof(VlanTagHdr) + sizeof(EthLlc) + sizeof(EthLlcOther))
 
 
-void VLAN::Decode(const uint8_t *pkt, const uint32_t len, 
-        Packet *p, uint16_t &p_hdr_len, uint16_t &next_prot_id)
+const uint16_t ETHERNET_TYPE_8021Q = 0x8100;
+
+
+
+namespace
+{
+
+class VlanCodec : public Codec
 {
-    dc.vlan++;
+public:
+    VlanCodec() : Codec("vlan"){};
+    ~VlanCodec();
+
+
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
+        Packet *, uint16_t &p_hdr_len, int &next_prot_id);
+
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
+    virtual void get_data_link_type(std::vector<int>&){};
+    
+};
 
-    if (p->greh != NULL)
-        dc.gre_vlan++;
+} // anonymous namespace
+
+
+
+bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
+        Packet *p, uint16_t &p_hdr_len, int &next_prot_id)
+{
+//    dc.vlan++;
+
+//    if (p->greh != NULL)
+//        dc.gre_vlan++;
 
     if(len < sizeof(VlanTagHdr))
     {
-        DecoderEvent(p, DECODE_BAD_VLAN, DECODE_BAD_VLAN_STR);
+        DecoderEvent(p, DECODE_BAD_VLAN);
 
         // TBD add decoder drop event for VLAN hdr len issue
-        dc.discards++;
+//        dc.discards++;
         p->iph = NULL;
         p->family = NO_IP;
-        return;
+        return false;
     }
 
-    p->vh = (VlanTagHdr *) pkt;
+    p->vh = (VlanTagHdr *) raw_pkt;
 
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Vlan traffic:\n");
                DebugMessage(DEBUG_DECODE, "   Priority: %d(0x%X)\n",
@@ -81,16 +101,15 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len,
     {
         if(len < sizeof(VlanTagHdr) + sizeof(EthLlc))
         {
-            DecoderEvent(p, DECODE_BAD_VLAN_ETHLLC,
-                            DECODE_BAD_VLAN_ETHLLC_STR);
+            DecoderEvent(p, DECODE_BAD_VLAN_ETHLLC);
 
-            dc.discards++;
+//            dc.discards++;
             p->iph = NULL;
             p->family = NO_IP;
-            return;
+            return false;
         }
 
-        p->ehllc = (EthLlc *) (pkt + sizeof(VlanTagHdr));
+        p->ehllc = (EthLlc *) (raw_pkt + sizeof(VlanTagHdr));
 
         DEBUG_WRAP(
                 DebugMessage(DEBUG_DECODE, "LLC Header:\n");
@@ -102,17 +121,16 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len,
         {
             if ( len < LEN_VLAN_LLC_OTHER )
             {
-                DecoderEvent(p, DECODE_BAD_VLAN_OTHER,
-                                DECODE_BAD_VLAN_OTHER_STR);
+                DecoderEvent(p, DECODE_BAD_VLAN_OTHER);
 
-                dc.discards++;
+//                dc.discards++;
                 p->iph = NULL;
                 p->family = NO_IP;
 
-                return;
+                return false;
             }
 
-            p->ehllcother = (EthLlcOther *) (pkt + sizeof(VlanTagHdr) + sizeof(EthLlc));
+            p->ehllcother = (EthLlcOther *) (raw_pkt + sizeof(VlanTagHdr) + sizeof(EthLlc));
 
             DEBUG_WRAP(
                     DebugMessage(DEBUG_DECODE, "LLC Other Header:\n");
@@ -128,19 +146,21 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len,
 //            PushLayer(PROTO_VLAN, p, pkt, sizeof(*p->vh));
 
             p_hdr_len = LEN_VLAN_LLC_OTHER;
-            next_prot_id = ntohs(p->ehllcother->proto_id)
+            next_prot_id = ntohs(p->ehllcother->proto_id);
         }
     }
     else
     {
         p_hdr_len = sizeof(VlanTagHdr);
-        next_prot_id = ntohs(p->vh->vth_proto)
+        next_prot_id = ntohs(p->vh->vth_proto);
 
     }
 
     return true;
 }
 
+#if 0
+
 /*
  * ENCODER
  */
@@ -148,20 +168,51 @@ void VLAN_Format (EncodeFlags, const Packet*, Packet* c, Layer* lyr)
 {
     c->vh = (VlanTagHdr*)lyr->start;
 }
+#endif
+
+
+
+void VlanCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_8021Q);
+}
+
+static Codec* ctor()
+{
+    return new VlanCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+static void sum()
+{
+//    sum_stats((PegCount*)&gdc, (PegCount*)&dc, array_size(dc_pegs));
+//    memset(&dc, 0, sizeof(dc));
+}
+
+static void stats()
+{
+//    show_percent_stats((PegCount*)&gdc, dc_pegs, array_size(dc_pegs),
+//        "decoder");
+}
+
 
 
-static const char* name = "vlan_decode";
+static const char* name = "VLAN";
 
-static const CodecApi tcp_api =
+static const CodecApi vlan_api =
 {
     { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    {ETHERNET_TYPE_8021Q},  
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
-    NULL, // ctor
-    NULL, // dtor
-    Vlan::Decode,
+    ctor, // ctor
+    dtor, // dtor
+    sum, // sum
+    stats  // stats
 };
 
diff --git a/src/codecs/tmp/prot_vlan.h b/src/codecs/tmp/prot_vlan.h
deleted file mode 100644 (file)
index 5f30392..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** 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
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*/
-
-
-#ifndef PROT_VLAN_H
-#define PROT_VLAN_H
-
-#include "encode.h"
-
-
-#define VLAN_HEADER_LEN 4
-#define ETHERNET_TYPE_8021Q 0x8100
-
-
-
-#endif
\ No newline at end of file
index 8a4feb70002aa45802f2bf6bc35a9254a5198fb9..aa6e1110b055ecfd901a733e29e4c9b12590a5f0 100644 (file)
@@ -83,9 +83,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
+static void sum()
+{
+//    sum_stats((PegCount*)&gdc, (PegCount*)&dc, array_size(dc_pegs));
+//    memset(&dc, 0, sizeof(dc));
+}
+
+static void stats()
+{
+//    show_percent_stats((PegCount*)&gdc, dc_pegs, array_size(dc_pegs),
+//        "decoder");
+}
+
+
+
 static const char* name = "name_codec";
 
-static const CodecApi ipv6_api =
+static const CodecApi codec_api =
 {
     { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
     NULL, // pinit
@@ -94,5 +108,7 @@ static const CodecApi ipv6_api =
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
+    sum, // sum
+    stats  // stats
 };
 
index 241c9deab7c63e67f9030d456c9fffb62f170e70..4e4d4b363a6fc5803a8ff0dea7e4c09e82e91db6 100644 (file)
@@ -95,7 +95,6 @@
 #include "snort_debug.h"
 #include "parser.h"
 #include "mstring.h"
-//#include "checksum.h"
 #include "perf_monitor/perf.h"
 #include "timersub.h"
 #include "fpcreate.h"