]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Adding Codec patch from mac
authorJosh <jrosenba@cisco.com>
Fri, 25 Apr 2014 17:10:56 +0000 (13:10 -0400)
committerJosh <jrosenba@cisco.com>
Fri, 25 Apr 2014 17:10:56 +0000 (13:10 -0400)
1  2 
src/codecs/basic/cd_eth.cc
src/codecs/basic/cd_udp.cc
src/managers/packet_manager.cc

index 269f85f6f6131008659aa51985b20ab3cdf1204f,3982921c3351f3827f6091f8b36a3c7c6c5f5ee3..c151c33dbe148bcde850f0dd9e4621108a2ac088
@@@ -53,7 -60,10 +53,10 @@@ public
      
  };
  
- } // namespace
 -} // anonymous namespace
++} // anonymous
+ static const uint16_t MAX_LENGTH = 1500;
+ static const uint16_t MIN_ETHERTYPE = 1536;
  
  
  //--------------------------------------------------------------------
@@@ -114,9 -125,19 +117,18 @@@ bool EthCodec::decode(const uint8_t *ra
              );
  
      next_prot_id = ntohs(p->eh->ether_type);
-     lyr_len = eth::hdr_len();
 -
+     if (next_prot_id > MIN_ETHERTYPE )
+     {
 -        hdr_len = eth::hdr_len();
++        lyr_len = eth::hdr_len();
+         return true;
+     }
+ //   add this alert type
+ //    if(len > MAX_LENGTH) {
+ //        CodecEvents::decoder_event(p, DECODE_ETH_INVALID_FRAME);
  
-     return true;
+     return false;
  }
  
  
index 7221e390f21cda6bc09852eda7466b7bc569dc80,2ec025a8794da686c8b562322b00c20344451cfb..88bf737e030dd5934341a5653cb32aa835a85b56
@@@ -1,5 -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>
index 8b3bd9dc6935e2c77adcccbd6b733104452486b5,03a4d2bb63392e1af866eaa750581eb419393461..a00c19adc16975f5a17c5d861fdb8daee5f0e207
  ** 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 "packet_manager.h"
 -
  #include <list>
 -using namespace std;
 -
 +#include <vector>
 +#include <cstring>
- #include "framework/codec.h"
 +#include "packet_manager.h"
+ #include "framework/codec.h"
  #include "snort.h"
  #include "thread.h"
  #include "log/messages.h"
  
  #include "protocols/packet.h"
  #include "protocols/undefined_protocols.h"
 +#include "time/profiler.h"
  
  
 -#include "time/profiler.h"
 +namespace
 +{
 +struct CdGenPegs{
 +    PegCount total_processed = 0;
 +    PegCount other_codecs = 0;
 +    PegCount discards = 0;
 +};
  
- } // anonymous namespace
 +std::vector<const char*> CdGenPegNames =
 +{
 +    "total",
 +    "other",
 +    "discards"
 +};
 +
++} // anonymous
  
 -//static list<const CodecApi*> s_codecs;
 -//static THREAD_LOCAL decode_f grinder;
  
  #ifdef PERF_PROFILING
  THREAD_LOCAL PreprocStats decodePerfStats;
@@@ -130,27 -105,21 +126,27 @@@ void PacketManager::decode
      p->pkt = pkt;
      len = pkthdr->caplen;
      curr_prot_id = GRINDER_ID;
 +    pkt_cnt.total_processed++;
  
 -    // The boolean check in this order so 
 -    while(curr_prot_id  >= 0 && 
 -            curr_prot_id < max_protocol_id &&
 -            s_protocols[curr_prot_id] != 0 &&
 -            s_protocols[curr_prot_id]->decode(pkt, len, p, lyr_len, next_prot_id))
 +    // 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;
 +        }           
  
 -
 -        // if we have succesfully decoded this layer, push the layer
          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;
-         next_prot_id = -1;
          lyr_len = 0;
      }
  
@@@ -218,56 -231,19 +214,55 @@@ void PacketManager::set_grinder(void
  
          if (!codec_registered)
              WarningMessage("The Codec %s is never used\n", cd->get_name());
 -        // ERRRO:  If multiple correct grinders found.
      }
 +}
  
 +void PacketManager::dump_stats()
 +{
 +    sum_stats((PegCount*)&gpkt_cnt, (PegCount*)&pkt_cnt, array_size(CdGenPegNames));
  
 +    for ( auto* cd : s_codecs )
 +        if (cd->sum != nullptr)
 +            cd->sum();
  
 -//        FatalError("Codec installation checking!!");
 -}
 +    std::vector<const char*> pegNames(CdGenPegNames);
 +    std::vector<PegCount> pegs;
  
 +    std::memcpy(&pegs[0], &gpkt_cnt, sizeof(gpkt_cnt));
  
 -void PacketManager::dump_stats()
 -{
 -//    for ( auto* cd : s_codecs )
 -//        cd->sum();
 +//    pegs.push_back(gpkt_cnt.total_processed);
 +//    pegs.push_back(gpkt_cnt.other_codecs);
 +//    pegs.push_back(gpkt_cnt.discards);
 +
 +    // using two temporary vectors to ensure codecs cannot
 +    // see any other codecs statistics
 +    std::vector<const char*> tmpNames;
 +    std::vector<PegCount> tmpPegs;
 +
 +    for ( auto* cd : s_codecs )
 +    {
 +        if (cd->stats != nullptr)
 +        {
 +            tmpPegs.clear();
 +            tmpNames.clear();
 +            if(cd->stats)
 +                cd->stats(tmpPegs, tmpNames);
 +            if (tmpNames.size() == tmpPegs.size())
 +            {
 +                pegs.insert(pegs.end(), tmpPegs.begin(), tmpPegs.end());
 +                pegNames.insert(pegNames.end(), tmpNames.begin(), tmpNames.end());
 +            } 
 +            else
 +            {
 +                WarningMessage("The %s Codecs stats function returned a "
 +                    "different %d PegCounts and %d PegNames.  the two "
 +                    "values must be equal\n",
 +                    cd->base.name, pegs.size(), pegNames.size());
 +            }
 +        }
 +    }
 +    show_percent_stats(&pegs[0], &pegNames[0], pegNames.size(),
 +        "codecs");
  }
  
  bool PacketManager::has_codec(uint16_t cd_id)