]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
ethertype's mapped to array of Codecs
authorJosh <jrosenba@cisco.com>
Mon, 28 Apr 2014 21:06:39 +0000 (17:06 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 28 Apr 2014 21:06:39 +0000 (17:06 -0400)
37 files changed:
src/codecs/CMakeLists.txt
src/codecs/basic/CMakeLists.txt
src/codecs/basic/cd_esp.cc
src/codecs/basic/cd_eth.cc
src/codecs/basic/cd_icmp4.cc
src/codecs/basic/cd_icmp6.cc
src/codecs/basic/cd_ipv4.cc
src/codecs/basic/cd_ipv6.cc
src/codecs/basic/cd_null.cc [moved from src/codecs/plugins/cd_none.cc with 59% similarity]
src/codecs/basic/cd_tcp.cc
src/codecs/basic/cd_udp.cc
src/codecs/codec_api.cc
src/codecs/codec_api.h
src/codecs/plugins/CMakeLists.txt
src/codecs/plugins/cd_ah.cc
src/codecs/plugins/cd_arp.cc
src/codecs/plugins/cd_dstopts.cc
src/codecs/plugins/cd_erspan2.cc
src/codecs/plugins/cd_erspan3.cc
src/codecs/plugins/cd_ethloopback.cc
src/codecs/plugins/cd_fragment.cc
src/codecs/plugins/cd_gre.cc
src/codecs/plugins/cd_gtp.cc
src/codecs/plugins/cd_hopopts.cc
src/codecs/plugins/cd_mpls.cc
src/codecs/plugins/cd_pppencap.cc
src/codecs/plugins/cd_pppoepkt.cc
src/codecs/plugins/cd_teredo.cc
src/codecs/plugins/cd_transbridge.cc
src/codecs/plugins/cd_vlan.cc
src/codecs/template.cc
src/events/CMakeLists.txt
src/events/codec_events.h
src/events/codec_events.h.bak [deleted file]
src/framework/codec.h
src/managers/packet_manager.cc
src/managers/packet_manager.h

index faaaa1ca822c586918146098d0d94e1176561e6c..403deb021ee8ca17aeed367fa9c5291a3408daf3 100644 (file)
@@ -19,8 +19,6 @@ endif(ENABLE_NON_ETHER_DECODERS)
 
 
 add_library( codecs STATIC
-    codec_events.cc
-    codec_events.h
     encode.h
     encode.cc
     decode.h
@@ -29,8 +27,6 @@ add_library( codecs STATIC
     decode_module.cc
     codec_api.h
     codec_api.cc
-    codec_stats.h
-    codec_stats.cc
 )
 
 
index 404d3c44f90d8bf9fd4b99edd76b369d213659fe..ba42052017cef0f2451f96a8d30d83a7454be379 100644 (file)
@@ -9,10 +9,12 @@ add_library( basic_codecs STATIC
     cd_tcp.cc
     cd_udp.cc
     cd_eth.cc
-    cd_esp.cc  # Incluse esp here because it MUST be statically linked due to its dependance on the packet manager
+    cd_esp.cc  # due to its dependance on the packet manager, esp must be statically linked.
+    cd_null.cc
 )
 
 target_link_libraries( basic_codecs
     protocols
     framework
+    events
 )
index ce70f10252ff96fae5bc68d50db8a48f1f6d0024..650bfc21a105ea32c1d5530c662b2f550fe0d25c 100644 (file)
@@ -37,10 +37,11 @@ namespace
 class EspCodec : public Codec
 {
 public:
-    EspCodec() : Codec("ESP"){};
+    EspCodec() : Codec("esp"){};
     ~EspCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -53,22 +54,14 @@ const uint32_t ESP_HEADER_LEN = 8;
 const uint32_t ESP_AUTH_DATA_LEN = 12;
 const uint32_t ESP_TRAILER_LEN = 2;
 
-struct CdPegs{
-    PegCount processed = 0;
-    PegCount discards = 0;
-};
-
-std::vector<const char*> peg_names =
-{
-    "NameCodec_processed",
-    "NameCodec_discards",
-};
+} // anonymous namespace
 
 
-} // anonymous namespace
 
-static THREAD_LOCAL CdPegs counts;
-static CdPegs gcounts;
+void EspCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ESP_PROT_ID);
+}
 
 
 
@@ -153,11 +146,6 @@ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     return true;
 }
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ESP_PROT_ID);
-}
-
 static Codec* ctor()
 {
     return new EspCodec();
@@ -168,18 +156,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "esp_codec";
+static const char* name = "esp";
 static const CodecApi esp_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    { 
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL, // get_dlt()
-    get_protocol_ids,
 };
 
 
index ac81d9bdbf17a2f246f48aa95230212b1ec3719b..312b41290b0f6c1da5bcf8ddba6ff99b7a95fb74 100644 (file)
@@ -38,10 +38,12 @@ namespace
 class EthCodec : public Codec
 {
 public:
-    EthCodec() : Codec("Eth"){};
+    EthCodec() : Codec("eth"){};
     ~EthCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v) {};
+    virtual void get_data_link_type(std::vector<int>&);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id);
 
@@ -54,6 +56,11 @@ public:
 } // anonymous
 
 
+void EthCodec::get_data_link_type(std::vector<int>&v)
+{
+    v.push_back(DLT_EN10MB);
+}
+
 
 //--------------------------------------------------------------------
 // decode.c::Ethernet
@@ -210,12 +217,6 @@ void Eth_Format (EncodeFlags f, const Packet* p, Packet* c, Layer* lyr)
 // api
 //-------------------------------------------------------------------------
 
-static void get_data_link_type(std::vector<int>&v)
-{
-    v.push_back(DLT_EN10MB);
-}
-
-
 static Codec* ctor()
 {
     return new EthCodec();
@@ -226,19 +227,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "eth_codec";
-
+static const char* name = "eth";
 static const CodecApi eth_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    { 
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    get_data_link_type,
-    NULL,
 };
 
 const BaseApi* cd_eth = &eth_api.base;
index aa2df3cfeaf8a743e757e802c8230b6259db2bae..19a88834920e187e518a7a7b386522c711aeeb3e 100644 (file)
@@ -49,6 +49,7 @@ public:
     Icmp4Codec() : Codec("icmp4"){};
     ~Icmp4Codec() {};
     
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id);
 
@@ -68,6 +69,11 @@ private:
 } // namespace
 
 
