]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Adding encoder backwards compatability
authorJosh <jrosenba@cisco.com>
Mon, 21 Apr 2014 21:07:25 +0000 (17:07 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 21 Apr 2014 21:07:25 +0000 (17:07 -0400)
22 files changed:
src/codecs/basic/cd_esp.cc
src/codecs/basic/cd_eth.cc
src/codecs/basic/cd_icmp4.cc
src/codecs/basic/cd_icmp6.cc
src/codecs/basic/cd_ipv4.cc
src/codecs/basic/cd_ipv6.cc
src/codecs/basic/cd_tcp.cc
src/codecs/basic/cd_udp.cc
src/codecs/plugins/cd_ah.cc
src/codecs/plugins/cd_arp.cc
src/codecs/plugins/cd_erspan2.cc
src/codecs/plugins/cd_erspan3.cc
src/codecs/plugins/cd_gre.cc
src/codecs/plugins/cd_gtp.cc
src/codecs/plugins/cd_mpls.cc
src/codecs/plugins/cd_pppencap.cc
src/codecs/plugins/cd_pppoepkt.cc
src/codecs/plugins/cd_vlan.cc
src/framework/codec.h
src/managers/packet_manager.cc
src/protocols/packet.cc
src/protocols/packet.h

index d6fa3edf3a46b72a754ab0b02dd6908609c466da..cea7def6ad6e6c37e0163bada320c91d9b53e2ee 100644 (file)
@@ -93,7 +93,6 @@ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 {
     const uint8_t *esp_payload;
     uint8_t pad_length;
-    uint8_t save_layer = p->next_layer;
 
     if (!ScESPDecoding())
         return false;
@@ -143,13 +142,13 @@ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     // set the data pointers and pretend this is an ip datagram.
     if (!PacketManager::has_codec(next_prot_id))
     {
-        p->packet_flags |= PKT_TRUST;
-        p->data = esp_payload;
-        p->dsize = (u_short) len - p_hdr_len;
+        p->packet_flags |= PKT_UNSURE_ENCAP;
     }
     else 
     {
-        p->packet_flags |= PKT_UNSURE_ENCAP;
+        p->packet_flags |= PKT_TRUST;
+        p->data = esp_payload;
+        p->dsize = (u_short) len - p_hdr_len;
     }
 
     return true;
index e55d9a8d9740123682370edd3bfa29ef7104c1f5..4ea76e65fe1da146ad1e90b48620a60fe7f74255 100644 (file)
@@ -54,6 +54,9 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual void get_data_link_type(std::vector<int>&);
+    // DELETE
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ETH; };
     
 };
 
index 01c29b2a90b02396509114dd42f09fe07b30a049..16ebc2316bb4effaf9631a00d4edae5a6474bf17 100644 (file)
@@ -62,11 +62,13 @@ public:
     
     virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, 
         Packet *p, uint16_t &p_hdr_len, int &next_prot_id);
-
-
     virtual void get_protocol_ids(std::vector<uint16_t>&);
 
 
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ICMP4; };
+
 private:
     PegCount packets;
     PegCount discards;
index adbf732c3e2120c78d81da01cd5ffb517dd999d6..df1d610ff607d0864f4ff81c94a9ca7f53f8094a 100644 (file)
@@ -47,8 +47,11 @@ public:
 
     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<uint16_t>&);
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ICMP6; };
     
 };
 
index 0658b15769a38117883fb7b5be8fb92467451a70..2aa1d791e4063f22eda322be58c6e75a87858e2e 100644 (file)
@@ -62,7 +62,10 @@ public:
     virtual void get_protocol_ids(std::vector<uint16_t>&);
 
     // used in random classes throughout Snort++
-    virtual inline bool is_ipv4(){ return true; };
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_IP4; };
 
 private:
 
