From: Josh Date: Tue, 29 Apr 2014 20:36:14 +0000 (-0400) Subject: packet manager refactor X-Git-Tag: 3.0.0-233~1542^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59f464796b53aed963a2c38286fc2018e5b83815;p=thirdparty%2Fsnort3.git packet manager refactor --- 59f464796b53aed963a2c38286fc2018e5b83815 diff --cc config.cmake.h.in index 4a5cdb38d,729ad5c18..e66a6b24c --- a/config.cmake.h.in +++ b/config.cmake.h.in @@@ -251,44 -298,56 +298,56 @@@ - /* Define available functions */ -/* Available compiler options ++/* Available compiler options */ - /* Define available libraries */ + /* Define if the compiler understands __FUNCTION__. */ + #cmakedefine HAVE___FUNCTION__ + /* Define if the compiler understands __func__. */ + #cmakedefine HAVE___func__ - /****************************************************************************************/ + /* Define __FUNCTION__ as required. */ + #cmakedefine __FUNCTION__ + /* Define if the compiler supports visibility declarations. */ + #cmakedefine HAVE_VISIBILITY + /* Define whether linuxthreads is being used */ + #cmakedefine HAVE_LINUXTHREADS + /* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ + #ifndef __cplusplus + #cmakedefine inline + #endif - /* Define if building universal (internal helper macro) */ - #cmakedefine01 AC_APPLE_UNIVERSAL_BUILD - /* Define if AIX */ - #cmakedefine01 AIX + /* general functions */ - /* Define if broken SIOCGIFMTU */ - #cmakedefine01 BROKEN_SIOCGIFMTU + /* Define to 1 if you have the `sigaction' function. */ + #cmakedefine HAVE_SIGACTION - /* Define if BSDi */ - #cmakedefine01 BSDI + /* snprintf function is available */ + #cmakedefine HAVE_SNPRINTF - /* Define if errlist is predefined */ - #cmakedefine01 ERRLIST_PREDEFINED + /* Define to 1 if you have the `strlcat' function. */ + #cmakedefine HAVE_STRLCAT - /* Define if FreeBSD */ - #cmakedefine01 FREEBSD + /* Define to 1 if you have the `strlcpy' function. */ + #cmakedefine HAVE_STRLCPY - /* Define to 1 if you have the `daq_acquire_with_meta' function. */ - #cmakedefine01 HAVE_DAQ_ACQUIRE_WITH_META + /* Define to 1 if you have the `vsnprintf' function. */ + #cmakedefine HAVE_VSNPRINTF - /* DAQ version supports address space ID in header. */ - #cmakedefine01 HAVE_DAQ_ADDRESS_SPACE_ID + /* Define to 1 if you have the `vswprintf' function. */ + #cmakedefine HAVE_VSWPRINTF - /* Define to 1 if you have the `daq_hup_apply' function. */ - #cmakedefine01 HAVE_DAQ_HUP_APPLY + /* Define to 1 if you have the `wprintf' function. */ + #cmakedefine HAVE_WPRINTF + /* Define to 1 if you have the `memrchr' function. */ + #cmakedefine HAVE_MEMRCHR /* Define to 1 if you have the `inet_ntop' function. */ #cmakedefine HAVE_INET_NTOP diff --cc src/codecs/basic/cd_esp.cc index 650bfc21a,ce70f1025..d37482d90 --- a/src/codecs/basic/cd_esp.cc +++ b/src/codecs/basic/cd_esp.cc @@@ -41,9 -41,8 +41,9 @@@ public ~EspCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); }; @@@ -81,7 -88,7 +81,7 @@@ void EspCodec::get_protocol_ids(std::ve * Returns: void function */ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { const uint8_t *esp_payload; uint8_t pad_length; diff --cc src/codecs/basic/cd_eth.cc index 312b41290,ac81d9bdb..6fd60a54d --- a/src/codecs/basic/cd_eth.cc +++ b/src/codecs/basic/cd_eth.cc @@@ -42,10 -42,8 +42,10 @@@ public ~EthCodec(){}; + virtual void get_protocol_ids(std::vector& v) {}; + virtual void get_data_link_type(std::vector&); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id); ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE #include "codecs/sf_protocols.h" @@@ -79,7 -72,7 +79,7 @@@ void EthCodec::get_data_link_type(std:: * Returns: void function */ bool EthCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { // dc.eth++; diff --cc src/codecs/basic/cd_icmp4.cc index 19a888349,aa2df3cfe..e8cbe1016 --- a/src/codecs/basic/cd_icmp4.cc +++ b/src/codecs/basic/cd_icmp4.cc @@@ -49,9 -49,8 +49,9 @@@ public Icmp4Codec() : Codec("icmp4"){}; ~Icmp4Codec() {}; + virtual void get_protocol_ids(std::vector&); virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id); ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below @@@ -93,7 -87,7 +93,7 @@@ void Icmp4Codec::get_protocol_ids(std:: * Returns: void function */ bool Icmp4Codec::decode(const uint8_t* raw_pkt, const uint32_t raw_len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { if(raw_len < ICMP_HEADER_LEN) { diff --cc src/codecs/basic/cd_icmp6.cc index e7ee50468,ae3f1a8e1..6568fb851 --- a/src/codecs/basic/cd_icmp6.cc +++ b/src/codecs/basic/cd_icmp6.cc @@@ -43,10 -43,8 +43,10 @@@ public ~Icmp6Codec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); + // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -76,7 -68,7 +76,7 @@@ static unsigned short in_chksum_icmp6(p //-------------------------------------------------------------------- bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len, -- Packet* p, uint16_t &lyr_len, int&next_prot_id) ++ Packet* p, uint16_t &lyr_len, uint16_t &next_prot_id) { if(len < icmp6::hdr_min_len()) { diff --cc src/codecs/basic/cd_ipv4.cc index 1b64e2d8b,706762771..a1606c74b --- a/src/codecs/basic/cd_ipv4.cc +++ b/src/codecs/basic/cd_ipv4.cc @@@ -51,9 -51,8 +51,9 @@@ public Ipv4Codec() : Codec("ipv4"){}; ~Ipv4Codec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_packet, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // used in random classes throughout Snort++ @@@ -114,7 -107,7 +114,7 @@@ void Ipv4Codec::get_protocol_ids(std::v * Returns: void function */ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { uint32_t ip_len; /* length from the start of the ip hdr to the pkt end */ diff --cc src/codecs/basic/cd_ipv6.cc index 5491d4d5b,3a927ac96..2c26e6f50 --- a/src/codecs/basic/cd_ipv6.cc +++ b/src/codecs/basic/cd_ipv6.cc @@@ -40,9 -42,8 +40,9 @@@ public Ipv6Codec() : Codec("ipv6"){}; ~Ipv6Codec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -72,7 -68,7 +72,7 @@@ void Ipv6Codec::get_protocol_ids(std::v //-------------------------------------------------------------------- bool Ipv6Codec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { ipv6::IP6RawHdr *hdr; uint32_t payload_len; diff --cc src/codecs/basic/cd_null.cc index e1cbae62c,a836d6024..edf4fa4fa --- a/src/codecs/basic/cd_null.cc +++ b/src/codecs/basic/cd_null.cc @@@ -27,38 -28,42 +27,40 @@@ #include "framework/codec.h" #include "events/codec_events.h" +#include "codecs/decode_module.h" ++#include "protocols/undefined_protocols.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& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, - Packet *, uint16_t &lyr_len, int &next_prot_id) { return false; }; - Packet *, uint16_t &lyr_len, int &next_prot_id); - - virtual void get_protocol_ids(std::vector&); - virtual void get_data_link_type(std::vector&){}; - ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id) { return false; }; + virtual inline bool is_default_codec() { return true; }; }; -} // anonymous namespace +} // namespace + + + +//------------------------------------------------------------------------- +// api +//------------------------------------------------------------------------- -void NameCodec::get_protocol_ids(std::vector& v) +void NullCodec::get_protocol_ids(std::vector& v) { - v.push_back(ipv6::ethertype()); - v.push_back(IPPROTO_IPV6); ++ v.push_back(FINISHED_DECODE); + // placeholder to avoid error } static Codec* ctor() diff --cc src/codecs/basic/cd_tcp.cc index 6c082cc3f,17964a022..26f2e44a9 --- a/src/codecs/basic/cd_tcp.cc +++ b/src/codecs/basic/cd_tcp.cc @@@ -57,10 -57,8 +57,10 @@@ public virtual ~TcpCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); + // DELETE #include "codecs/sf_protocols.h" @@@ -106,7 -98,7 +106,7 @@@ void TcpCodec::get_protocol_ids(std::ve * Returns: void function */ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { if(len < tcp::hdr_len()) { diff --cc src/codecs/basic/cd_udp.cc index 5f8b06508,9b678ad67..b6ef15ee8 --- a/src/codecs/basic/cd_udp.cc +++ b/src/codecs/basic/cd_udp.cc @@@ -50,9 -50,8 +50,9 @@@ public ~UdpCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE #include "codecs/sf_protocols.h" @@@ -75,14 -74,8 +75,14 @@@ static inline unsigned short in_chksum_ +void UdpCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { uint16_t uhlen; u_char fragmented_udp_flag = 0; diff --cc src/codecs/plugins/cd_ah.cc index 8b4029ae0,1c3f9b44f..f3d1701cb --- a/src/codecs/plugins/cd_ah.cc +++ b/src/codecs/plugins/cd_ah.cc @@@ -39,9 -39,8 +39,9 @@@ public ~AhCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below @@@ -55,14 -54,9 +55,14 @@@ static const uint16_t AH_PROT_ID = 51; } // anonymous namespace +void AhCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { IP6Extension *ah = (IP6Extension *)raw_pkt; diff --cc src/codecs/plugins/cd_arp.cc index e80216b76,4dde063e9..4ac2206d8 --- a/src/codecs/plugins/cd_arp.cc +++ b/src/codecs/plugins/cd_arp.cc @@@ -38,9 -38,8 +38,9 @@@ public ~ArpCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below @@@ -78,7 -71,7 +78,7 @@@ void ArpCodec::get_protocol_ids(std::ve * Returns: void function */ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { // dc.arp++; diff --cc src/codecs/plugins/cd_dstopts.cc index 8ad048d61,54bdfd3a3..c64c0442d --- a/src/codecs/plugins/cd_dstopts.cc +++ b/src/codecs/plugins/cd_dstopts.cc @@@ -47,9 -47,8 +47,9 @@@ public ~NameCodec(); + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); virtual void get_protocol_ids(std::vector&); virtual void get_data_link_type(std::vector&){}; diff --cc src/codecs/plugins/cd_erspan2.cc index bd4151127,4a83f1677..8cd5870a1 --- a/src/codecs/plugins/cd_erspan2.cc +++ b/src/codecs/plugins/cd_erspan2.cc @@@ -31,12 -31,11 +31,12 @@@ namespac class Erspan2Codec : public Codec { public: - Erspan2Codec() : Codec("ERSPAN_2"){}; + Erspan2Codec() : Codec("erspan2"){}; ~Erspan2Codec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -74,7 -70,7 +74,7 @@@ void Erspan2Codec::get_protocol_ids(std * */ bool Erspan2Codec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { lyr_len = sizeof(ERSpanType2Hdr); uint32_t payload_len; diff --cc src/codecs/plugins/cd_erspan3.cc index d66251112,1cc5e3ac5..980220808 --- a/src/codecs/plugins/cd_erspan3.cc +++ b/src/codecs/plugins/cd_erspan3.cc @@@ -37,9 -37,8 +37,9 @@@ public ~Erspan3Codec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -82,7 -74,7 +82,7 @@@ void Erspan3Codec::get_protocol_ids(std * */ bool Erspan3Codec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { lyr_len= sizeof(ERSpanType3Hdr); uint32_t payload_len; diff --cc src/codecs/plugins/cd_ethloopback.cc index 3780883a5,17e1390e2..fc1f326b1 --- a/src/codecs/plugins/cd_ethloopback.cc +++ b/src/codecs/plugins/cd_ethloopback.cc @@@ -34,9 -34,8 +34,9 @@@ public ~EthLoopbackCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); }; @@@ -46,14 -45,8 +46,14 @@@ const uint16_t ETHERNET_TYPE_LOOP = 0x9 } // anonymous namespace + +void EthLoopbackCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "EthLoopback is not supported.\n");); diff --cc src/codecs/plugins/cd_fragment.cc index 571fe53aa,e98cbf8e0..1916a9fd9 --- a/src/codecs/plugins/cd_fragment.cc +++ b/src/codecs/plugins/cd_fragment.cc @@@ -45,9 -47,8 +45,9 @@@ public ~NameCodec(); + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); virtual void get_protocol_ids(std::vector&); diff --cc src/codecs/plugins/cd_gre.cc index 5e087755d,10d8c040e..c9dd04b36 --- a/src/codecs/plugins/cd_gre.cc +++ b/src/codecs/plugins/cd_gre.cc @@@ -37,9 -37,8 +37,9 @@@ public ~GreCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -93,7 -100,7 +93,7 @@@ void GreCodec::get_protocol_ids(std::ve * Notes: see RFCs 1701, 2784 and 2637 */ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { if (len < GRE_HEADER_LEN) { diff --cc src/codecs/plugins/cd_gtp.cc index 1806fcad2,865a66d7c..ee249b854 --- a/src/codecs/plugins/cd_gtp.cc +++ b/src/codecs/plugins/cd_gtp.cc @@@ -44,12 -44,12 +44,12 @@@ namespac class GtpCodec : public Codec { public: - GtpCodec() : Codec("GTP"){}; + GtpCodec() : Codec("gtp"){}; ~GtpCodec(){}; - + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below @@@ -73,7 -69,7 +73,7 @@@ void GtpCodec::get_protocol_ids(std::ve */ bool GtpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { uint32_t header_len; uint8_t next_hdr_type; diff --cc src/codecs/plugins/cd_hopopts.cc index dc23d8ec1,a836d6024..cc98d5708 --- a/src/codecs/plugins/cd_hopopts.cc +++ b/src/codecs/plugins/cd_hopopts.cc @@@ -45,10 -47,8 +45,10 @@@ public ~NameCodec(); + + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); virtual void get_protocol_ids(std::vector&); virtual void get_data_link_type(std::vector&){}; diff --cc src/codecs/plugins/cd_mpls.cc index 60cb20f9d,665f059ac..95ca5dabe --- a/src/codecs/plugins/cd_mpls.cc +++ b/src/codecs/plugins/cd_mpls.cc @@@ -39,12 -39,12 +39,12 @@@ namespac class MplsCodec : public Codec { public: - MplsCodec() : Codec("MPLS"){}; + MplsCodec() : Codec("mpls"){}; ~MplsCodec(){}; - + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -63,15 -63,8 +63,15 @@@ const static uint32_t NUM_RESERVED_LABE static int checkMplsHdr(uint32_t, uint8_t, uint8_t, uint8_t, Packet *); +void MplsCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { uint32_t* tmpMplsHdr; uint32_t mpls_h; diff --cc src/codecs/plugins/cd_pppencap.cc index 44f8b683d,e878fd59a..3cf99983d --- a/src/codecs/plugins/cd_pppencap.cc +++ b/src/codecs/plugins/cd_pppencap.cc @@@ -41,9 -41,8 +41,9 @@@ public ~PppEncap(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -78,7 -74,7 +78,7 @@@ void PppEncap::get_protocol_ids(std::ve * Returns: void function */ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { static THREAD_LOCAL bool had_vj = false; uint16_t protocol; diff --cc src/codecs/plugins/cd_pppoepkt.cc index feebdd698,0a38970c2..8b2b962e0 --- a/src/codecs/plugins/cd_pppoepkt.cc +++ b/src/codecs/plugins/cd_pppoepkt.cc @@@ -35,9 -35,8 +35,9 @@@ public ~PPPoEPkt(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below #include "codecs/sf_protocols.h" @@@ -101,7 -93,7 +101,7 @@@ void PPPoEPkt::get_protocol_ids(std::ve * */ bool PPPoEPkt::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { //PPPoE_Tag *ppppoe_tag=0; //PPPoE_Tag tag; /* needed to avoid alignment problems */ diff --cc src/codecs/plugins/cd_routing.cc index a836d6024,a836d6024..36c6bf44d --- a/src/codecs/plugins/cd_routing.cc +++ b/src/codecs/plugins/cd_routing.cc @@@ -48,7 -48,7 +48,7 @@@ public virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); virtual void get_protocol_ids(std::vector&); virtual void get_data_link_type(std::vector&){}; diff --cc src/codecs/plugins/cd_swipe.cc index 1fe241a9d,4f8a54e9a..4dda224fc --- a/src/codecs/plugins/cd_swipe.cc +++ b/src/codecs/plugins/cd_swipe.cc @@@ -42,22 -42,14 +42,22 @@@ public SwipeCodec() : Codec("swipe"){}; virtual ~SwipeCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id); ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id); }; } // namespace + +void SwipeCodec::get_protocol_ids(std::vector &proto_ids) +{ + proto_ids.push_back(SWIPE_PROT_ID); +} + + bool SwipeCodec::decode(const uint8_t* raw_packet, const uint32_t raw_len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { codec_events::decoder_event(p, DECODE_IP_BAD_PROTO); diff --cc src/codecs/plugins/cd_teredo.cc index 989f80d86,ba2fcd12e..36ad5f3a1 --- a/src/codecs/plugins/cd_teredo.cc +++ b/src/codecs/plugins/cd_teredo.cc @@@ -50,22 -50,15 +50,22 @@@ public TeredoCodec() : Codec("teredo"){}; ~TeredoCodec(){}; - + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); }; } // anonymous namespace + +void TeredoCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { diff --cc src/codecs/plugins/cd_transbridge.cc index 9b2c06f43,55c6c9e54..a87cfb35d --- a/src/codecs/plugins/cd_transbridge.cc +++ b/src/codecs/plugins/cd_transbridge.cc @@@ -43,9 -43,8 +43,9 @@@ public ~TransbridgeCodec(){}; + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); }; @@@ -75,7 -70,7 +75,7 @@@ void TransbridgeCodec::get_protocol_ids * wasn't needed since we are already deep into the packet */ bool TransbridgeCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { // dc.gre_eth++; diff --cc src/codecs/plugins/cd_vlan.cc index 33b8e74c7,44f44657b..5203b2a43 --- a/src/codecs/plugins/cd_vlan.cc +++ b/src/codecs/plugins/cd_vlan.cc @@@ -39,9 -39,9 +39,9 @@@ public VlanCodec() : Codec("vlan"){}; ~VlanCodec(){}; - + virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); // DELETE from here and below @@@ -60,14 -73,8 +60,14 @@@ static inline uint32_t len_vlan_llc_oth } +void VlanCodec::get_protocol_ids(std::vector& 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) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { // dc.vlan++; diff --cc src/codecs/template.cc index 67b313c74,d7c95aa50..a55fd4698 --- a/src/codecs/template.cc +++ b/src/codecs/template.cc @@@ -40,7 -40,7 +40,7 @@@ public virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *, uint16_t &lyr_len, int &next_prot_id); ++ Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); virtual void get_protocol_ids(std::vector&); virtual void get_data_link_type(std::vector&){}; @@@ -55,7 -55,7 +55,7 @@@ static CdPegs gcounts bool NameCodec::decode(const uint8_t *raw_pkt, const uint32_t len, -- Packet *p, uint16_t &lyr_len, int &next_prot_id) ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) { } diff --cc src/framework/codec.h index 41107319d,1a8cef33c..133339a72 --- a/src/framework/codec.h +++ b/src/framework/codec.h @@@ -46,18 -51,13 +46,18 @@@ public virtual ~Codec() { }; 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!! ++ Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) = 0; + // 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&) {}; + // Register the code's protocol ID's and Ethertypes + virtual void get_protocol_ids(std::vector&) = 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; }; diff --cc src/managers/packet_manager.cc index 599b2d018,09f127245..8983dcb7f --- a/src/managers/packet_manager.cc +++ b/src/managers/packet_manager.cc @@@ -62,33 -61,13 +62,34 @@@ THREAD_LOCAL PreprocStats decodePerfSta static const uint16_t max_protocol_id = 65535; static std::list s_codecs; -static std::array s_protocols; +//static std::array s_protocols; + - // statistics information - static THREAD_LOCAL std::array s_stats; - static std::array g_stats; - static THREAD_LOCAL CdGenPegs pkt_cnt; + +static std::array s_proto_map{}; +static std::array s_protocols{}; +static THREAD_LOCAL uint8_t grinder = 0; + // statistics information -static THREAD_LOCAL std::array s_stats; -static std::array g_stats; ++static THREAD_LOCAL std::array s_stats; ++static std::array g_stats; + static THREAD_LOCAL CdGenPegs pkt_cnt; + +//------------------------------------------------------------------------- +// helper functions +//------------------------------------------------------------------------- + +// note that we now have multiple preproc configs saved by parser +// (s5-global, s5-tcp, ..., etc.) but just one ppapi. that means +// we must call the config func multiple times but add only the 1st +// instance to the policy list. +static inline const CodecApi* GetApi(const char* keyword) +{ + for ( auto* p : s_codecs ) + if ( !strncasecmp(p->base.name, keyword, strlen(p->base.name)) ) + return p; + return NULL; +} + //------------------------------------------------------------------------- // plugins @@@ -245,19 -211,20 +246,19 @@@ void PacketManager::set_grinder(void { 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(), ++ s_protocols[grinder]->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(!grinder) + FatalError("Unable to find a Codec with data link type %d!!\n", daq_dlt); } void PacketManager::thread_term() @@@ -302,55 -269,6 +303,44 @@@ 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 mapped_prot, 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; ++ mapped_prot = grinder; + pkt_cnt.total_processed++; + + // loop until the protocol id is no longer valid - while(curr_prot_id >= 0 && curr_prot_id < max_protocol_id) ++ while(s_protocols[mapped_prot]->decode(pkt, len, p, lyr_len, next_prot_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; ++ mapped_prot = s_proto_map[next_prot_id]; ++ PacketClass::PushLayer(p, s_protocols[mapped_prot], pkt, lyr_len); ++ s_stats[mapped_prot + stat_offset]++; + len -= lyr_len; + pkt += lyr_len; ++ next_prot_id = FINISHED_DECODE; // necessary in case decode returns true an + 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; diff --cc src/protocols/undefined_protocols.h index cdc15bc9f,cdc15bc9f..b04584b35 --- a/src/protocols/undefined_protocols.h +++ b/src/protocols/undefined_protocols.h @@@ -28,7 -28,7 +28,7 @@@ * 256 (0x0100) - 1535 (0x05FF) --> random protocols (teredo, gtp) * 1536 (0x6000) - 65536 (0xFFFF) --> Ethertypes */ --const uint16_t GRINDER_ID = 0x0100; ++const uint16_t FINISHED_DECODE = 0x0100; const uint16_t PROTOCOL_TEREDO = 0x0101; const uint16_t PROTOCOL_GTP = 0x0102;