]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Refactor packet manager
authorJosh <jrosenba@cisco.com>
Wed, 30 Apr 2014 21:36:39 +0000 (17:36 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 30 Apr 2014 21:36:39 +0000 (17:36 -0400)
src/codecs/basic/cd_esp.cc
src/codecs/basic/cd_icmp6.cc
src/codecs/basic/cd_tcp.cc
src/codecs/plugins/cd_arp.cc
src/codecs/plugins/cd_mpls.cc
src/codecs/plugins/cd_pppencap.cc
src/codecs/plugins/cd_swipe.cc
src/ips_options/ips_icmp_id.cc
src/ips_options/ips_icmp_seq.cc
src/network_inspectors/normalize/norm.cc
src/protocols/ipv6.h

index d37482d90b30b95d2259aa228935da3fd19780a9..1604a3b7eb06efa90df24b99794019086c25b171 100644 (file)
@@ -30,6 +30,7 @@
 #include "codecs/decode_module.h"
 #include "managers/packet_manager.h"
 #include "events/codec_events.h"
+#include "protocols/undefined_protocols.h"
 
 namespace
 {
@@ -122,9 +123,7 @@ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     else
     {
         p->packet_flags |= PKT_TRUST;
-        p->data = esp_payload;
-        p->dsize = (u_short) len - lyr_len;
-        next_prot_id = -1;
+        next_prot_id = FINISHED_DECODE;
         return true;
     }
 
index 33f8d63e5de8088aab3a253b71c3d81a35591672..bd13cd989c49c58e79b390f145e20d62906044a9 100644 (file)
@@ -67,8 +67,10 @@ void Icmp6Codec::get_protocol_ids(std::vector<uint16_t>& v)
 
 
 static void DecodeICMPEmbeddedIP6(const uint8_t *pkt, const uint32_t len, Packet *p);
-static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int);
 
+#if 0
+static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int);
+#endif
 
 
 //--------------------------------------------------------------------
@@ -76,7 +78,7 @@ static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int);
 //--------------------------------------------------------------------
 
 bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len, 
-    Packet* p, uint16_t &lyr_len, uint16_t &next_prot_id)
+    Packet* p, uint16_t &lyr_len, uint16_t & /* next_prot_id */)
 {
     if(len < icmp6::hdr_min_len())
     {
@@ -331,7 +333,6 @@ bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len,
 
     p->proto_bits |= PROTO_BIT__ICMP;
     p->proto_bits &= ~(PROTO_BIT__UDP | PROTO_BIT__TCP);
-    next_prot_id = -1;
     return true;
 }
 
index 26f2e44a9d20e764434b825fd7f616b3784d162f..940bc95df927d660980d4c402f7c6a031f372064 100644 (file)
@@ -59,7 +59,7 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+        Packet *, uint16_t &lyr_len, uint16_t &);
 
 
     // DELETE
@@ -106,7 +106,7 @@ void TcpCodec::get_protocol_ids(std::vector<uint16_t>& v)
  * Returns: void function
  */
 bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+        Packet *p, uint16_t &lyr_len, uint16_t& /*next_prot_id*/)
 {
     if(len < tcp::hdr_len())
     {
@@ -116,9 +116,6 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         codec_events::decoder_event(p, DECODE_TCP_DGRAM_LT_TCPHDR);
 
         p->tcph = NULL;
-//        dc.discards++;
-//        dc.tdisc++;
-
         return false;
     }
 
index 4ac2206d81711faaff09a4d348ef00eda47525a3..3aab33cca629098acfc52bbbe0f293a6eff640d7 100644 (file)
@@ -40,7 +40,7 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+        Packet *, uint16_t &lyr_len, uint16_t &);
     
 
     // DELETE from here and below
@@ -78,10 +78,8 @@ void ArpCodec::get_protocol_ids(std::vector<uint16_t>& v)
  * Returns: void function
  */
 bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+        Packet *p, uint16_t &lyr_len, uint16_t& /* next_prot_id */)
 {
-//    dc.arp++;
-
 //    if (p->greh != NULL)
 //        dc.gre_arp++;
 
@@ -90,15 +88,12 @@ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     if(len < sizeof(EtherARP))
     {
         codec_events::decoder_event(p, DECODE_ARP_TRUNCATED);
-
-//        dc.discards++;
         return false;
     }
 
     p->proto_bits |= PROTO_BIT__ARP;
     lyr_len = sizeof(*p->ah);
-    next_prot_id = -1;
-
+    
     return true;
 }
 