@@ -126,7 +129,6 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
         Packet *p, uint16_t &p_hdr_len, int &next_prot_id)
 {
     uint32_t ip_len; /* length from the start of the ip hdr to the pkt end */
-    uint32_t hlen;   /* ip header length */
 
 //    dc.ip++;
 
@@ -197,14 +199,13 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
     ip_len = ntohs(p->iph->ip_len);
 
     /* get the IP header length */
-    hlen = ipv4::get_pkt_hdr_len(p->iph) << 2;
-    p_hdr_len = hlen;
+    p_hdr_len = ipv4::get_pkt_hdr_len(p->iph) << 2;
 
     /* header length sanity check */
-    if(hlen < ipv4::hdr_len())
+    if(p_hdr_len < ipv4::hdr_len())
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
-            "Bogus IP header length of %i bytes\n", hlen););
+            "Bogus IP header length of %i bytes\n", p_hdr_len););
 
         DecoderEvent(p, DECODE_IPV4_INVALID_HEADER_LEN);
 
@@ -247,11 +248,11 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
     }
 #endif
 
-    if(ip_len < hlen)
+    if(ip_len < p_hdr_len)
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
             "IP dgm len (%d bytes) < IP hdr "
-            "len (%d bytes), packet discarded\n", ip_len, hlen););
+            "len (%d bytes), packet discarded\n", ip_len, p_hdr_len););
 
         DecoderEvent(p, DECODE_IPV4_DGRAM_LT_IPHDR);
 
@@ -274,7 +275,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
          * need to check them (should make this a command line/config
          * option
          */
-        int16_t csum = in_chksum_ip((u_short *)p->iph, hlen);
+        int16_t csum = in_chksum_ip((u_short *)p->iph, p_hdr_len);
 
         if(csum)
         {
@@ -293,7 +294,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
     }
 
     /* test for IP options */
-    p->ip_options_len = (uint16_t)(hlen - ipv4::hdr_len());
+    p->ip_options_len = (uint16_t)(p_hdr_len - ipv4::hdr_len());
 
     if(p->ip_options_len > 0)
     {
@@ -320,7 +321,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
     p->actual_ip_len = (uint16_t) ip_len;
 
     /* set the remaining packet length */
-    ip_len -= hlen;
+    ip_len -= p_hdr_len;
 
     /* check for fragmented packets */
     p->frag_offset = ntohs(p->iph->ip_off);
@@ -353,7 +354,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
         {
             /* set the packet fragment flag */
             p->frag_flag = 1;
-            p->ip_frag_start = raw_packet + hlen;
+            p->ip_frag_start = raw_packet + p_hdr_len;
             p->ip_frag_len = (uint16_t)ip_len;
 //            dc.frags++;
         }
@@ -369,7 +370,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
     }
 
     /* Set some convienience pointers */
-    p->ip_data = raw_packet + hlen;
+    p->ip_data = raw_packet + p_hdr_len;
     p->ip_dsize = (u_short) ip_len;
 
     /* See if there are any ip_proto only rules that match */
@@ -386,20 +387,18 @@ bool Ipv4Codec::decode(const uint8_t *raw_packet, const uint32_t len,
             (p->iph->ip_proto == IPPROTO_UDP)))
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "IP header length: %lu\n",
-                    (unsigned long)hlen););
+                    (unsigned long)p_hdr_len););
 
         next_prot_id = p->iph->ip_proto;
-        p_hdr_len = hlen;
         return true;
     }
     else
     {
         /* set the payload pointer and payload size */
-        p->data = raw_packet + hlen;
+        p->data = raw_packet + p_hdr_len;
         p->dsize = (u_short) ip_len;
     }
 
-    p_hdr_len = hlen;
     return true;
 }
 
index 96e89e29ca606f1dcdfebca704dabbd11f03c56e..b745ef3197b5368d909870e654a19bdd90659a59 100644 (file)
@@ -58,10 +58,10 @@ public:
     virtual void get_protocol_ids(std::vector<uint16_t>&);
 
 
-    // used in random classes throughout Snort++
-    virtual inline bool is_ipv6(){ return true; };
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_IP6; };
 
-    
 };
 
 