+void Icmp4Codec::get_protocol_ids(std::vector<uint16_t> &v)
+{
+    v.push_back(IPPROTO_ICMP);
+}
+
 
 
 
@@ -554,24 +560,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static void get_protocol_ids(std::vector<uint16_t> &proto_ids)
-{
-    proto_ids.push_back(IPPROTO_ICMP);
-}
-
-static const char* name = "icmp4_codec";
-
+static const char* name = "icmp4";
 static const CodecApi icmp4_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    { 
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids,
 };
 
 
index ed769145d0068868ce124f2ccda92e1a0d4e267f..37aab620612784f64a26352a0f178aca4701fc88 100644 (file)
@@ -39,13 +39,15 @@ namespace
 class Icmp6Codec : public Codec
 {
 public:
-    Icmp6Codec() : Codec("Icmp6"){};
+    Icmp6Codec() : Codec("icmp6"){};
     ~Icmp6Codec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
+
     // DELETE from here and below
     #include "codecs/sf_protocols.h"
     virtual inline PROTO_ID get_proto_id() { return PROTO_ICMP6; };
@@ -57,6 +59,12 @@ public:
 } // anonymous namespace
 
 
+void Icmp6Codec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_ICMPV6);
+}
+
+
 
 static void DecodeICMPEmbeddedIP6(const uint8_t *pkt, const uint32_t len, Packet *p);
 static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int);
@@ -597,11 +605,6 @@ static unsigned short in_chksum_icmp6(pseudoheader6 *ph,
 }
 
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(IPPROTO_ICMPV6);
-}
-
 static Codec* ctor()
 {
     return new Icmp6Codec();
@@ -612,19 +615,24 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "icmp6_codec";
+static const char* name = "icmp6";
 
 static const CodecApi ipv6_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids
 };
 
 
index 706762771e831bf3e15654d592e86e6f6161a2b2..1b64e2d8b033bd95aaa10ebc044dbb3aae9c5c70 100644 (file)
@@ -51,6 +51,7 @@ public:
     Ipv4Codec() : Codec("ipv4"){};
     ~Ipv4Codec(){};
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_packet, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -91,6 +92,12 @@ static inline unsigned short in_chksum_ip( unsigned short *, int);
 static void DecodeIPOptions(const uint8_t *start, uint32_t o_len, Packet *p);
 
 
+void Ipv4Codec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ipv4::ethertype_ip());
+    v.push_back(ipv4::prot_id());
+}
+
 //--------------------------------------------------------------------
 // prot_ipv4.cc::IP4 decoder
 //--------------------------------------------------------------------
@@ -984,25 +991,23 @@ static void dtor(Codec *cd)
 }
 
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ipv4::ethertype_ip());
-    v.push_back(ipv4::prot_id());
-}
-
-static const char* name = "ipv4_decode";
-
+static const char* name = "ipv4";
 static const CodecApi ipv4_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    { 
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
     ipv4_codec_ginit, // pinit
     ipv4_codec_gterm, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL, 
-    get_protocol_ids,
 };
 
 
index 3a927ac961bd475d94a9a4f3f1ed51ed605b7ec4..5491d4d5b484739511f98efe9cbc3b171dd915e6 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
@@ -42,6 +40,7 @@ public:
     Ipv6Codec() : Codec("ipv6"){};
     ~Ipv6Codec(){};
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -62,6 +61,11 @@ static inline int IPV6ExtensionOrder(uint8_t type);
 static void CheckIPV6Multicast(Packet *p);
 static inline int CheckTeredoPrefix(ipv6::IP6RawHdr *hdr);
 
+void Ipv6Codec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ipv6::ethertype());
+    v.push_back(ipv6::prot_id());
+}
 
 //--------------------------------------------------------------------
 // decode.c::IP6 decoder
@@ -983,11 +987,6 @@ EncStatus Opt6_Update (Packet* p, Layer* lyr, uint32_t* len)
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ipv6::ethertype());
-    v.push_back(ipv6::prot_id());
-}
 
 static Codec* ctor()
 {
@@ -999,18 +998,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "ipv6_codec";
+static const char* name = "ipv6";
 static const CodecApi ipv6_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids,
 };
 
 
similarity index 59%
rename from src/codecs/plugins/cd_none.cc
rename to src/codecs/basic/cd_null.cc
index a836d60247c0feae559b5a8c691b9cd8f57ac7d4..e1cbae62c12c5c1a2c840811670755817cb14995 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
+// cd_null.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
-#if 0
-
-#ifdef HAVE_DUMBNET_H
-#include <dumbnet.h>
-#else
-#include <dnet.h>
-#endif
-#endif
 
 #include "framework/codec.h"
 #include "events/codec_events.h"
+#include "codecs/decode_module.h"
+
 
 namespace
 {
 
-class NameCodec : public Codec
+class NullCodec : public Codec
 {
 public:
-    NameCodec() : Codec("NAME"){};
-    ~NameCodec();
-
+    NullCodec() : Codec("null"){};
+    ~NullCodec(){};
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *, uint16_t &lyr_len, int &next_prot_id);
-
-    virtual void get_protocol_ids(std::vector<uint16_t>&);
-    virtual void get_data_link_type(std::vector<int>&){};
-    
+        Packet *, uint16_t &lyr_len, int &next_prot_id) { return false; };
+    virtual inline bool is_default_codec() { return true; };
 };
 
-} // anonymous namespace
+} // namespace
+
+
+
 
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
 
 
-void NameCodec::get_protocol_ids(std::vector<uint16_t>& v)
+void NullCodec::get_protocol_ids(std::vector<uint16_t>& v)
 {
-    v.push_back(ipv6::ethertype());
-    v.push_back(IPPROTO_IPV6);
+    // placeholder to avoid error
 }
 
 static Codec* ctor()
 {
-    return new NameCodec();
+    return new NullCodec();
 }
 
 static void dtor(Codec *cd)
@@ -76,11 +71,18 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "name_codec";
 
-static const CodecApi ipv6_api =
+static const char* name = "null";
+static const CodecApi null_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
@@ -89,3 +91,4 @@ static const CodecApi ipv6_api =
     dtor, // dtor
 };
 