index 95ca5dabedea4aaeced30ea26a9d60887f8c430a..1f12ff1fa0d14be6edf831a2771ef8172d2fd6e0 100644 (file)
@@ -159,7 +159,6 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             break;
 
         default:
-            next_prot_id = -1;
             break;
     }
 
index 3cf99983ddad1044c0bc858545e1c537321f0857..fd8e0c55f6dcf47e6f9b9703dad10103a2f9c045 100644 (file)
@@ -93,7 +93,6 @@ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len,
 
     p->data = raw_pkt;
     p->dsize = (uint16_t)len;
-    next_prot_id = -1;
     return true;
 #endif  /* WORDS_MUSTALIGN */
 
@@ -167,7 +166,6 @@ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len,
             break;
 
         default:
-            next_prot_id = -1;
             break;
     }
     return true;
index c1c6eb900ccce293c19a71ad4f8ad0a56df3c706..ae49df3ffab195b9309653be9e894139a6a8e62f 100644 (file)
@@ -40,7 +40,7 @@ public:
     
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, 
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id);
+        Packet *p, uint16_t &lyr_len, uint16_t &);
 };
 
 } // namespace
@@ -53,7 +53,7 @@ void SwipeCodec::get_protocol_ids(std::vector<uint16_t> &proto_ids)
 
 
 bool SwipeCodec::decode(const uint8_t* raw_packet, const uint32_t raw_len, 
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+        Packet *p, uint16_t &lyr_len, uint16_t& /*next_prot_id*/)
 {
     // currently unsupported
     codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
index 63ff5fd68b9fcf891438efeef2c6a94d41cc632f..2c59aa351659d2b6ce216d62916e15c11c8117b6 100644 (file)
@@ -146,7 +146,7 @@ int IcmpIdOption::eval(Packet *p)
     PREPROC_PROFILE_START(icmpIdPerfStats);
 
     if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
-        || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY)
+        || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY)
       )
     {
         /* test the rule ID value against the ICMP extension ID field */
index 445f7ed27ae391e13f9ce0256d37b61a39ae2718..88972054b590bbb7b63d23623994c31523ddf7af 100644 (file)
@@ -145,7 +145,7 @@ int IcmpSeqOption::eval(Packet *p)
     PREPROC_PROFILE_START(icmpSeqPerfStats);
 
     if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
-        || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY)
+        || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY)
       )
     {
         /* test the rule ID value against the ICMP extension ID field */
index 80cc26a73149cf821b93d28f4551c6cc830cd548..afad6e60171b2594854cc1e6c4b490f67fb0634f 100644 (file)
@@ -283,7 +283,7 @@ static int Norm_ICMP6 (
 {
     ICMPHdr* h = (ICMPHdr*)(p->layers[layer].start);
 
-    if ( (h->type == (uint16_t)ICMP6_ECHO || h->type == (uint16_t)ICMP6_REPLY) &&
+    if ( ((uint16_t)h->type == ICMP6_ECHO || (uint16_t)h->type == ICMP6_REPLY) &&
          (h->code != 0) )
     {
         h->code = static_cast<icmp4::IcmpCode>(0);
index 8b7b6d6daee17ba489b3faada979fb68a694ba49..fe00136a884a97fa058b7be0cff5e50dad1eade9 100644 (file)
@@ -65,6 +65,9 @@ struct in6_addr
 #define IPRAW_HDR_VER(p_rawiph) \
    (ntohl(p_rawiph->ip6_vtf) >> 28)
 
+#if 0
+// defined in dnet.h and currently unused.
+
 #ifndef IP_PROTO_HOPOPTS
 # define IP_PROTO_HOPOPTS    0
 #endif
@@ -77,6 +80,7 @@ struct in6_addr
 #define IP_PROTO_ICMPV6     58
 #define IP_PROTO_IPV6       41
 #define IP_PROTO_IPIP       4
+#endif
 
 #define IP6F_OFFSET_MASK    0xfff8  /* mask out offset from _offlg */
 #define IP6F_MF_MASK        0x0001  /* more-fragments flag */