]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge with russ. Packet_manager.cc possibly screwed up
authorJosh <jrosenba@cisco.com>
Wed, 23 Apr 2014 17:33:44 +0000 (13:33 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 23 Apr 2014 17:33:44 +0000 (13:33 -0400)
1  2 
src/codecs/basic/cd_esp.cc
src/codecs/basic/cd_eth.cc
src/codecs/basic/cd_ipv4.cc
src/managers/packet_manager.cc

Simple merge
Simple merge
Simple merge
index caf88ae2c8f9e87fe75a6911a607cac2a2fa2f8d,ac281f723fbb1ee96ace54b0270762c42bf5dee3..9b1347e28af71cbcc23bd638d254fe70fa47dac7
  ** 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>
 +#include <vector>
  using namespace std;
  
- #include "packet_manager.h"
- #include "codec.h"
+ #include "framework/codec.h"
  #include "snort.h"
  #include "thread.h"
  #include "log/messages.h"
@@@ -126,22 -117,16 +122,23 @@@ 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, p_hdr_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, p_hdr_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, p_hdr_len);
          curr_prot_id = next_prot_id;
          len -= p_hdr_len;
@@@ -212,55 -242,21 +254,45 @@@ 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;
-     pegs.push_back(gpkt_cnt.total_processed);
-     pegs.push_back(gpkt_cnt.other_codecs);
-     pegs.push_back(gpkt_cnt.discards);
  
 -void PacketManager::dump_stats()
 -{
 -//    for ( auto* cd : s_codecs )
 -//        cd->sum();
 +    // 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();
 +//            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)
  {
      return s_protocols[cd_id] != 0;