+const BaseApi* cd_null = &null_api.base;
index 17964a022c2bbe6421e70551d09d6d92ff8f147f..6c082cc3f3caa963134f7508b721f5a77d5c245c 100644 (file)
@@ -50,16 +50,18 @@ namespace
 class TcpCodec : public Codec
 {
 public:
-    TcpCodec() : Codec("Tcp")
+    TcpCodec() : Codec("tcp")
     {
 
     };
     virtual ~TcpCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
+
     // DELETE
     #include "codecs/sf_protocols.h"
     virtual inline PROTO_ID get_proto_id() { return PROTO_TCP; };
@@ -86,6 +88,12 @@ static inline unsigned short in_chksum_tcp(pseudoheader *, unsigned short *, int
 static inline unsigned short in_chksum_tcp6(pseudoheader6 *, unsigned short *, int);
 
 
+void TcpCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_TCP);
+}
+
+
 /*
  * Function: DecodeTCP(uint8_t *, const uint32_t, Packet *)
  *
@@ -1005,7 +1013,6 @@ static void tcp_codec_ginit()
 {
     SynToMulticastDstIp = IpAddrSetParse(snort_conf, "[232.0.0.0/8,233.0.0.0/8,239.0.0.0/8]");
 
-
     if( SynToMulticastDstIp == NULL )
         FatalError("Could not initialize SynToMulticastDstIp\n");
 
@@ -1031,24 +1038,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(IPPROTO_TCP);
-}
-
-static const char* name = "tcp_codec";
-
+static const char* name = "tcp";
 static const CodecApi tcp_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     tcp_codec_ginit, // pinit
     tcp_codec_gterm, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL, 
-    get_protocol_ids,
 };
 
 const BaseApi* cd_tcp = &tcp_api.base;
index 9b678ad675204d69c4cc91563ae9fc25d32c66f3..5f8b06508c9a6b509b9f2035701da9461a75eec7 100644 (file)
@@ -50,6 +50,7 @@ public:
     ~UdpCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -74,6 +75,12 @@ static inline unsigned short in_chksum_udp(pseudoheader *, unsigned short *, int
 
 
 
+void UdpCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_UDP);
+}
+
+
 bool UdpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
     Packet *p, uint16_t &lyr_len, int &next_prot_id)
 {
@@ -599,12 +606,6 @@ static inline unsigned short in_chksum_udp(pseudoheader *ph,
 // api
 //-------------------------------------------------------------------------
 
-
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(IPPROTO_UDP);
-}
-
 static Codec* ctor()
 {
     return new UdpCodec();
@@ -615,19 +616,24 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "udp_codec";
+static const char* name = "udp";
 
 static const CodecApi udp_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0, nullptr, nullptr },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    { 
+        PT_CODEC, 
+        name, 
+        CDAPI_PLUGIN_V0, 
+        0, 
+        nullptr, 
+        nullptr 
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids,
 };
 
 
index ee50e0b3c5f671ee71657cfc43bf9a9dc6db967e..b1ae3aa40c06ca521cbaa82b81a5d567bd41aa23 100644 (file)
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
+// packet_manager.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include "codec_api.h"
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include "codec_api.h"
 #include "framework/codec.h"
 
 
+extern const BaseApi* cd_eth;
+extern const BaseApi* cd_ipv4;
+extern const BaseApi* cd_ipv6;
+extern const BaseApi* cd_icmp4;
+extern const BaseApi* cd_icmp6;
+extern const BaseApi* cd_tcp;
+extern const BaseApi* cd_udp;
+extern const BaseApi* cd_esp;
+extern const BaseApi* cd_null;
+
+#ifdef STATIC_DECODERS
+extern const BaseApi* cd_ah;
+extern const BaseApi* cd_arp;
+extern const BaseApi* cd_erspan2;
+extern const BaseApi* cd_erspan3; 
+extern const BaseApi* cd_ethloopback; 
+extern const BaseApi* cd_gre;
+extern const BaseApi* cd_gtp;
+extern const BaseApi* cd_mpls;
+extern const BaseApi* cd_pppencap;
+extern const BaseApi* cd_pppoe;
+extern const BaseApi* cd_swipe;
+extern const BaseApi* cd_teredo;
+extern const BaseApi* cd_transbridge;
+extern const BaseApi* cd_vlan;
+#endif
+
 const BaseApi* codecs[] =
 {
     cd_eth,
@@ -36,6 +65,7 @@ const BaseApi* codecs[] =
     cd_tcp,
     cd_udp,
     cd_esp,
+    cd_null,
 
 #ifdef STATIC_DECODERS
     cd_ah,
index 45aa8f8d08264dd9bde490556c5102f348b3b81d..7e3f0b661ce0aa01fc6e1a5f3de17b43dd499688 100644 (file)
 #ifndef CODECS_H
 #define CODECS_H
 
-struct BaseApi;
 
-extern const BaseApi* cd_eth;
-extern const BaseApi* cd_ipv4;
-extern const BaseApi* cd_ipv6;
-extern const BaseApi* cd_icmp4;
-extern const BaseApi* cd_icmp6;
-extern const BaseApi* cd_tcp;
-extern const BaseApi* cd_udp;
-extern const BaseApi* cd_esp;
-
-#ifdef STATIC_DECODERS
-extern const BaseApi* cd_ah;
-extern const BaseApi* cd_arp;
-extern const BaseApi* cd_erspan2;
-extern const BaseApi* cd_erspan3; 
-extern const BaseApi* cd_ethloopback; 
-extern const BaseApi* cd_gre;
-extern const BaseApi* cd_gtp;
-extern const BaseApi* cd_mpls;
-extern const BaseApi* cd_pppencap;
-extern const BaseApi* cd_pppoe;
-extern const BaseApi* cd_swipe;
-extern const BaseApi* cd_teredo;
-extern const BaseApi* cd_transbridge;
-extern const BaseApi* cd_vlan;
-
-#endif
-
-extern const BaseApi* codecs[];
+extern const struct BaseApi* codecs[];
 
 #endif
index 320a6190b034dfa8a11be64db84cb1f82f35229e..9232726f6cf55dd16cb009b45bc2b01814194212 100644 (file)
@@ -16,4 +16,7 @@ add_library( codec_plugins STATIC
     cd_pppoepkt.cc
 )
 
+target_link_libraries( codec_plugins
+    events
+)
 
index 1c3f9b44f1dcda214e1caddda1bb56ffe3188850..8b4029ae0b92f31c75a121733f16dae87c8a8b5c 100644 (file)
@@ -39,6 +39,7 @@ public:
     ~AhCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -54,6 +55,11 @@ static const uint16_t AH_PROT_ID = 51; // RFC 4302
 
 } // anonymous namespace
 
+void AhCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(AH_PROT_ID);
+}
+
 
 bool AhCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id)
@@ -77,11 +83,6 @@ bool AhCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(AH_PROT_ID);
-}
-
 static Codec* ctor()
 {
     return new AhCodec();
@@ -92,18 +93,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "ah_codec";
+static const char* name = "ah";
 static const CodecApi ah_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name, 
+        CDAPI_PLUGIN_V0, 
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr, 
-    get_protocol_ids,
 };
 
 
index 4dde063e9f081f67dea5cc46dbbd2e8c262056f4..e80216b7691dd84b8ad69aeba6c1fc253fcaa3cd 100644 (file)
@@ -34,10 +34,11 @@ namespace
 class ArpCodec : public Codec
 {
 public:
-    ArpCodec() : Codec("Arp"){};
+    ArpCodec() : Codec("arp"){};
     ~ArpCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -54,6 +55,12 @@ static const uint16_t ETHERNET_TYPE_ARP = 0x0806;
 
 
 
+void ArpCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_ARP);
+    v.push_back(ETHERNET_TYPE_REVARP);
+}
+
 
 //--------------------------------------------------------------------
 // decode.c::ARP
@@ -97,12 +104,10 @@ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
 
 
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_ARP);
-    v.push_back(ETHERNET_TYPE_REVARP);
-}
 
 static Codec* ctor()
 {
@@ -114,32 +119,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 = "arp_codec";
+static const char* name = "arp";
 static const CodecApi arp_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL, // get_dlt
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index 54bdfd3a3f07c4f27b5e0b9bcefe9eda7d432c04..8ad048d6184ae7fee6c1d1391dbc7631464e9913 100644 (file)
@@ -47,6 +47,7 @@ public:
     ~NameCodec();
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
index 4a83f1677662688164e92da1f664218b6c0b19fb..bd4151127d81dba51011deb623dd2e45c112d035 100644 (file)
@@ -17,7 +17,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
-// cd_esp.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// cd_erspan2.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 
 #include "framework/codec.h"
@@ -31,9 +31,10 @@ namespace
 class Erspan2Codec : public Codec
 {
 public:
-    Erspan2Codec() : Codec("ERSPAN_2"){};
+    Erspan2Codec() : Codec("erspan2"){};
     ~Erspan2Codec(){};
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -53,7 +54,10 @@ struct ERSpanType2Hdr
 const uint16_t ETHERTYPE_ERSPAN_TYPE2 = 0x88be;
 } // namespace
 
-
+void Erspan2Codec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERTYPE_ERSPAN_TYPE2);
+}
 
 
 /*
@@ -100,17 +104,15 @@ bool Erspan2Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
         return false;
     }
 
-
-    next_prot_id = ETHERTYPE_TRANS_ETHER_BRIDGING; // huh?
+    next_prot_id = ETHERTYPE_TRANS_ETHER_BRIDGING;
     return true;
 }
 
 
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERTYPE_ERSPAN_TYPE2);
-}
 
 static Codec* ctor()
 {
@@ -123,7 +125,7 @@ static void dtor(Codec *cd)
 }
 
 
-static const char* name = "erspan2_codec";
+static const char* name = "erspan2";
 static const CodecApi erspan2_api =
 {
     { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
@@ -133,8 +135,6 @@ static const CodecApi erspan2_api =
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr,
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index 1cc5e3ac5cc12a472bdc8ff7eb92e82844e2d2be..d66251112f3de0a2e7d83b1ad1d56b9892092a21 100644 (file)
@@ -33,10 +33,11 @@ namespace
 class Erspan3Codec : public Codec
 {
 public:
-    Erspan3Codec() : Codec("ERSPAN_3"){};
+    Erspan3Codec() : Codec("erspan3"){};
     ~Erspan3Codec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -60,6 +61,13 @@ struct ERSpanType3Hdr
 const uint16_t ETHERTYPE_ERSPAN_TYPE3 = 0x22eb;
 } // anonymous namespace
 
+
+void Erspan3Codec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERTYPE_ERSPAN_TYPE3);
+}
+
+
 /*
  * Function: DecodeERSPANType3(uint8_t *, uint32_t, Packet *)
  *
@@ -114,11 +122,6 @@ bool Erspan3Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERTYPE_ERSPAN_TYPE3);
-}
-
 static Codec* ctor()
 {
     return new Erspan3Codec();
@@ -130,18 +133,23 @@ static void dtor(Codec *cd)
 }
 
 
-static const char* name = "erspan3_codec";
+static const char* name = "erspan3";
 static const CodecApi erspan3_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr, // get_dlt
-    get_protocol_ids,
 };
 
 
index 17e1390e21681ef0d0d9120da41f825e844f8606..3780883a55dfae149762125501dad31b39b0a851 100644 (file)
@@ -17,7 +17,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
-// cd_vlan.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// cd_ethloopback.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 
 #include "framework/codec.h"
@@ -30,10 +30,11 @@ namespace
 class EthLoopbackCodec : public Codec
 {
 public:
-    EthLoopbackCodec() : Codec("Ethloopback"){};
+    EthLoopbackCodec() : Codec("ethloopback"){};
     ~EthLoopbackCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -45,6 +46,12 @@ const uint16_t ETHERNET_TYPE_LOOP = 0x9000;
 
 } // anonymous namespace
 
+
+void EthLoopbackCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_LOOP);
+}
+
 bool EthLoopbackCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id)
 {
@@ -56,7 +63,6 @@ bool EthLoopbackCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 //    if (p->greh != NULL)
 //        dc.gre_loopback++;
 
-    next_prot_id = -1;
     return true;
 }
 
@@ -66,10 +72,6 @@ bool EthLoopbackCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 //-------------------------------------------------------------------------
 
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_LOOP);
-}
 
 static Codec* ctor()
 {
@@ -81,18 +83,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "ethloopback_codec";
+static const char* name = "ethloopback";
 static const CodecApi ethloopback_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr, // get_dlt
-    get_protocol_ids,
 };
 
 
index e98cbf8e0df676a4133dbd607b98fb30da0e24fb..571fe53aac611f42fae7fae6a42ead9aba8206a8 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
@@ -43,10 +41,11 @@ namespace
 class NameCodec : public Codec
 {
 public:
-    NameCodec() : Codec("NAME"){};
+    NameCodec() : Codec("fragment"){};
     ~NameCodec();
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
index 10d8c040e4561050b4df27f5c5046a55a643540a..5e087755df3be9bb290c063079bd193b6d4a7488 100644 (file)
@@ -33,10 +33,11 @@ namespace
 class GreCodec : public Codec
 {
 public:
-    GreCodec() : Codec("GRE"){};
+    GreCodec() : Codec("gre"){};
     ~GreCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -68,22 +69,14 @@ static const uint32_t GRE_V1_ACK_LEN = 4;
 #define GRE_RECUR(x)   (x->flags & 0x07)
 #define GRE_FLAGS(x)   (x->version & 0xF8)
 
-#if 0
-#define GRE_HEADER_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_HEADER_LEN 4
-#endif
-
 } // anonymous namespace
 
 
+void GreCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(GRE_PROT_ID);
+}
 
-//--------------------------------------------------------------------
-// decode.c::GRE
-//--------------------------------------------------------------------
 
 /*
  * Function: DecodeGRE(uint8_t *, uint32_t, Packet *)
@@ -251,10 +244,6 @@ void GRE_Format (EncodeFlags, const Packet*, Packet* c, Layer* lyr)
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(GRE_PROT_ID);
-}
 
 static Codec* ctor()
 {
@@ -266,18 +255,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "gre_codec";
+static const char* name = "gre";
 static const CodecApi gre_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr,
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index 865a66d7cf9399467f8a5fc9aaf8b389ca21cd4d..1806fcad23a62683042b82f96ed3382d93c1963d 100644 (file)
@@ -44,10 +44,10 @@ namespace
 class GtpCodec : public Codec
 {
 public:
-    GtpCodec() : Codec("GTP"){};
+    GtpCodec() : Codec("gtp"){};
     ~GtpCodec(){};
 
-
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -60,6 +60,10 @@ public:
 } // anonymous namespace
 
 
+void GtpCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(PROTOCOL_GTP);
+}
 
 /* Function: DecodeGTP(uint8_t *, uint32_t, Packet *)
  *
@@ -271,10 +275,9 @@ EncStatus GTP_Update (Packet*, Layer* lyr, uint32_t* len)
 
 #endif
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(PROTOCOL_GTP);
-}
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
 static Codec* ctor()
 {
@@ -286,18 +289,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "gtp_codec";
+static const char* name = "gtp";
 static const CodecApi gtp_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
     NULL, // pinit
     NULL, // pterm
     NULL, // tinit
     NULL, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index a836d60247c0feae559b5a8c691b9cd8f57ac7d4..dc23d8ec14564439109d1d3683144fe1a729c767 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
@@ -43,10 +41,12 @@ namespace
 class NameCodec : public Codec
 {
 public:
-    NameCodec() : Codec("NAME"){};
+    NameCodec() : Codec("hopopts"){};
     ~NameCodec();
 
 
+
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
index 665f059ac310c8295668c3951a1256593070d179..60cb20f9d1d81197892ce30bc70b240175c5727f 100644 (file)
@@ -39,10 +39,10 @@ namespace
 class MplsCodec : public Codec
 {
 public:
-    MplsCodec() : Codec("MPLS"){};
+    MplsCodec() : Codec("mpls"){};
     ~MplsCodec(){};
 
-
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);    
 
@@ -63,6 +63,13 @@ const static uint32_t NUM_RESERVED_LABELS = 16;
 static int checkMplsHdr(uint32_t, uint8_t, uint8_t, uint8_t, Packet *);
 
 
+void MplsCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_MPLS_UNICAST);
+    v.push_back(ETHERNET_TYPE_MPLS_MULTICAST);
+}
+
+
 bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id)
 {
@@ -251,12 +258,9 @@ static int checkMplsHdr(
     return iRet;
 }
 
-
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_MPLS_UNICAST);
-    v.push_back(ETHERNET_TYPE_MPLS_MULTICAST);
-}
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
 static Codec* ctor()
 {
@@ -268,18 +272,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "mpls_codec";
+static const char* name = "mpls";
 static const CodecApi mpls_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    { 
+        PT_CODEC, 
+        name, 
+        CDAPI_PLUGIN_V0, 
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr, // get_dlt
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index e878fd59a8009ffc3c3d46300ae3d5b097b33cb6..44f8b683d73414db68c9c58891aa22f027ddc310 100644 (file)
@@ -37,10 +37,11 @@ namespace
 class PppEncap : public Codec
 {
 public:
-    PppEncap() : Codec("PPPEncapsulation"){};
+    PppEncap() : Codec("ppp_encap"){};
     ~PppEncap(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -56,10 +57,13 @@ const static uint16_t PPP_VJ_COMP = 0x002d;        /* VJ compressed TCP/IP */
 const static uint16_t PPP_VJ_UCOMP = 0x002f;        /* VJ uncompressed TCP/IP */
 const static uint16_t PPP_IPX = 0x002b;        /* Novell IPX Protocol */
 
