From: Josh Date: Thu, 17 Apr 2014 21:03:38 +0000 (-0400) Subject: adding vlah codec. changed directory names X-Git-Tag: 3.0.0-233~1559^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=608926c47ce52def8faffb26dac9cbb79aa78370;p=thirdparty%2Fsnort3.git adding vlah codec. changed directory names --- diff --git a/src/codecs/CMakeLists.txt b/src/codecs/CMakeLists.txt index 8cc369821..5ac8dfd4a 100644 --- a/src/codecs/CMakeLists.txt +++ b/src/codecs/CMakeLists.txt @@ -1,6 +1,6 @@ -add_subdirectory(essential) +add_subdirectory(basic) add_subdirectory(plugins) add_subdirectory(chained) @@ -32,7 +32,7 @@ add_library( codecs STATIC target_link_libraries( codecs - essential + basic_codecs codec_plugins protocols sfip diff --git a/src/codecs/essential/CMakeLists.txt b/src/codecs/basic/CMakeLists.txt similarity index 67% rename from src/codecs/essential/CMakeLists.txt rename to src/codecs/basic/CMakeLists.txt index c2de794fb..888715392 100644 --- a/src/codecs/essential/CMakeLists.txt +++ b/src/codecs/basic/CMakeLists.txt @@ -1,7 +1,7 @@ -add_library( essential +add_library( basic_codecs cd_icmp4.cc cd_icmp6.cc cd_ipv4.cc @@ -11,6 +11,6 @@ add_library( essential cd_eth.cc ) -target_link_libraries( essential +target_link_libraries( basic_codecs protocols ) diff --git a/src/codecs/essential/cd_eth.cc b/src/codecs/basic/cd_eth.cc similarity index 100% rename from src/codecs/essential/cd_eth.cc rename to src/codecs/basic/cd_eth.cc diff --git a/src/codecs/essential/cd_icmp4.cc b/src/codecs/basic/cd_icmp4.cc similarity index 100% rename from src/codecs/essential/cd_icmp4.cc rename to src/codecs/basic/cd_icmp4.cc diff --git a/src/codecs/essential/cd_icmp6.cc b/src/codecs/basic/cd_icmp6.cc similarity index 100% rename from src/codecs/essential/cd_icmp6.cc rename to src/codecs/basic/cd_icmp6.cc diff --git a/src/codecs/essential/cd_ipv4.cc b/src/codecs/basic/cd_ipv4.cc similarity index 100% rename from src/codecs/essential/cd_ipv4.cc rename to src/codecs/basic/cd_ipv4.cc diff --git a/src/codecs/essential/cd_ipv6.cc b/src/codecs/basic/cd_ipv6.cc similarity index 100% rename from src/codecs/essential/cd_ipv6.cc rename to src/codecs/basic/cd_ipv6.cc diff --git a/src/codecs/essential/cd_tcp.cc b/src/codecs/basic/cd_tcp.cc similarity index 100% rename from src/codecs/essential/cd_tcp.cc rename to src/codecs/basic/cd_tcp.cc diff --git a/src/codecs/essential/cd_udp.cc b/src/codecs/basic/cd_udp.cc similarity index 100% rename from src/codecs/essential/cd_udp.cc rename to src/codecs/basic/cd_udp.cc diff --git a/src/codecs/encode.cc b/src/codecs/encode.cc index d625c9376..6f05bc5b9 100644 --- a/src/codecs/encode.cc +++ b/src/codecs/encode.cc @@ -105,7 +105,8 @@ typedef struct { // PKT_MAX is sized to ensure that any reassembled packet // can accommodate a full datagram at innermost layer -#define PKT_MAX (ETHERNET_HEADER_LEN + VLAN_HEADER_LEN + ETHERNET_MTU + IP_MAXPACKET) +// 4 == VLAN_HEADER +#define PKT_MAX (ETHERNET_HEADER_LEN + 4 + ETHERNET_MTU + IP_MAXPACKET) // all layer encoders look like this: typedef ENC_STATUS (*Encoder)(EncState*, Buffer* in, Buffer* out); diff --git a/src/codecs/plugins/CMakeLists.txt b/src/codecs/plugins/CMakeLists.txt index c8bce02bc..49a0b717c 100644 --- a/src/codecs/plugins/CMakeLists.txt +++ b/src/codecs/plugins/CMakeLists.txt @@ -3,6 +3,7 @@ add_library( codec_plugins STATIC cd_swipe.cc cd_teredo.cc cd_gtp.cc + cd_vlan.cc ) diff --git a/src/codecs/tmp/prot_vlan.cc b/src/codecs/plugins/cd_vlan.cc similarity index 64% rename from src/codecs/tmp/prot_vlan.cc rename to src/codecs/plugins/cd_vlan.cc index 444028995..d9d31a637 100644 --- a/src/codecs/tmp/prot_vlan.cc +++ b/src/codecs/plugins/cd_vlan.cc @@ -26,43 +26,63 @@ #include "config.h" #endif -#include "generators.h" -#include "decode.h" -#include "static_include.h" +#include "protocols/packet.h" +#include "codecs/decode_module.h" +#include "codecs/codec_events.h" +#include "codecs/decode.h" -#include "decoder_includes.h" -#include "prot_vlan.h" -#include "prot_arp.h" -#include "prot_ipv4.h" -#include "prot_ipv6.h" -#include "prot_ethloopback.h" -#include "prot_pppoepkt.h" #define LEN_VLAN_LLC_OTHER (sizeof(VlanTagHdr) + sizeof(EthLlc) + sizeof(EthLlcOther)) -void VLAN::Decode(const uint8_t *pkt, const uint32_t len, - Packet *p, uint16_t &p_hdr_len, uint16_t &next_prot_id) +const uint16_t ETHERNET_TYPE_8021Q = 0x8100; + + + +namespace +{ + +class VlanCodec : public Codec { - dc.vlan++; +public: + VlanCodec() : Codec("vlan"){}; + ~VlanCodec(); + + + virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, + Packet *, uint16_t &p_hdr_len, int &next_prot_id); + + virtual void get_protocol_ids(std::vector&); + virtual void get_data_link_type(std::vector&){}; + +}; - if (p->greh != NULL) - dc.gre_vlan++; +} // anonymous namespace + + + +bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len, + Packet *p, uint16_t &p_hdr_len, int &next_prot_id) +{ +// dc.vlan++; + +// if (p->greh != NULL) +// dc.gre_vlan++; if(len < sizeof(VlanTagHdr)) { - DecoderEvent(p, DECODE_BAD_VLAN, DECODE_BAD_VLAN_STR); + DecoderEvent(p, DECODE_BAD_VLAN); // TBD add decoder drop event for VLAN hdr len issue - dc.discards++; +// dc.discards++; p->iph = NULL; p->family = NO_IP; - return; + return false; } - p->vh = (VlanTagHdr *) pkt; + p->vh = (VlanTagHdr *) raw_pkt; DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Vlan traffic:\n"); DebugMessage(DEBUG_DECODE, " Priority: %d(0x%X)\n", @@ -81,16 +101,15 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len, { if(len < sizeof(VlanTagHdr) + sizeof(EthLlc)) { - DecoderEvent(p, DECODE_BAD_VLAN_ETHLLC, - DECODE_BAD_VLAN_ETHLLC_STR); + DecoderEvent(p, DECODE_BAD_VLAN_ETHLLC); - dc.discards++; +// dc.discards++; p->iph = NULL; p->family = NO_IP; - return; + return false; } - p->ehllc = (EthLlc *) (pkt + sizeof(VlanTagHdr)); + p->ehllc = (EthLlc *) (raw_pkt + sizeof(VlanTagHdr)); DEBUG_WRAP( DebugMessage(DEBUG_DECODE, "LLC Header:\n"); @@ -102,17 +121,16 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len, { if ( len < LEN_VLAN_LLC_OTHER ) { - DecoderEvent(p, DECODE_BAD_VLAN_OTHER, - DECODE_BAD_VLAN_OTHER_STR); + DecoderEvent(p, DECODE_BAD_VLAN_OTHER); - dc.discards++; +// dc.discards++; p->iph = NULL; p->family = NO_IP; - return; + return false; } - p->ehllcother = (EthLlcOther *) (pkt + sizeof(VlanTagHdr) + sizeof(EthLlc)); + p->ehllcother = (EthLlcOther *) (raw_pkt + sizeof(VlanTagHdr) + sizeof(EthLlc)); DEBUG_WRAP( DebugMessage(DEBUG_DECODE, "LLC Other Header:\n"); @@ -128,19 +146,21 @@ void VLAN::Decode(const uint8_t *pkt, const uint32_t len, // PushLayer(PROTO_VLAN, p, pkt, sizeof(*p->vh)); p_hdr_len = LEN_VLAN_LLC_OTHER; - next_prot_id = ntohs(p->ehllcother->proto_id) + next_prot_id = ntohs(p->ehllcother->proto_id); } } else { p_hdr_len = sizeof(VlanTagHdr); - next_prot_id = ntohs(p->vh->vth_proto) + next_prot_id = ntohs(p->vh->vth_proto); } return true; } +#if 0 + /* * ENCODER */ @@ -148,20 +168,51 @@ void VLAN_Format (EncodeFlags, const Packet*, Packet* c, Layer* lyr) { c->vh = (VlanTagHdr*)lyr->start; } +#endif + + + +void VlanCodec::get_protocol_ids(std::vector& v) +{ + v.push_back(ETHERNET_TYPE_8021Q); +} + +static Codec* ctor() +{ + return new VlanCodec(); +} + +static void dtor(Codec *cd) +{ + delete cd; +} + +static void sum() +{ +// sum_stats((PegCount*)&gdc, (PegCount*)&dc, array_size(dc_pegs)); +// memset(&dc, 0, sizeof(dc)); +} + +static void stats() +{ +// show_percent_stats((PegCount*)&gdc, dc_pegs, array_size(dc_pegs), +// "decoder"); +} + -static const char* name = "vlan_decode"; +static const char* name = "VLAN"; -static const CodecApi tcp_api = +static const CodecApi vlan_api = { { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 }, - {ETHERNET_TYPE_8021Q}, NULL, // pinit NULL, // pterm NULL, // tinit NULL, // tterm - NULL, // ctor - NULL, // dtor - Vlan::Decode, + ctor, // ctor + dtor, // dtor + sum, // sum + stats // stats }; diff --git a/src/codecs/tmp/prot_vlan.h b/src/codecs/tmp/prot_vlan.h deleted file mode 100644 index 5f303923d..000000000 --- a/src/codecs/tmp/prot_vlan.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -** Copyright (C) 2002-2013 Sourcefire, Inc. -** Copyright (C) 1998-2002 Martin Roesch -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License Version 2 as -** published by the Free Software Foundation. You may not use, modify or -** distribute this program under any other version of the GNU General -** Public License. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - - -#ifndef PROT_VLAN_H -#define PROT_VLAN_H - -#include "encode.h" - - -#define VLAN_HEADER_LEN 4 -#define ETHERNET_TYPE_8021Q 0x8100 - - - -#endif \ No newline at end of file diff --git a/src/codecs/tmp/template.cc b/src/codecs/tmp/template.cc index 8a4feb700..aa6e1110b 100644 --- a/src/codecs/tmp/template.cc +++ b/src/codecs/tmp/template.cc @@ -83,9 +83,23 @@ static void dtor(Codec *cd) delete cd; } +static void sum() +{ +// sum_stats((PegCount*)&gdc, (PegCount*)&dc, array_size(dc_pegs)); +// memset(&dc, 0, sizeof(dc)); +} + +static void stats() +{ +// show_percent_stats((PegCount*)&gdc, dc_pegs, array_size(dc_pegs), +// "decoder"); +} + + + static const char* name = "name_codec"; -static const CodecApi ipv6_api = +static const CodecApi codec_api = { { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 }, NULL, // pinit @@ -94,5 +108,7 @@ static const CodecApi ipv6_api = NULL, // tterm ctor, // ctor dtor, // dtor + sum, // sum + stats // stats }; diff --git a/src/network_inspectors/defrag/defrag.cc b/src/network_inspectors/defrag/defrag.cc index 241c9deab..4e4d4b363 100644 --- a/src/network_inspectors/defrag/defrag.cc +++ b/src/network_inspectors/defrag/defrag.cc @@ -95,7 +95,6 @@ #include "snort_debug.h" #include "parser.h" #include "mstring.h" -//#include "checksum.h" #include "perf_monitor/perf.h" #include "timersub.h" #include "fpcreate.h"