@@ -484,8 +484,8 @@ void DecodeIPV6Extensions(uint8_t next, const uint8_t *pkt, const uint32_t len,
             DecoderEvent(p, DECODE_IPV6_BAD_NEXT_HEADER);
 
 //            dc.other++;
-            p->data = pkt;
-            p->dsize = (uint16_t)len;
+//            p->data = pkt;
+//            p->dsize = (uint16_t)len;
             break;
     };
 }
index ad23b4bcca1d66154c5435aeb43e2c961f5d944e..443e34e008be08569ca3d2ad4fd4149389aad240 100644 (file)
@@ -62,8 +62,11 @@ public:
 
     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<uint16_t>&);
+
+    // DELETE
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_TCP; };
 };
 
 static IpAddrSet *SynToMulticastDstIp = NULL;
index 705df92909ecf0e1bcb4c6f0ef78204052e8d845..8d1801ae111bce8bf7a913b8bf624d8ca1136a16 100644 (file)
@@ -60,6 +60,11 @@ public:
         Packet *, uint16_t &p_hdr_len, int &next_prot_id);
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
+
+    // DELETE
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_UDP; };
+
     
 };
 
@@ -234,8 +239,9 @@ bool UdpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 //    PushLayer(PROTO_UDP, p, raw_pkt, udp::header_len());
 
 
-    p->data = (uint8_t *) (raw_pkt + udp::header_len());
-    p->dsize = uhlen - udp::header_len(); // length validated above
+    // set in packet manager
+//    p->data = (uint8_t *) (raw_pkt + udp::header_len());
+//    p->dsize = uhlen - udp::header_len(); // length validated above
     p->proto_bits |= PROTO_BIT__UDP;
 
     /*  Drop packet if we ignore this port  */
index f591c2f70beda31158744df0c5750bb84ae41d44..99408e28885d99b7b20e4707f851a5807ae72efc 100644 (file)
@@ -43,8 +43,12 @@ public:
 
     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<uint16_t>&);
+
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_AH; };
     
 };
 
index 65e655978f7d1359253f9e1ef7599c44579cd0fa..130720dd6d6f45a76d895e672a9e577fb037d7ee 100644 (file)
@@ -42,9 +42,12 @@ public:
 
     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<uint16_t>&);
     
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ARP; };
 };
 
 
index dbea43c8801e8488b9d87c884018968ef28bf891..5e310f334c55b0191a3edada51f1d9e6fbf1db1f 100644 (file)
@@ -41,6 +41,9 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
 };
 
 
index 71014aa020f14b77be462844895beaad900f347c..9df6c0bcf39bda38a1079e52697ef0bcb6e9ed47 100644 (file)
@@ -43,6 +43,9 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
 };
 
 
index 486e4e7cedb24582ea351c2be49fac1c05e70e7f..87634d3ce886c6d1a17ebf0d6b4dc41ac3d75a1f 100644 (file)
@@ -43,7 +43,12 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual void get_data_link_type(std::vector<int>&){};
-    
+
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_GRE; };
+
 };
 
 static const uint16_t GRE_PROT_ID = 47;
index ded90aa18f416f13e24929162f92086b5b45c142..fb85e3357cdfa300e7df907f7dc7fbdbebaaf76a 100644 (file)
@@ -51,8 +51,12 @@ public:
 
     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<uint16_t>&);
 
-    virtual void get_protocol_ids(std::vector<uint16_t>&);    
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_GTP; };    
 };
 
 } // anonymous namespace
index 05822c0730a74f3388f60460e2fc4a11639ad9e2..281b1fbed57859f10049a39a410528a3ab6983f0 100644 (file)
@@ -46,9 +46,12 @@ public:
 
     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<uint16_t>&);
     
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_MPLS; };
 };
 
 
index d4996de930ec8d2696f2cfff22940f5c7e73845e..775446578711da80e3f564d1a809f769940dcd95 100644 (file)
@@ -45,8 +45,12 @@ public:
 
     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<uint16_t>&);
+
+
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_PPP_ENCAP; };
     
 };
 
