]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Main Packet struct is now allocated using PacketManager::encode_new()
authorJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 19:47:15 +0000 (15:47 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 19:47:15 +0000 (15:47 -0400)
1  2 
src/main/modules.cc
src/main/snort.cc
src/main/snort_config.h
src/managers/codec_manager.cc
src/managers/codec_manager.h
src/protocols/packet_manager.cc
src/protocols/packet_manager.h

Simple merge
index 5923c36a031ccf627463f3974dad6e8a936aff49,cabc87c0c42e8c7bce6c779a278ba3a49bc631c3..e1087ec9be8f2112adc8c4353dbc6c0548e0bf4b
@@@ -117,7 -117,6 +117,7 @@@ using namespace std
  
  //-------------------------------------------------------------------------
  
- static THREAD_LOCAL Packet s_packet; // runtime variable.
++static THREAD_LOCAL Packet* s_packet; // runtime variable.
  THREAD_LOCAL SnortConfig* snort_conf = nullptr;
  static SnortConfig* snort_cmd_line_conf = nullptr;
  
@@@ -702,7 -673,7 +674,7 @@@ void set_main_hook(MainHook_f f
  { main_hook = f; }
  
  Packet* get_current_packet()
--{ return &s_packet; }
++{ return s_packet; }
  
  // FIXIT-J for multiple packet threads
  // using thread locals for s_pkth and s_data won't work
  // capture all if it is not clear which thread crashed
  void CapturePacket()
  {
--    if ( s_packet.pkth )
++    if ( s_packet->pkth )
      {
--        s_pkth = *s_packet.pkth;
++        s_pkth = *(s_packet->pkth);
  
--        if ( s_packet.pkt )
 -            memcpy(s_data, s_packet.pkt, 0xFFFF & s_packet.pkth->caplen);
++        if ( s_packet->pkt )
 +        {
-             memcpy(s_data, s_packet.pkt, 0xFFFF & s_packet.pkth->caplen);
-             s_packet.pkt = s_data;
++            memcpy(s_data, s_packet->pkt, 0xFFFF & s_packet->pkth->caplen);
++            s_packet->pkt = s_data;
 +        }
      }
  }
  
@@@ -873,9 -821,9 +825,9 @@@ DAQ_Verdict packet_callback
  
      ActionManager::reset_queue();
  
--    verdict = ProcessPacket(&s_packet, pkthdr, pkt);
++    verdict = ProcessPacket(s_packet, pkthdr, pkt);
  
--    ActionManager::execute(&s_packet);
++    ActionManager::execute(s_packet);
  
      if ( Active_PacketWasDropped() )
      {
      }
      else
      {
--        Packet* p = &s_packet;
--        if ( s_packet.packet_flags & PKT_MODIFIED )
++        if ( s_packet->packet_flags & PKT_MODIFIED )
          {
              // this packet was normalized and/or has replacements
--            PacketManager::encode_update(&s_packet);
++            PacketManager::encode_update(s_packet);
              verdict = DAQ_VERDICT_REPLACE;
          }
--        else if ( p->packet_flags & PKT_RESIZED )
++        else if ( s_packet->packet_flags & PKT_RESIZED )
          {
--            printf("packet flags = 0x%X\n", p->packet_flags);
++            printf("packet flags = 0x%X\n", s_packet->packet_flags);
              // we never increase, only trim, but
              // daq doesn't support resizing wire packet
--            if ( !DAQ_Inject(s_packet.pkth, 0, s_packet.pkt, s_packet.pkth->pktlen) )
++            if ( !DAQ_Inject(s_packet->pkth, 0, s_packet->pkt, s_packet->pkth->pktlen) )
              {
                  verdict = DAQ_VERDICT_BLOCK;
                  inject = 1;
          }
          else
          {
--            if ( (s_packet.packet_flags & PKT_IGNORE) ||
--                (stream.get_ignore_direction(s_packet.flow) == SSN_DIR_BOTH) )
++            if ( (s_packet->packet_flags & PKT_IGNORE) ||
++                (stream.get_ignore_direction(s_packet->flow) == SSN_DIR_BOTH) )
              {
                  if ( !Active_GetTunnelBypass() )
                  {
                      pc.internal_whitelist++;
                  }
              }
--            else if ( s_packet.ptrs.decode_flags & DECODE_PKT_TRUST )
++            else if ( s_packet->ptrs.decode_flags & DECODE_PKT_TRUST )
              {
--                stream.set_ignore_direction(s_packet.flow, SSN_DIR_BOTH);
++                stream.set_ignore_direction(s_packet->flow, SSN_DIR_BOTH);
  
                  verdict = DAQ_VERDICT_WHITELIST;
              }
          flow_con->timeout_flows(4, pkthdr->ts.tv_sec);
      }
  
--    s_packet.pkth = NULL;  // no longer avail on segv
++    s_packet->pkth = NULL;  // no longer avail on segv
  
      if ( snort_conf->pkt_cnt && pc.total_from_daq >= snort_conf->pkt_cnt )
          DAQ_BreakLoop(-1);
@@@ -967,7 -915,7 +918,8 @@@ void snort_thread_init(const char* intf
      DAQ_New(snort_conf, intf);
      DAQ_Start();
  
-     CodecManager::thread_init(snort_conf, s_packet);
++    s_packet = PacketManager::encode_new();
+     CodecManager::thread_init();
      FileAPIPostInit();
  
      // this depends on instantiated daq capabilities
@@@ -999,7 -947,6 +951,13 @@@ void snort_thread_term(
      ActionManager::thread_term(snort_conf);
      IpsManager::clear_options();
      EventManager::close_outputs();
-     CodecManager::thread_term(s_packet);
++    CodecManager::thread_term();
++
++    if (s_packet)
++    {
++        PacketManager::encode_delete(s_packet);
++        s_packet = nullptr;
++    }
  
      if ( DAQ_WasStarted() )
          DAQ_Stop();
index 71009394cf42829241c4e6273cc64fef09bbf3dd,d293253a9df5caa237f97b9b52481f63509245c6..333d630504fb6afce2a98d09bbc7961d2049adac
@@@ -284,23 -281,14 +284,23 @@@ struct SnortConfi
      bool unit_test;
  #endif
  
-     InspectionPolicy* get_inspection_policy() const
-     { return policy_map->get_inspection_policy(); };
+     InspectionPolicy* get_inspection_policy()
+     { return policy_map->inspection_policy[0]; };
  
-     IpsPolicy* get_ips_policy() const
-     { return policy_map->get_ips_policy(); };
+     IpsPolicy* get_ips_policy()
+     { return policy_map->ips_policy[0]; };
  
-     NetworkPolicy* get_network_policy() const
-     { return policy_map->get_network_policy(); };
+     NetworkPolicy* get_network_policy()
+     { return policy_map->network_policy[0]; };
 +
 +    inline uint8_t get_num_layers() const
 +    { return num_layers; }
 +
 +    inline uint8_t get_ip6_maxopts() const
 +    { return max_ip6_options; }
 +
 +    inline uint8_t get_ip_maxlayers() const
 +    { return max_ip_layers; }
  };
  
  SnortConfig* SnortConfNew(void);
index 310f8e91832569ebc65a5f91308b2d9d618f09e9,b2637e17a9f9a3aa2b566eab3dc149522eafd099..000c319a78d892213d33e2c05b2600cf310c529c
@@@ -197,11 -196,8 +197,8 @@@ void CodecManager::instantiate(
          instantiate(wrap, nullptr, nullptr);
  }
  
- void CodecManager::thread_init(const SnortConfig* const sc, Packet& p)
 -void CodecManager::thread_init(void)
++void CodecManager::thread_init()
  {
-     max_layers = sc->get_num_layers();
-     p.layers = new Layer[max_layers];
      for ( CodecApiWrapper& wrap : s_codecs )
          if (wrap.api->tinit)
              wrap.api->tinit();
index deb10efc35c2a04f0901ec8026ef56e3fc950881,a29467bda1151d33a8f3773fdcee4a52157dab81..13f8636b9069b160c5df30f7c5c21488136d5c2c
@@@ -62,10 -62,10 +62,10 @@@ public
      static void instantiate();
      // destroy all global codec related information
      static void release_plugins();
 -    // initialize the current threads codecs
 +    // initialize the current threads DLT and Packet struct
-     static void thread_init(const SnortConfig* const, Packet&);
+     static void thread_init();
      // destroy thread_local data
-     static void thread_term(Packet&);
+     static void thread_term();
      // print all of the codec plugins
      static void dump_plugins();
  
index 9ec1df09ba590bae646b361b3a63ddebd8248bbc,38d44c89daefcb6951584d3a56d688e2bdc28032..60554bd88d87c1e317fa5127eaae0398c5b63575
@@@ -105,9 -103,8 +105,9 @@@ Packet* PacketManager::encode_new(
  {
      Packet* p = (Packet*)SnortAlloc(sizeof(*p));
      uint8_t* b = (uint8_t*)SnortAlloc(sizeof(*p->pkth) + Codec::PKT_MAX + SPARC_TWIDDLE);
-     Layer* lyr = (Layer*)SnortAlloc(sizeof(Layer) * CodecManager::max_layers);
++    Layer* lyr = new Layer[CodecManager::max_layers];
  
 -    if ( !p || !b )
 +    if ( !p || !b || !lyr)
          FatalError("encode_new() => Failed to allocate packet\n");
  
      p->pkth = (DAQ_PktHdr_t*)b;
@@@ -123,14 -119,9 +123,14 @@@ void PacketManager::encode_delete(Packe
  {
      if (p)
      {
 -        if (p->pkth)
 +        if(p->pkth)
              free((void*)p->pkth);  // cast away const!
  
-             free(p->layers);
 +        if(p->layers)
++            delete[] p->layers;
 +
 +        p->pkth = nullptr;
 +        p->layers = nullptr;
          free(p);
      }
  }
index c472bcd323801dcbf468313e0a90995d5c459a6d,e100fb4d19f10074357921535437b6dc38b9841d..bf18280964d00f833d826b5f0adb30c3612055a0
@@@ -143,10 -126,8 +143,10 @@@ private
      //  STATISTICS!!
  
      // The only time we should accumulate is when CodecManager tells us too
-     friend void CodecManager::thread_term(Packet&);
+     friend void CodecManager::thread_term();
      static void accumulate();
 +    static bool encode(const Packet* p, EncodeFlags,
 +        uint8_t lyr_start, uint8_t next_prot, Buffer& buf);
  
      // constant offsets into the s_stats array.  Notice the stat_offset
      // constant which is used when adding a protocol specific codec