-} // anonymous namespace
-
+} // namespace
 
 
+void PppEncap::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERTYPE_PPP);
+}
 
 
 /*
@@ -174,11 +178,6 @@ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len,
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERTYPE_PPP);
-}
-
 static Codec* ctor()
 {
     return new PppEncap();
@@ -189,18 +188,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "pppencap_codec";
+static const char* name = "ppp_encap";
 static const CodecApi pppencap_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr, // get_dlt
-    get_protocol_ids,
 };
 
 #ifdef BUILDING_SO
index 0a38970c254135eb984c9c7c4caa8fd433ccf179..feebdd69889cd3447a2864dcb19bebdcf93602d3 100644 (file)
@@ -31,10 +31,11 @@ namespace
 class PPPoEPkt : public Codec
 {
 public:
-    PPPoEPkt() : Codec("PPP_over_Eth"){};
+    PPPoEPkt() : Codec("ppp_over_eth"){};
     ~PPPoEPkt(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -70,7 +71,14 @@ const uint16_t PPPoE_TAG_AC_SYSTEM_ERROR = 0x0202;
 const uint16_t PPPoE_TAG_GENERIC_ERROR = 0x0203;
 
 
-} // anonymous namespace
+} // namespace
+
+
+void PPPoEPkt::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_PPPoE_DISC);
+    v.push_back(ETHERNET_TYPE_PPPoE_SESS);
+}
 
 
 //--------------------------------------------------------------------
@@ -283,11 +291,9 @@ EncStatus PPPoE_Encode (EncState* enc, Buffer* in, Buffer* out)
 }
 #endif
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_PPPoE_DISC);
-    v.push_back(ETHERNET_TYPE_PPPoE_SESS);
-}
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
 static Codec* ctor()
 {
@@ -299,18 +305,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "pppoepkt_codec";
+static const char* name = "ppp_over_eth";
 static const CodecApi pppoe_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC, 
+        name, 
+        CDAPI_PLUGIN_V0, 
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr,
-    get_protocol_ids,
 };
 
 
index ba2fcd12e370da36a5f83ab19e03679564d952f7..989f80d86b536ee60680b4f3651941454c791948 100644 (file)
@@ -50,13 +50,20 @@ public:
     TeredoCodec() : Codec("teredo"){};
     ~TeredoCodec(){};
 
-
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 };
 
 } // anonymous namespace
 
+
+void TeredoCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(PROTOCOL_TEREDO);
+}
+
+
 bool TeredoCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id)
 {
@@ -114,10 +121,9 @@ bool TeredoCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
 
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(PROTOCOL_TEREDO);
-}
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
 
 static Codec* ctor()
 {
@@ -130,18 +136,22 @@ static void dtor(Codec *cd)
 }
 
 static const char* name = "teredo";
-
 static const CodecApi teredo_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL,
-    get_protocol_ids
 };
 
 
index 55c6c9e549001b11b0d195e2657374747802a1cf..9b2c06f43e2786068698eb91c051a48220c40eef 100644 (file)
@@ -39,10 +39,11 @@ namespace
 class TransbridgeCodec : public Codec
 {
 public:
-    TransbridgeCodec() : Codec("Transbridge"){};
+    TransbridgeCodec() : Codec("transbridge"){};
     ~TransbridgeCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
     
@@ -51,6 +52,10 @@ public:
 } // anonymous namespace
 
 
+void TransbridgeCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERTYPE_TRANS_ETHER_BRIDGING); // defined in ethertypes.h"
+}
 
 
 /*
@@ -97,10 +102,6 @@ bool TransbridgeCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 // api
 //-------------------------------------------------------------------------
 
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERTYPE_TRANS_ETHER_BRIDGING); // defined in ethertypes.h"
-}
 
 static Codec* ctor()
 {
@@ -112,18 +113,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "transbridge_codec";
+static const char* name = "transbridge";
 static const CodecApi transbridge_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    nullptr,
-    get_protocol_ids,
 };
 
 
index 44f44657b6da3f02953c67785c3b500a0ec02e19..fb9c97d2b3b4c32ade42286eaf288479b3d81b05 100644 (file)
@@ -40,6 +40,7 @@ public:
     ~VlanCodec(){};
 
 
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, int &next_prot_id);
 
@@ -49,30 +50,23 @@ public:
     virtual inline PROTO_ID get_proto_id() { return PROTO_VLAN; };
 };
 
-struct CdPegs{
-    PegCount processed = 0;
-    PegCount discards = 0;
-};
-
-std::vector<const char*> peg_names =
-{
-    "NameCodec_processed",
-    "NameCodec_discards",
-};
-
+} // namespace
 
-} // anonymous namespace
-
-static THREAD_LOCAL CdPegs counts;
-static CdPegs gcounts;
 static const uint16_t ETHERNET_TYPE_8021Q = 0x8100;
 
+
 static inline uint32_t len_vlan_llc_other()
 {
     return (sizeof(VlanTagHdr) + sizeof(EthLlc) + sizeof(EthLlcOther));
 }
 
 
+void VlanCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_8021Q);
+}
+
+
 bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id)
 {
@@ -184,13 +178,6 @@ void VLAN_Format (EncodeFlags, const Packet*, Packet* c, Layer* lyr)
 // api
 //-------------------------------------------------------------------------
 
-
-
-static void get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_8021Q);
-}
-
 static Codec* ctor()
 {
     return new VlanCodec();
@@ -201,18 +188,23 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const char* name = "vlan_codec";
+static const char* name = "vlan";
 static const CodecApi vlan_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
     ctor, // ctor
     dtor, // dtor
-    NULL, // get_dlt
-    get_protocol_ids,
 };
 
 
index d7c95aa5061a1116f4f968d1c5bac26afaba8a57..67b313c74f87d3432cf6ea5c8dcac810e2825f24 100644 (file)
@@ -36,7 +36,7 @@ class NameCodec : public Codec
 {
 public:
     NameCodec() : Codec("NAME"){};
-    ~NameCodec();
+    ~NameCodec() {};
 
 
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
index c02fa127c88560bff5cc52252edba76f1848fc3f..7c31c1ffb2d045cd5cea53a5f753a1e783b32ce9 100644 (file)
@@ -12,6 +12,7 @@ add_library (events STATIC
     event_wrapper.h 
     sfeventq.cc 
     sfeventq.h
+    codec_events.cc
 )
 
 install (FILES ${INCLUDES}
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b9c5a6fe96c380ba3042b14cdce7071d21e56777 100644 (file)
@@ -0,0 +1,54 @@
+/*
+** 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 CODEC_EVENTS_H
+#define CODEC_EVENTS_H
+
+#include <array>
+
+// included for DECODE_INDEX_MAX
+#include "detection/generators.h"
+//#include "utils/sfActionQueue.h"
+#include "network_inspectors/normalize/normalize.h"
+#include "protocols/packet.h"
+#include "time/profiler.h"
+#include "codecs/decode_module.h"
+
+namespace codec_events
+{
+
+    void exec_ip_chksm_drop(Packet*);
+    void exec_udp_chksm_drop (Packet *);
+    void exec_tcp_chksm_drop (Packet*);
+    void exec_hop_drop(Packet* p, int sid);
+    void exec_ttl_drop (Packet *data, int sid);
+    void exec_icmp_chksm_drop (Packet*);
+
+    void decoder_event (Packet *, int);
+    void decoder_alert_encapsulated(
+        Packet *p, int sid, const uint8_t *pkt, uint32_t len);
+
+    int ScNormalDrop (NormFlags nf);
+
+} //namespace codec_events
+
+
+#endif
+
diff --git a/src/events/codec_events.h.bak b/src/events/codec_events.h.bak
deleted file mode 100644 (file)
index b9c5a6f..0000000
+++ /dev/null
@@ -1,54 +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 CODEC_EVENTS_H
-#define CODEC_EVENTS_H
-
-#include <array>
-
-// included for DECODE_INDEX_MAX
-#include "detection/generators.h"
-//#include "utils/sfActionQueue.h"
-#include "network_inspectors/normalize/normalize.h"
-#include "protocols/packet.h"
-#include "time/profiler.h"
-#include "codecs/decode_module.h"
-
-namespace codec_events
-{
-
-    void exec_ip_chksm_drop(Packet*);
-    void exec_udp_chksm_drop (Packet *);
-    void exec_tcp_chksm_drop (Packet*);
-    void exec_hop_drop(Packet* p, int sid);
-    void exec_ttl_drop (Packet *data, int sid);
-    void exec_icmp_chksm_drop (Packet*);
-
-    void decoder_event (Packet *, int);
-    void decoder_alert_encapsulated(
-        Packet *p, int sid, const uint8_t *pkt, uint32_t len);
-
-    int ScNormalDrop (NormFlags nf);
-
-} //namespace codec_events
-
-
-#endif
-
index 1a8cef33c53a6eb876f06eeaf75d9eb9d1a1935f..41107319d3430beee44df343a0c0aadb4c8f5591 100644 (file)
@@ -39,11 +39,6 @@ struct Packet;
 // to be useful, these must be explicit (*_V0, *_V1, ...)
 #define CDAPI_PLUGIN_V0 0
 
-//-------------------------------------------------------------------------
-// FIXIT just starting points for Codec and CodecApi
-
-
-
 
 
 class Codec {
@@ -52,33 +47,33 @@ public:
 
     virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, 
         Packet *p, uint16_t &lyr_len, int &next_prot_id) = 0;
-
-    // do nothing unless methods overridden.
-    // ONE OF THESE METHODS MUST BE IMPLEMENTED!!
+    // Get the codec's name
     virtual inline const char* get_name(){return name; };
+    // Registers this Codec's data link type (as defined by libpcap)
+    virtual void get_data_link_type(std::vector<int>&) {};
+    // Register the code's protocol ID's and Ethertypes
+    virtual void get_protocol_ids(std::vector<uint16_t>&) = 0;
+    // used by packet manager to determine the default/null codec
+    virtual inline bool is_default_codec() { return false; };
 
 
+    // DELETE
     virtual inline PROTO_ID get_proto_id() { return PROTO_MAX; };
 
 
 protected:
     Codec(const char* s) { name = s; };
 
-
-
 private:
     const char* name;
 };
 
-struct _daq_pkthdr;
 
-typedef int (*cd_eval_f)(void*, Packet*);
 //typedef cd_eval_f (*cd_new_f)(const char* key, void**);
 typedef Codec* (*cd_new_f)();
 
 typedef void (*cd_del_f)(Codec *);
 typedef void (*cd_aux_f)();
-typedef bool (*decode_f)(const uint8_t *, const uint32_t, Packet *, uint16_t &, uint16_t &);
 typedef void (*cd_dlt_f)(std::vector<int>&v);
 typedef void (*cd_prot_id_f)(std::vector<uint16_t>&);
 
@@ -92,7 +87,6 @@ struct CodecApi
 {
     BaseApi base;
 
-
     // these may be nullptr
     cd_aux_f ginit;  // initialize global plugin data
     cd_aux_f gterm;  // clean-up pinit()
@@ -103,9 +97,6 @@ struct CodecApi
     // these must be set
     cd_new_f ctor;   // get eval optional instance data
     cd_del_f dtor;   // clean up instance data
-
-    cd_dlt_f dlt;   // get the data link type
-    cd_prot_id_f proto_id;  // get the protocol ids
 };
 
 #endif
index 496eafdfc0b295a706a981ddff33a1edcb635cef..2aae893dcd8bacf5a388f4a1c3135469115b93d7 100644 (file)
@@ -69,12 +69,9 @@ static THREAD_LOCAL std::array<PegCount, max_protocol_id + gen_peg_size> s_stats
 static std::array<PegCount, max_protocol_id + gen_peg_size> g_stats;
 static THREAD_LOCAL CdGenPegs pkt_cnt;
 
-static std::array<uint8_t, max_protocol_id> s_proto_map;
-static std::array<Codec*, 256> s_protocols;
-
-extern const BaseApi* cd_unimplemented;
-static THREAD_LOCAL uint8_t grinder;
-static bool initial_instatiation = true;
+static std::array<uint8_t, max_protocol_id> s_proto_map{};
+static std::array<Codec*, 256> s_protocols{};
+static THREAD_LOCAL uint8_t grinder = 0;
 
 //-------------------------------------------------------------------------
 // helper functions
@@ -117,9 +114,6 @@ void PacketManager::add_plugin(const CodecApi* api)
                         api->base.name);  
 
     s_codecs.push_back(api);
-
-    if (api->ginit)
-        api->ginit();
 }
 
 void PacketManager::release_plugins()
@@ -148,132 +142,75 @@ void PacketManager::dump_plugins()
 
 void PacketManager::instantiate(const CodecApi* cd_api, Module* m, SnortConfig* sc)
 {
+    static uint16_t codec_id = 1;
+    std::vector<uint16_t> ids;
+
     const CodecApi *p = GetApi(cd_api->base.name);
 
     if(!p)
-    {
         ParseError("Unknown codec: '%s'.", cd_api->base.name);
-    }
-    else
-    {
-        p->ctor();
-    }
-}
 
+    // global init here to ensure the global policy has already been configured
+    if (p->ginit)
+        p->ginit();
 
+    Codec *cd = p->ctor();
+    cd->get_protocol_ids(ids);
+    for (auto id : ids)
+    {
+        if(s_proto_map[id] != 0)
+            WarningMessage("The Codecs %s and %s have both been registered "
+                "for protocol_id %d. Codec %s will be used\n",
+                s_protocols[s_proto_map[id]]->get_name(), cd->get_name(), 
+                id, cd->get_name());
 
-//-------------------------------------------------------------------------
-// grinder
-//-------------------------------------------------------------------------
-
-void PacketManager::decode(
-    Packet* p, const DAQ_PktHdr_t* pkthdr, const uint8_t* pkt)
-{
-    PROFILE_VARS;
-    int curr_prot_id, next_prot_id;
-    uint16_t len, lyr_len;
-
-    PREPROC_PROFILE_START(decodePerfStats);
-
-    // initialize all of the relevent data to decode this packet
-    memset(p, 0, PKT_ZERO_LEN);
-    p->pkth = pkthdr;
-    p->pkt = pkt;
-    len = pkthdr->caplen;
-    curr_prot_id = GRINDER_ID;
-    pkt_cnt.total_processed++;
+        s_proto_map[id] = codec_id;
+    }
 
-    // loop until the protocol id is no longer valid
-    while(curr_prot_id  >= 0 && curr_prot_id < max_protocol_id)
+    if(cd->is_default_codec())
     {
-        if (s_protocols[curr_prot_id] == 0)
-        {
-            pkt_cnt.other_codecs++;
-            break;
-        }
-        else if( !s_protocols[curr_prot_id]->decode(pkt, len, p, lyr_len, next_prot_id))
-        {
-            pkt_cnt.discards++;
-            break;
-        }           
-
-        s_stats[curr_prot_id + stat_offset]++;
-        PacketClass::PushLayer(p, s_protocols[curr_prot_id], pkt, lyr_len);
-        curr_prot_id = next_prot_id;
-        next_prot_id = -1;
-        len -= lyr_len;
-        pkt += lyr_len;
-        lyr_len = 0;
+        if(s_protocols[0])
+            s_protocols[0] = cd;
+        else
+            FatalError("Only one Codec may be the registered as default, "
+                "but both the %s and %s return 'true' when "
+                " the function default_codec().\n",
+                s_protocols[0]->get_name(), cd->get_name());
     }
 
-    p->dsize = len;
-    p->data = pkt;
-    PREPROC_PROFILE_END(decodePerfStats);
+    s_protocols[codec_id++] = cd;
 }
 
-
 void PacketManager::set_grinder(void)
 {
-    std::vector<uint16_t> proto;
-    std::vector<int> dlt;
-    bool codec_registered;
-    uint16_t cd_cnt = 0;
-
+    for ( auto* p : s_codecs )
+        if (p->tinit)
+            p->tinit();
 
     int daq_dlt = DAQ_GetBaseProtocol();
-
-    for ( auto* p : s_codecs )
+    for(int i = 0; i < s_protocols.size(); i++)
     {
-        codec_registered = false;
-
+        Codec *cd = s_protocols[i];
+        std::vector<int> data_link_types;
 
-        // TODO:  add module
-        // null check performed when plugin added.
-        Codec *cd = p->ctor();
-
-
-        proto.clear();
-        if(p->proto_id)
-            p->proto_id(proto);
-        for (auto proto_id : proto)
-        {
-            if(s_protocols[proto_id] != NULL)
-                WarningMessage("The Codecs %s and %s have both been registered "
-                    "for protocol_id %d. Codec %s will be used\n",
-                    s_protocols[proto_id]->get_name(), cd->get_name(), 
-                    proto_id, cd->get_name());
-            s_protocols[proto_id] = cd;
-            codec_registered = true;
-        }
-        // add protocols to the array
-
-
-        dlt.clear();
-        if(p->dlt)
-            p->dlt(dlt);
-        // set the grinder if the data link types match
-        for (auto curr_dlt : dlt )
+        cd->get_data_link_type(data_link_types);
+        for (auto curr_dlt : data_link_types)
         {
            if (curr_dlt == daq_dlt)
            {
-                if (s_protocols[GRINDER_ID] != NULL)
+                if (grinder != 0)
                     WarningMessage("The Codecs %s and %s have both been registered "
                         "as the raw decoder. Codec %s will be used\n",
                         s_protocols[GRINDER_ID]->get_name(), cd->get_name(), 
                         cd->get_name());
 
-                s_protocols[GRINDER_ID] = cd;
-                codec_registered = true;
+                grinder = i;
             }
         }
-
-        if (!codec_registered)
-            WarningMessage("The Codec %s is never used\n", cd->get_name());
-
-
-        if (p->tinit)
-            p->tinit();
     }
+
+    if(!grinder)
+        FatalError("Unable to find a Codec with data link type %d!!\n", daq_dlt);
 }
 
 void PacketManager::thread_term()
@@ -318,6 +255,55 @@ void PacketManager::accumulate()
     stats_mutex.unlock();
 }
 
+//-------------------------------------------------------------------------
+// grinder
+//-------------------------------------------------------------------------
+
+void PacketManager::decode(
+    Packet* p, const DAQ_PktHdr_t* pkthdr, const uint8_t* pkt)
+{
+    PROFILE_VARS;
+    int curr_prot_id, next_prot_id;
+    uint16_t len, lyr_len;
+
+    PREPROC_PROFILE_START(decodePerfStats);
+
+    // initialize all of the relevent data to decode this packet
+    memset(p, 0, PKT_ZERO_LEN);
+    p->pkth = pkthdr;
+    p->pkt = pkt;
+    len = pkthdr->caplen;
+    curr_prot_id = GRINDER_ID;
+    pkt_cnt.total_processed++;
+
+    // loop until the protocol id is no longer valid
+    while(curr_prot_id  >= 0 && curr_prot_id < max_protocol_id)
+    {
+        if (s_protocols[curr_prot_id] == 0)
+        {
+            pkt_cnt.other_codecs++;
+            break;
+        }
+        else if( !s_protocols[curr_prot_id]->decode(pkt, len, p, lyr_len, next_prot_id))
+        {
+            pkt_cnt.discards++;
+            break;
+        }           
+
+        s_stats[curr_prot_id + stat_offset]++;
+        PacketClass::PushLayer(p, s_protocols[curr_prot_id], pkt, lyr_len);
+        curr_prot_id = next_prot_id;
+        next_prot_id = -1;
+        len -= lyr_len;
+        pkt += lyr_len;
+        lyr_len = 0;
+    }
+
+    p->dsize = len;
+    p->data = pkt;
+    PREPROC_PROFILE_END(decodePerfStats);
+}
+
 bool PacketManager::has_codec(uint16_t cd_id)
 {
     return s_protocols[cd_id] != 0;
index 373b9537716606da37f6d6667850a8a78045f132..8d9f47909958d736e2b36e8848fa3ed08fffe77d 100644 (file)
@@ -53,9 +53,6 @@ public:
     static void set_grinder();  // thread_init
     static void thread_term();
 
-    static void init_codecs();
-    static void term_codecs();
-
     static void decode(Packet*, const struct _daq_pkthdr*, const uint8_t*);
     static void dump_stats();