index e24c6ff3031141340d3c31ca1047991e76d1c51a..b2a4dfea61c11478050d6eca78ba411d0298288a 100644 (file)
@@ -39,9 +39,11 @@ public:
 
     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<uint16_t>&);
     
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_PPPOE; };
 };
 
 
index b8957450884a1583e9fe9dd15cb1a4b53c4dc3ac..5555183921924f9ad37186735f96be9dd32cf3e6 100644 (file)
@@ -56,7 +56,11 @@ public:
 
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual void get_data_link_type(std::vector<int>&){};
+
     
+    // DELETE from here and below
+    #include "codecs/sf_protocols.h"
+    virtual inline PROTO_ID get_proto_id() { return PROTO_VLAN; };
 };
 
 } // anonymous namespace
index da951c5392dbac20db07e410ef1dafe65a827920..8abecb9f98e24741efbce2c696ce68bb3de6cded 100644 (file)
 #include "framework/base_api.h"
 
 
+// REMOVE WHEN POSSIBLE!!!
+#include "codecs/sf_protocols.h"
+
+
 struct Packet;
 
 // this is the current version of the api
@@ -53,12 +57,12 @@ public:
     // ONE OF THESE METHODS MUST BE IMPLEMENTED!!
     virtual void get_protocol_ids(std::vector<uint16_t>&){};
     virtual void get_data_link_type(std::vector<int>&){};
-
-    virtual inline bool is_ipv4(){ return false; };
-    virtual inline bool is_ipv6(){ return false; };
     virtual inline const char* get_name(){return name; };
 
 
+    virtual inline PROTO_ID get_proto_id() { return PROTO_MAX; };
+
+
 protected:
     Codec(const char* s) { name = s; };
 
index 4b3bc9be3b94a2f263d521d6761e83f720ba5401..8a9e7091a10f54e46d13d42137ded3e80f7df680 100644 (file)
@@ -34,7 +34,7 @@ THREAD_LOCAL PreprocStats decodePerfStats;
 //namespace
 //{
     static const uint16_t max_protocol_id = 65535;
-    static std::array<Codec *, max_protocol_id> s_protocols;
+    static std::array<Codec*, max_protocol_id> s_protocols;
     static list<const CodecApi*> s_codecs;
 
 //} // namespace
@@ -100,6 +100,7 @@ void PacketManager::decode(
 
     // 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))
     {
@@ -229,8 +230,6 @@ void PacketManager::set_grinder(void)
 //        FatalError("Codec installation checking!!");
 }
 
-    static void init_codecs();
-
 
 void PacketManager::dump_stats()
 {
index 15afd3bb503708fc746e7c934f945a1605db4e5e..4c70706dd3f03b89a4d288e61a1708d91dd0d453 100644 (file)
 #include "codecs/sf_protocols.h"
 #include "log/messages.h"
 
-void PacketClass::PushLayer(Packet *p, const Codec *cd, const uint8_t *hdr_start, uint32_t len)
+void PacketClass::PushLayer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len)
 {
     if ( p->next_layer < LAYER_MAX )
     {
-        Layer* lyr = p->layers + p->next_layer++;
-        lyr->proto = PROTO_TCP;
-        lyr->cd = cd;
-        lyr->start = (uint8_t*)hdr_start;
-        lyr->length = (uint16_t)len;
+        Layer lyr = p->layers[p->next_layer];
+        lyr.proto = cd->get_proto_id();
+        lyr.cd = cd;
+        lyr.start = (uint8_t*)hdr_start;
+        lyr.length = (uint16_t)len;
     }
     else
     {
         LogMessage("(snort_decoder) WARNING: decoder got too many layers;"
             " next proto is something.\n");
     }
-}
\ No newline at end of file
+}
+
index e3f69ec249512faeb891c9c59b4c9a2b5c366140..783e2941b98a5613dfe4f430a2656336e785b972 100644 (file)
@@ -898,8 +898,7 @@ typedef struct
 class PacketClass{
 
 public:
-    static 
-    void PushLayer(Packet *p, const Codec *cd, const uint8_t *hdr_start, uint32_t len);
+    static void PushLayer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len);
 
 
 private: