]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
adding support for codec specific logging, and implemented some of those loggers
authorJosh <jrosenba@cisco.com>
Sat, 30 Aug 2014 00:00:49 +0000 (20:00 -0400)
committerJosh <jrosenba@cisco.com>
Sat, 30 Aug 2014 00:23:48 +0000 (20:23 -0400)
38 files changed:
src/codecs/ip/cd_esp.cc
src/codecs/ip/cd_frag.cc
src/codecs/ip/cd_gre.cc
src/codecs/ip/cd_ipv4.cc
src/codecs/ip/cd_ipv6.cc
src/codecs/ip/cd_tcp.cc
src/codecs/ip/cd_udp.cc
src/codecs/link/cd_mpls.cc
src/codecs/misc/cd_default.cc
src/codecs/root/cd_eth.cc
src/codecs/template.cc
src/detection/detection_options.cc
src/detection/fpdetect.cc
src/framework/codec.h
src/log/CMakeLists.txt
src/log/Makefile.am
src/log/log.cc
src/log/log.h
src/log/log_text.cc
src/log/log_text.h
src/log/messages.h
src/loggers/alert_csv.cc
src/main/snort.cc
src/managers/CMakeLists.txt
src/managers/Makefile.am
src/managers/codec_manager.cc
src/network_inspectors/port_scan/port_scan.cc
src/packet_io/active.cc
src/protocols/CMakeLists.txt
src/protocols/Makefile.am
src/protocols/gre.h
src/protocols/ip.cc
src/protocols/packet_manager.cc [moved from src/managers/packet_manager.cc with 97% similarity]
src/protocols/packet_manager.h [moved from src/managers/packet_manager.h with 95% similarity]
src/protocols/protocol_ids.h
src/stream/ip/ip_defrag.cc
src/stream/tcp/tcp_session.cc
src/utils/stats.cc

index f0f99422a7d907d610b02ed5d370581f210d206a..de06e398f768baf5ba70997b2034007594038129 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "framework/codec.h"
 #include "snort.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "codecs/codec_events.h"
 #include "protocols/protocol_ids.h"
 
index 17435e6c5fdb9a0eb70f2d9cb368fd26cc4aaa09..0747e4cc798e660d9f4fca596a65d18a1387c751 100644 (file)
@@ -33,6 +33,8 @@
 #include "detection/fpdetect.h"
 #include "codecs/ip/ip_util.h"
 #include "protocols/packet.h"
+#include "log/text_log.h"
+#include "protocols/packet_manager.h"
 
 
 namespace
@@ -50,6 +52,8 @@ public:
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
 
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/,
+                    const Packet* const);
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     
 };
@@ -101,8 +105,9 @@ bool Ipv6FragCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
 #endif
 
     // three least signifigant bits are all flags
-    p->frag_offset = ntohs(ip6frag_hdr->get_off()) >> 3;
-    if (p->frag_offset || (p->decode_flags & DECODE__MF))
+    const uint16_t frag_offset =  ntohs(ip6frag_hdr->get_off()) >> 3;
+    p->frag_offset = frag_offset;
+    if (frag_offset || (p->decode_flags & DECODE__MF))
     {
         p->decode_flags |= DECODE__FRAG;
     }
@@ -110,7 +115,7 @@ bool Ipv6FragCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
     {
         codec_events::decoder_event(p, DECODE_IPV6_BAD_FRAG_PKT);
     }
-    if (!(p->frag_offset))
+    if (!(frag_offset))
     {
         // check header ordering of fragged (next) header
         if ( ip_util::IPV6ExtensionOrder(ip6frag_hdr->ip6f_nxt) <
@@ -124,7 +129,7 @@ bool Ipv6FragCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
     lyr_len = sizeof(ip::IP6Frag);
     p->ip_frag_len = (uint16_t)(raw_len - lyr_len);
 
-    if ( (p->decode_flags & DECODE__FRAG) && ((p->frag_offset > 0) ||
+    if ( (p->decode_flags & DECODE__FRAG) && ((frag_offset > 0) ||
          (ip6frag_hdr->ip6f_nxt != IPPROTO_UDP)) )
     {
         /* For non-zero offset frags, we stop decoding after the
@@ -148,25 +153,35 @@ bool Ipv6FragCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
 
 
 void Ipv6FragCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{ v.push_back(IPPROTO_ID_FRAGMENT); }
+
+
+void Ipv6FragCodec::log(TextLog* log, const uint8_t* raw_pkt,
+                    const Packet* const)
 {
-    v.push_back(IPPROTO_ID_FRAGMENT);
-}
+    const ip::IP6Frag* fragh = reinterpret_cast<const ip::IP6Frag*>(raw_pkt);
+    const uint16_t offlg = ntohs(fragh->get_off());
+
+
+    TextLog_Print(log, "Frag6: Next:%s(%02X) Off:%u ID:%u",
+            PacketManager::get_proto_name(fragh->ip6f_nxt), fragh->ip6f_nxt,
+            (offlg >> 3), ntohl(fragh->get_id()));
 
+    if (offlg & ip::IP6F_MF_MASK)
+        TextLog_Puts(log, " MF");
 
+    TextLog_NewLine(log);
+}
 
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
 static Codec* ctor(Module*)
-{
-    return new Ipv6FragCodec();
-}
+{ return new Ipv6FragCodec(); }
 
 static void dtor(Codec *cd)
-{
-    delete cd;
-}
+{ delete cd; }
 
 static const CodecApi ipv6_frag_api =
 {
index 1fa7df200a58e6cbb943b146d66c7ed3296e724f..08cea1aa45b6bcb632e509d91c79b2754f1b11f7 100644 (file)
@@ -1,6 +1,5 @@
 /*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License Version 2 as
@@ -30,6 +29,8 @@
 #include "protocols/protocol_ids.h"
 #include "codecs/sf_protocols.h"
 #include "protocols/gre.h"
+#include "log/text_log.h"
+#include "protocols/packet_manager.h"
 
 namespace
 {
@@ -71,6 +72,8 @@ public:
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+     void log(TextLog* /*log*/, const uint8_t* /*raw_pkt*/,
+                    const Packet* const);
 
 
 };
@@ -100,9 +103,7 @@ static const uint32_t GRE_V1_ACK_LEN = 4;
 
 
 void GreCodec::get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(IPPROTO_ID_GRE);
-}
+{ v.push_back(IPPROTO_ID_GRE); }
 
 
 /*
@@ -242,30 +243,33 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
 }
 
 
+void GreCodec::log(TextLog* log, const uint8_t* raw_pkt,
+                    const Packet* const)
+{
+    const gre::GREHdr *greh = reinterpret_cast<const gre::GREHdr *>(raw_pkt);
+
+    TextLog_Print(log, "GRE  version:%u flags:0x%02X ether-type:%s(0x%04X)\n",
+            greh->get_version(), greh->flags,
+            PacketManager::get_proto_name(greh->get_proto()),
+            greh->get_proto());
+}
+
 
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{
-    return new GreModule;
-}
+{ return new GreModule; }
 
 static void mod_dtor(Module* m)
-{
-    delete m;
-}
+{ delete m; }
 
 static Codec* ctor(Module*)
-{
-    return new GreCodec();
-}
+{ return new GreCodec(); }
 
 static void dtor(Codec *cd)
-{
-    delete cd;
-}
+{ delete cd; }
 
 static const CodecApi gre_api =
 {
index ed5f05e315d729df91133d0148a7633801ea6e82..797c983349aa007d3f08789bd0927a6b95eaa7c3 100644 (file)
 #endif
 
 #include <array>
-#include "snort.h"
+#include "main/snort.h"
 #include "fpdetect.h"
 
 
 #include "protocols/tcp.h"
 #include "protocols/ipv4.h"
+#include "protocols/packet_manager.h"
 
 #include "utils/stats.h"
 #include "packet_io/active.h"
@@ -48,6 +49,8 @@
 #include "codecs/decode_module.h"
 #include "codecs/sf_protocols.h"
 #include "protocols/ip.h"
+#include "log/text_log.h"
+#include "log/log_text.h"
 
 namespace{
 
@@ -105,6 +108,8 @@ public:
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/,
+        const Packet* const);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
@@ -114,7 +119,6 @@ private:
     static uint8_t RevTTL (const EncState* enc, uint8_t ttl);
     static uint8_t FwdTTL (const EncState* enc, uint8_t ttl);
     static uint8_t GetTTL (const EncState* enc);
-    
 };
 
 /* Last updated 5/2/2014.
@@ -232,7 +236,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         codec_events::decoder_event(p, DECODE_IP_MULTIPLE_ENCAPSULATION);
 
     /* lay the IP struct over the raw data */
-    IP4Hdr* iph = reinterpret_cast<IP4Hdr*>(const_cast<uint8_t *>(raw_pkt));
+    const IP4Hdr* const iph = reinterpret_cast<const IP4Hdr*>(raw_pkt);
 
     /*
      * with datalink DLT_RAW it's impossible to differ ARP datagrams from IP.
@@ -685,6 +689,79 @@ static int OptLenValidate(const uint8_t *option_ptr,
     return 0;
 }
 
+/******************************************************************
+ *********************  L O G G E R  ******************************
+*******************************************************************/
+
+struct ip4_addr
+{
+    union
+    {
+        uint32_t addr32;
+        uint8_t addr8[4];
+    };
+};
+
+void Ipv4Codec::log(TextLog* log, const uint8_t* raw_pkt, const Packet* const p)
+{
+    const IP4Hdr* const ip4h = reinterpret_cast<const IP4Hdr*>(raw_pkt);
+
+    // FIXIT-H  -->  This does NOT obfuscate correctly
+    if (ScObfuscate())
+    {
+        TextLog_Print(log, "IPv4  xxx.xxx.xxx.xxx -> xxx.xxx.xxx.xxx");
+    }
+    else
+    {
+        ip4_addr src, dst;
+        src.addr32 = ip4h->get_src();
+        dst.addr32 = ip4h->get_dst();
+
+        TextLog_Print(log, "%d.%d.%d.%d -> %d.%d.%d.%d",
+            (int)src.addr8[0], (int)src.addr8[1],
+            (int)src.addr8[2], (int)src.addr8[3],
+            (int)dst.addr8[0], (int)dst.addr8[1],
+            (int)dst.addr8[2], (int)dst.addr8[3]);
+    }
+
+    TextLog_NewLine(log);
+
+    const uint16_t hlen = ip4h->get_hlen() << 2;
+    const uint16_t len = ntohs(ip4h->get_len());
+    const uint16_t frag_off = ntohs(ip4h->get_off());
+
+    TextLog_Print(log, "\tNext:%s(%02X) TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u",
+            PacketManager::get_proto_name(ip4h->get_proto()),
+            ip4h->get_proto(), ip4h->get_ttl(), ip4h->get_tos(),
+            ip4h->get_id(), hlen, len);
+
+
+    /* print the reserved bit if it's set */
+    if(frag_off & 0x8000)
+        TextLog_Puts(log, " RB");
+
+    /* printf more frags/don't frag bits */
+    if(frag_off & 0x4000)
+        TextLog_Puts(log, " DF");
+
+    if(frag_off & 0x2000)
+        TextLog_Puts(log, " MF");
+
+    TextLog_NewLine(log);
+
+    /* print IP options */
+    if(p->ip_option_count > 0)
+    {
+        LogIpOptions(log, p);
+    }
+
+
+    if( p->decode_flags & DECODE__FRAG)
+    {
+        TextLog_Print(log, "Frag Offset: 0x%04X   Frag Size: 0x%04X\n",
+                (frag_off & 0x1FFF), (len - hlen));
+    }
+}
 
 /******************************************************************
  ******************** E N C O D E R  ******************************
@@ -812,14 +889,10 @@ void Ipv4Codec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr)
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{
-    return new Ipv4Module;
-}
+{ return new Ipv4Module; }
 
 static void mod_dtor(Module* m)
-{
-    delete m;
-}
+{ delete m; }
 
 //-------------------------------------------------------------------------
 // ip id considerations:
@@ -854,14 +927,10 @@ static void ipv4_codec_gterm()
 
 
 static Codec *ctor(Module*)
-{
-    return new Ipv4Codec;
-}
+{ return new Ipv4Codec; }
 
 static void dtor(Codec *cd)
-{
-    delete cd;
-}
+{ delete cd; }
 
 static const CodecApi ipv4_api =
 {
index 3f6b2b2ed78782935c43e288e0dd748dcae8c464..3ce069fa49145585b35a4ff487ac67405fadf755 100644 (file)
@@ -38,6 +38,8 @@
 #include "codecs/decode_module.h"
 #include "codecs/sf_protocols.h"
 #include "protocols/protocol_ids.h"
+#include "protocols/packet_manager.h"
+#include "log/text_log.h"
 
 namespace
 {
@@ -95,6 +97,8 @@ public:
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/,
+                    const Packet* const) ;
 
 private:
 
@@ -181,7 +185,7 @@ bool Ipv6Codec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
 
     /* lay the IP struct over the raw data */
     const ip::IP6Hdr* const ip6h =
-        reinterpret_cast<ip::IP6Hdr*>(const_cast<uint8_t*>(raw_pkt));
+        reinterpret_cast<const ip::IP6Hdr*>(raw_pkt);
 
     if(raw_len < ip::IP6_HEADER_LEN)
     {
@@ -590,9 +594,63 @@ static inline int CheckTeredoPrefix(const ip::IP6Hdr* const hdr)
     return 0;
 }
 
-/*
- * Encoders
- */
+
+/******************************************************************
+ *********************  L O G G E R  ******************************
+*******************************************************************/
+
+void Ipv6Codec::log(TextLog* log, const uint8_t* raw_pkt,
+                    const Packet* const)
+{
+    const ip::IP6Hdr* const ip6h = reinterpret_cast<const ip::IP6Hdr*>(raw_pkt);
+
+
+    TextLog_NewLine(log);
+
+    //FIXIT-H  -->  This does NOT obfuscate correctly
+
+    // FIXIT-H  -->  This does NOT obfuscate correctly
+    if (ScObfuscate())
+    {
+        TextLog_Print(log, "IPv6  x:x:x:x::x:x:x:x -> x:x:x:x::x:x:x:x");
+    }
+    else
+    {
+        const ip::snort_in6_addr* const src = ip6h->get_src();
+        const ip::snort_in6_addr* const dst = ip6h->get_dst();
+
+        TextLog_Print(log, "%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
+                            "%02X%02X:%02X%02X:%02X%02X -> %02X%02X:%02X%02X:"
+                            "%02X%02X:%02X%02X:%02X%02X:%02X%02X",
+            (int)src->u6_addr8[0], (int)src->u6_addr8[1], (int)src->u6_addr8[2],
+            (int)src->u6_addr8[3], (int)src->u6_addr8[4], (int)src->u6_addr8[5],
+            (int)src->u6_addr8[6], (int)src->u6_addr8[7], (int)src->u6_addr8[8],
+            (int)src->u6_addr8[9], (int)src->u6_addr8[10], (int)src->u6_addr8[11],
+            (int)src->u6_addr8[12], (int)src->u6_addr8[13], (int)src->u6_addr8[14],
+            (int)src->u6_addr8[15], (int)dst->u6_addr8[0], (int)dst->u6_addr8[1],
+            (int)dst->u6_addr8[2], (int)dst->u6_addr8[3], (int)dst->u6_addr8[4],
+            (int)dst->u6_addr8[5], (int)dst->u6_addr8[6], (int)dst->u6_addr8[7],
+            (int)dst->u6_addr8[8], (int)dst->u6_addr8[9], (int)dst->u6_addr8[10],
+            (int)dst->u6_addr8[11], (int)dst->u6_addr8[12], (int)dst->u6_addr8[13],
+            (int)dst->u6_addr8[14], (int)dst->u6_addr8[15]);
+    }
+
+
+    TextLog_NewLine(log);
+
+
+    TextLog_Print(log, "\tNext:%s(%02X) TTL:%u TOS:0x%X DgmLen:%u",
+            PacketManager::get_proto_name(ip6h->get_next()),
+            ip6h->get_next(), ip6h->get_hop_lim(), ip6h->get_tos(),
+            ntohs(ip6h->get_len()));
+
+    TextLog_NewLine(log);
+}
+
+
+/******************************************************************
+ *************************  E N C O D E R  ************************
+ ******************************************************************/
 
 bool Ipv6Codec::encode(EncState* enc, Buffer* out, const uint8_t* raw_in)
 {
@@ -702,24 +760,16 @@ void Ipv6Codec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr)
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{
-    return new Ipv6Module;
-}
+{ return new Ipv6Module; }
 
 static void mod_dtor(Module* m)
-{
-    delete m;
-}
+{ delete m; }
 
 static Codec* ctor(Module*)
-{
-    return new Ipv6Codec();
-}
+{ return new Ipv6Codec(); }
 
 static void dtor(Codec *cd)
-{
-    delete cd;
-}
+{ delete cd; }
 
 static const CodecApi ipv6_api =
 {
index 5bbf58fbf32262ead3536d76dc23600d2bfd43c1..97eda190e35292fa734d698955cd674cc26d4bad 100644 (file)
 #include "packet_io/sfdaq.h"
 #include "parser/parse_ip.h"
 #include "sfip/sf_ipvar.h"
+#include "log/text_log.h"
+#include "log/log_text.h"
+#include "log/log.h"
+#include "protocols/packet_manager.h"
 
 
 namespace
@@ -103,6 +107,8 @@ public:
 
     virtual PROTO_ID get_proto_id() { return PROTO_TCP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/,
+                    const Packet* const) ;
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         Packet *, uint16_t &lyr_len, uint16_t &);
     virtual bool encode(EncState*, Buffer* out, const uint8_t *raw_in);
@@ -159,7 +165,7 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
     }
 
     /* lay TCP on top of the data cause there is enough of it! */
-    tcp::TCPHdr* tcph = reinterpret_cast<tcp::TCPHdr*>(const_cast<uint8_t*>(raw_pkt));
+    const tcp::TCPHdr* tcph = reinterpret_cast<const tcp::TCPHdr*>(raw_pkt);
     p->tcph = tcph;
 
     /* multiply the payload offset value by 4 */
@@ -606,9 +612,45 @@ static inline void TCPMiscTests(Packet *p)
         codec_events::decoder_event(p, DECODE_TCP_PORT_ZERO);
 }
 
+/******************************************************************
+ ************************  L O G G E R   **************************
+ ******************************************************************/
+
+
+void TcpCodec::log(TextLog* log, const uint8_t* raw_pkt,
+                    const Packet* const p)
+{
+    char tcpFlags[9];
+
+    const tcp::TCPHdr* tcph = reinterpret_cast<const tcp::TCPHdr*>(raw_pkt);
+    TextLog_Puts(log, "TCP  ");
+
+    /* print TCP flags */
+    CreateTCPFlagString(tcph, tcpFlags);
+    TextLog_Puts(log, tcpFlags); /* We don't care about the NULL */
+
+    /* print other TCP info */
+    TextLog_Print(log, " SrcPort:%u  DstPort:%u  Seq: 0x%lX  Ack: 0x%lX  "
+            "Win: 0x%X  TcpLen: %d",ntohs(tcph->th_sport),
+            ntohs(tcph->th_dport), (u_long) ntohl(tcph->th_seq),
+            (u_long) ntohl(tcph->th_ack),
+            ntohs(tcph->th_win), TCP_OFFSET(tcph) << 2);
+
+    if((tcph->th_flags & TH_URG) != 0)
+        TextLog_Print(log, "  UrgPtr: 0x%X\n", (uint16_t) ntohs(tcph->th_urp));
+
+    TextLog_NewLine(log);
+
+    /* dump the TCP options */
+    if(p->tcp_option_count > 0)
+    {
+        LogTcpOptions(log, p);
+    }
+}
+
 
 /******************************************************************
- ******************** E N C O D E R  ******************************
+ ************************* E N C O D E R  *************************
  ******************************************************************/
 
 //-------------------------------------------------------------------------
@@ -1045,14 +1087,10 @@ static inline unsigned short in_chksum_tcp6(pseudoheader6 *ph,
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{
-    return new TcpModule;
-}
+{ return new TcpModule; }
 
 static void mod_dtor(Module* m)
-{
-    delete m;
-}
+{ delete m; }
 
 /*
  * Static api functions.  there are NOT part of the TCPCodec class,
index 8ac7397d64a10e3d292f0e2cdde8e36c511c608e..65d64b30ec018591a33a9bcb4bf73e06a99ea61a 100644 (file)
@@ -39,6 +39,7 @@
 #include "protocols/ipv4.h"
 #include "protocols/protocol_ids.h"
 #include "codecs/ip/checksum.h"
+#include "log/text_log.h"
 
 #include "framework/codec.h"
 #include "packet_io/active.h"
@@ -131,6 +132,7 @@ public:
     virtual bool encode(EncState*, Buffer* out, const uint8_t *raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/, const Packet* const);
     
 };
 
@@ -357,6 +359,15 @@ static inline void PopUdp (Packet* p)
         p->dsize = p->ip_api.pay_len();
 }
 
+void UdpCodec::log(TextLog* log, const uint8_t* raw_pkt, const Packet* const)
+{
+    const udp::UDPHdr* udph = reinterpret_cast<const udp::UDPHdr*>(raw_pkt);
+
+    TextLog_Print(log, "UDP  SourcePort:%d DestPort:%d Len:%d\n",
+            ntohs(udph->uh_sport), ntohs(udph->uh_dport),
+            ntohs(udph->uh_len) - udp::UDP_HEADER_LEN);
+}
+
 /******************************************************************
  ******************** E N C O D E R  ******************************
  ******************************************************************/
index cc69a8990dbf75f1537f3da12d8cf4a420e8a621..e12fe62586263fb873a5b9d184a0c5e04cec578e 100644 (file)
@@ -1,22 +1,24 @@
-/*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public LicenseUpdateMPLSStats
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*/
+/****************************************************************************
+ *
+ * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2003-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ ****************************************************************************/
 // cd_mpls.cc author Josh Rosenbaum <jrosenba@cisco.com>
 
 
@@ -33,6 +35,7 @@
 #include "codecs/sf_protocols.h"
 #include "main/snort_config.h"
 #include "main/snort.h"
+#include "log/text_log.h"
 
 namespace
 {
@@ -115,7 +118,8 @@ public:
     virtual PROTO_ID get_proto_id() { return PROTO_MPLS; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
-        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);    
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/, const Packet* const);
 
 };
 
@@ -155,7 +159,7 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
     int iRet = 0;
 
     UpdateMPLSStats(&sfBase, raw_len, Active_PacketWasDropped());
-    tmpMplsHdr = (const uint32_t *) raw_pkt;
+    tmpMplsHdr = reinterpret_cast<const uint32_t *>(raw_pkt);
 
     while (!bos)
     {
@@ -310,29 +314,28 @@ static int checkMplsHdr(
     return iRet;
 }
 
+void MplsCodec::log(TextLog* log, const uint8_t* /*raw_pkt*/,
+        const Packet* const p)
+{
+    TextLog_Print(log,"MPLS  label:0x%05X exp:0x%X bos:0x%X ttl:0x%X\n",
+        p->mplsHdr.label, p->mplsHdr.exp, p->mplsHdr.bos, p->mplsHdr.ttl);
+}
+
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
 static Module* mod_ctor()
-{
-    return new MplsModule;
-}
+{ return new MplsModule; }
 
 static void mod_dtor(Module* m)
-{
-    delete m;
-}
+{ delete m; }
 
 static Codec* ctor(Module*)
-{
-    return new MplsCodec();
-}
+{ return new MplsCodec(); }
 
 static void dtor(Codec *cd)
-{
-    delete cd;
-}
+{ delete cd; }
 
 static const CodecApi mpls_api =
 {
index 52303b3727cc12d858c3886c5a14824de1eb807d..8956faf165c9d2561465b199e85b5e5f3e1ea43b 100644 (file)
@@ -31,7 +31,7 @@
 namespace
 {
 
-#define CD_DEFAULT_NAME "default_codec"
+#define CD_DEFAULT_NAME "unknown"
 
 class DefaultCodec : public Codec
 {
index 97dd53468193d7252962a36c91bcce9bcd158789..15ef23afd1350220650ce0849cfc7a135416b2cb 100644 (file)
@@ -29,8 +29,9 @@
 #include "protocols/packet.h"
 #include "protocols/eth.h"
 #include "codecs/codec_events.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "codecs/sf_protocols.h"
+#include "log/text_log.h"
 
 namespace
 {
@@ -60,8 +61,9 @@ public:
 
 
     virtual PROTO_ID get_proto_id() { return PROTO_ETH; };
-    virtual void get_protocol_ids(std::vector<uint16_t>&) {};
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual void get_data_link_type(std::vector<int>&);
+    virtual void log(TextLog* /*log*/, const uint8_t* /*raw_pkt*/, const Packet*const );
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
@@ -82,6 +84,11 @@ void EthCodec::get_data_link_type(std::vector<int>&v)
     v.push_back(DLT_EN10MB);
 }
 
+void EthCodec::get_protocol_ids(std::vector<uint16_t>&v)
+{
+    v.push_back(ETHERNET_802_3);
+}
+
 
 //--------------------------------------------------------------------
 // decode.c::Ethernet
@@ -143,6 +150,26 @@ bool EthCodec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
 }
 
 
+void EthCodec::log(TextLog* log, const uint8_t* raw_pkt, const Packet* const)
+{
+    const eth::EtherHdr *eh = reinterpret_cast<const eth::EtherHdr *>(raw_pkt);
+
+    /* src addr */
+    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X -> ", eh->ether_src[0],
+        eh->ether_src[1], eh->ether_src[2], eh->ether_src[3],
+        eh->ether_src[4], eh->ether_src[5]);
+
+    /* dest addr */
+    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X ", eh->ether_dst[0],
+        eh->ether_dst[1], eh->ether_dst[2], eh->ether_dst[3],
+        eh->ether_dst[4], eh->ether_dst[5]);
+
+    /* protocol and pkt size */
+    TextLog_Print(log, "type:0x%X", ntohs(eh->ether_type));
+
+    // FIXIT-L - J Log length in PacketManager
+}
+
 //-------------------------------------------------------------------------
 // ethernet
 //-------------------------------------------------------------------------
index 746839c759c86d4381801cb647d3dfd6920c9ca7..3ea23d08cc197e9cc9d1c2ffd6f77364195e4c71 100644 (file)
@@ -51,6 +51,7 @@ public:
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t &raw_len,
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
 
+    virtual void log(TextLog*, const uint8_t* /*raw_pkt*/,const Packet* const);
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual void get_data_link_type(std::vector<int>&);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
index 414b102c62683fe666c6c9562ec2ba04c22e73f3..eae738039b03620fc902d379873c620c1678578a 100644 (file)
@@ -57,7 +57,7 @@
 #include "framework/ips_option.h"
 #include "framework/cursor.h"
 #include "managers/ips_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "detection/detection_defines.h"
 
 typedef struct _detection_option_key
index d50e4e6c0f37fa7f7fa2634b015778bcc42906b2..da3a4c82d59de24dcaa74170cbdfd63f58706022 100644 (file)
@@ -71,7 +71,7 @@
 #include "detection_util.h"
 #include "detection_options.h"
 #include "actions/actions.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "managers/action_manager.h"
 
 /*
index ee8cba9b70c501095a4a748c85d4560d6afe3abb..9de1d8f72a4fffb736ac0f10ecb24c63f6c61997 100644 (file)
@@ -27,7 +27,7 @@
 #include "framework/base_api.h"
 #include "codecs/sf_protocols.h"
 
-
+struct TextLog;
 struct Packet;
 struct Layer;
 
@@ -117,7 +117,9 @@ public:
      * ETHERNET_MTU == 1500
      * IP_MAXPACKET ==  65535
      */
-    static constexpr uint32_t PKT_MAX = 14 + 4 + 1500 + 65535;
+    static const uint32_t PKT_MAX = 14 + 4 + 1500 + 65535;
+
+    /*  Codec Initialization */
 
     // Get the codec's name
     inline const char* get_name(){return name; };
@@ -127,20 +129,35 @@ public:
     virtual void get_data_link_type(std::vector<int>&) {};
     // Register the code's protocol ID's and Ethertypes
     virtual void get_protocol_ids(std::vector<uint16_t>&) {};
-    // decode function
+
+    /* Maom decodomg fimctopm */
     virtual bool decode(const uint8_t* raw_packet, const uint32_t& raw_len,
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) = 0;
-
-    // 
-    // Encode the current packet. Encoding starts with the innermost
-    // layer and working outwards.  All encoders MUST call the update
-    // bound function before writing to output buffer.
-    // PARAMS:
-    //        EncStats * = The current EncState struct
-    //        Buffer *out = the buffer struct. When called, out->base pointers
-    //              to the already encoded packet! to create more memory, call
-    //              update_buffer function!
-    //        uint8_t* raw_in =  A pointer to the raw input which was decoded
+        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)=0;
+
+    /*
+     *  Log this layer's information
+     *  PARAMS:
+     *          TextLog* = the logger. Defined in "text_log.h"
+     *          const uint8_t *raw_pkt = the same data seen during decode
+     *          Packet *p = pointer to the packet struct.
+     */
+    virtual void log(TextLog* /*log*/, const uint8_t* /*raw_pkt*/,
+                    const Packet* const) {}
+
+
+    /*
+     * Encoding -- active response!!
+     *
+     * Encode the current packet. Encoding starts with the innermost
+     * layer and working outwards.  All encoders MUST call the update
+     * bound function before writing to output buffer.
+     * PARAMS:
+     *        EncStats * = The current EncState struct
+     *        Buffer *out = the buffer struct. When called, out->base pointers
+     *              to the already encoded packet! to create more memory, call
+     *              update_buffer function!
+     *        uint8_t* raw_in =  A pointer to the raw input which was decoded
+     */
     virtual bool encode(EncState*, Buffer* /*out*/, const uint8_t* /*raw_in*/)
     { return true; };
     // update function
index 0123be83eb2830ac19b744ce2dcf13ee9c384dd8..9ec9d5509fb70a9afb43594415e2274fd7171ebf 100644 (file)
@@ -2,19 +2,18 @@
 set (LOG_INCLUDES
     messages.h
     obfuscation.h
+    text_log.h
 )
 
 add_library ( log STATIC
     ${LOG_INCLUDES}
-    log.cc 
-    log.h 
-    log_text.cc 
-    log_text.h 
+    log.cc
+    log.h
+    log_text.cc
+    log_text.h
     messages.cc
-    obfuscation.cc 
-    obfuscation.h 
-    text_log.cc 
-    text_log.h
+    obfuscation.cc
+    text_log.cc
 )
 
 set_default_visibility_compile_flag( log )
index a53080127166fe4643c4ce8c795e40b280c429c3..6a1565780a64c7f8d96f1ca95dbb0597e9b6b0e0 100644 (file)
@@ -6,7 +6,8 @@ x_includedir = $(pkgincludedir)/log
 
 x_include_HEADERS = \
 messages.h \
-obfuscation.h
+obfuscation.h \
+text_log.h
 
 liblog_a_SOURCES = \
 log.cc \
@@ -15,8 +16,7 @@ log_text.cc \
 log_text.h \
 messages.cc \
 obfuscation.cc \
-text_log.cc \
-text_log.h
+text_log.cc
 
 liblog_a_CXXFLAGS = $(AM_CXXFLAGS) -fvisibility=default
 
index 969cb4011c561c2ba556968b0917d068a6fa481a..196c5a320470c72a86e191713e67db02dd498f1e 100644 (file)
@@ -45,17 +45,17 @@ using namespace std;
 /* Input is packet and an nine-byte (including NULL) character array.  Results
  * are put into the character array.
  */
-void CreateTCPFlagString(Packet * p, char *flagBuffer)
+void CreateTCPFlagString(const tcp::TCPHdr* const tcph, char *flagBuffer)
 {
     /* parse TCP flags */
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_RES1) ? '1' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_RES2) ? '2' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_URG)  ? 'U' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_ACK)  ? 'A' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_PUSH) ? 'P' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_RST)  ? 'R' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_SYN)  ? 'S' : '*');
-    *flagBuffer++ = (char) ((p->tcph->th_flags & TH_FIN)  ? 'F' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_RES1) ? '1' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_RES2) ? '2' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_URG)  ? 'U' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_ACK)  ? 'A' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_PUSH) ? 'P' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_RST)  ? 'R' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_SYN)  ? 'S' : '*');
+    *flagBuffer++ = (char) ((tcph->th_flags & TH_FIN)  ? 'F' : '*');
     *flagBuffer = '\0';
 
 }
index bb53e3f8ec2df1e3b8376544d76dbdc1dbf6a475..7476acf6537487b945922e8f201dab52e40cdea0 100644 (file)
 #define LOG_H
 
 #include "protocols/packet.h"
+#include "main/snort_types.h"
 
-void CreateTCPFlagString(Packet *, char *);
+namespace tcp
+{
+struct TCPHdr;
+} // namespace tcp
+
+
+SO_PUBLIC void CreateTCPFlagString(const tcp::TCPHdr* const, char *);
 
 FILE *OpenAlertFile(const char *);
 int RollAlertFile(const char *);
index 6a86c86649fab09ebc52c97ba2d242135e8be1ed..981a3d835441a0db7c2445a28efdcb34a5b70899 100644 (file)
@@ -441,21 +441,18 @@ void Log2ndHeader(TextLog* log, Packet* p)
  * IP stuff cloned from log.c
  *-------------------------------------------------------------------
  */
-static void LogIpOptions(TextLog*  log, Packet * p)
+
+void LogIpOptions(TextLog*  log, const Packet* const p)
 {
-    int i;
-    int j;
+    uint8_t i, j;
     u_long init_offset;
     u_long print_offset;
+    const uint8_t option_count = p->ip_option_count;
 
     init_offset = TextLog_Tell(log);
+    TextLog_Print(log, "IP Options (%d) => ", option_count);
 
-    if(!p->ip_option_count || p->ip_option_count > 40)
-        return;
-
-    TextLog_Print(log, "IP Options (%d) => ", p->ip_option_count);
-
-    for(i = 0; i < (int) p->ip_option_count; i++)
+    for(i = 0; i < option_count; i++)
     {
         print_offset = TextLog_Tell(log);
 
@@ -511,17 +508,35 @@ static void LogIpOptions(TextLog*  log, Packet * p)
             default:
                 TextLog_Print(log, "Opt %d: ", p->ip_options[i].code);
 
-                if(p->ip_options[i].len)
+                const ip::IpOptions* const ip_opt = &(p->ip_options[i]);
+                const uint8_t opt_len = ip_opt->len;
+
+                if(opt_len)
                 {
-                    for(j = 0; j < p->ip_options[i].len; j++)
+                    if (ip_opt->data)
                     {
-                        if (p->ip_options[i].data)
-                            TextLog_Print(log, "%02X", p->ip_options[i].data[j]);
-                        else
-                            TextLog_Print(log, "%02X", 0);
-
-                        if((j % 2) == 0)
-                            TextLog_Putc(log, ' ');
+                        for(j = 0; (j + 1) < opt_len; j += 2)
+                        {
+                            TextLog_Print(log, "%02X%02X ",ip_opt->data[j],
+                                                           ip_opt->data[j+1]);
+                        }
+
+                        // since we're skipping by two, if (j+1) == opt_len,
+                        // we will not have printed j
+                        if (j < opt_len)
+                            TextLog_Print(log, "%02X",ip_opt->data[j]);
+                    }
+                    else
+                    {
+                        for(j = 0; (j + 1) < opt_len; j += 2)
+                        {
+                            TextLog_Print(log, "%02X%02X ", 0, 0);
+                        }
+
+                        // since we're skipping by two, if (j+1) == opt_len,
+                        // we will not have printed j
+                        if (j < opt_len)
+                            TextLog_Print(log, "%02X",0);
                     }
                 }
                 break;
@@ -686,24 +701,22 @@ static void LogOuterIPHeader(TextLog *log, Packet *p)
  * TCP stuff cloned from log.c
  *-------------------------------------------------------------------
  */
-static void LogTcpOptions(TextLog*  log, Packet * p)
-{
-    int i;
-    int j;
-    uint8_t tmp[5];
-#if 0
-    u_long init_offset;
-    u_long print_offset;
+inline uint16_t extract_16_bits(const uint8_t* const buf)
+{ return ntohs(* ((uint16_t*)(buf)) ); }
 
-    init_offset = TextLog_Tell(log);
-#endif
+inline uint32_t extract_32_bits(const uint8_t* const buf)
+{ return ntohl(* ((uint32_t*)(buf)) ); }
 
-    TextLog_Print(log, "TCP Options (%d) => ", p->tcp_option_count);
+void LogTcpOptions(TextLog*  log, const Packet* const p)
+{
+    uint8_t i;
+    int j;
+    const uint8_t option_count = p->tcp_option_count;
+    const Options* const opts = p->tcp_options;
 
-    if(p->tcp_option_count > 40 || !p->tcp_option_count)
-        return;
+    TextLog_Print(log, "TCP Options (%d) => ", option_count);
 
-    for(i = 0; i < (int) p->tcp_option_count; i++)
+    for(i = 0; i < option_count; i++)
     {
 #if 0
         print_offset = TextLog_Tell(log);
@@ -714,16 +727,21 @@ static void LogTcpOptions(TextLog*  log, Packet * p)
             init_offset = TextLog_Tell(log);
         }
 #endif
-        switch(p->tcp_options[i].code)
+        switch(opts[i].code)
         {
             case TCPOPT_MAXSEG:
-                memset((char*)tmp, 0, sizeof(tmp));
+            {
+                uint16_t val;
                 TextLog_Puts(log, "MSS: ");
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 2);
-                TextLog_Print(log, "%u ", EXTRACT_16BITS(tmp));
-                break;
 
+                if (opts[i].data)
+                    val = extract_16_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "%u ", val);
+                break;
+            }
             case TCPOPT_EOL:
                 TextLog_Puts(log, "EOL ");
                 break;
@@ -733,87 +751,150 @@ static void LogTcpOptions(TextLog*  log, Packet * p)
                 break;
 
             case TCPOPT_WSCALE:
-                if (p->tcp_options[i].data)
-                    TextLog_Print(log, "WS: %u ", p->tcp_options[i].data[0]);
+            {
+                uint8_t val;
+
+                if (opts[i].data)
+                    val = opts[i].data[0];
                 else
-                    TextLog_Print(log, "WS: %u ", 0);
+                    val = 0;
+
+                TextLog_Print(log, "WS: %u ", val);
                 break;
+            }
             case TCPOPT_SACK:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data && (p->tcp_options[i].len >= 2))
-                    memcpy(tmp, p->tcp_options[i].data, 2);
-                TextLog_Print(log, "Sack: %u@", EXTRACT_16BITS(tmp));
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data && (p->tcp_options[i].len >= 4))
-                    memcpy(tmp, (p->tcp_options[i].data) + 2, 2);
-                TextLog_Print(log, "%u ", EXTRACT_16BITS(tmp));
-                break;
+            {
+                uint16_t val1, val2;
+
+                if (opts[i].data && (opts[i].len >= 4))
+                {
+                    val1 = extract_16_bits(opts[i].data);
+                    val2 = extract_16_bits(opts[i].data + 2);
+                }
+                else if (opts[i].data && (opts[i].len >= 2))
+                {
+                    val1 = extract_16_bits(opts[i].data);
+                    val2 = 0;
+                }
+                else
+                {
+                    val1 = 0;
+                    val2 = 0;
+                }
 
+                TextLog_Print(log, "Sack: %u@%u", val1, val2);
+                break;
+            }
             case TCPOPT_SACKOK:
                 TextLog_Puts(log, "SackOK ");
                 break;
 
             case TCPOPT_ECHO:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "Echo: %u ", EXTRACT_32BITS(tmp));
-                break;
+            {
+                uint32_t val;
 
-            case TCPOPT_ECHOREPLY:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "Echo Rep: %u ", EXTRACT_32BITS(tmp));
+                if (opts[i].data)
+                    val = extract_32_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "Echo: %u ", val);
                 break;
+            }
+            case TCPOPT_ECHOREPLY:
+            {
+                uint32_t val;
 
-            case TCPOPT_TIMESTAMP:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "TS: %u ", EXTRACT_32BITS(tmp));
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, (p->tcp_options[i].data) + 4, 4);
-                TextLog_Print(log, "%u ", EXTRACT_32BITS(tmp));
+                if (opts[i].data)
+                    val = extract_32_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "Echo Rep: %u ", val);
                 break;
+            }
+            case TCPOPT_TIMESTAMP:
+            {
+                uint32_t val1, val2;
 
-            case TCPOPT_CC:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "CC %u ", EXTRACT_32BITS(tmp));
+                if (opts[i].data)
+                {
+                    val1 = extract_32_bits(opts[i].data);
+                    val2 = extract_32_bits(opts[i].data + 4);
+                }
+                else
+                {
+                    val1 = 0;
+                    val2 = 0;
+                }
+                TextLog_Print(log, "TS: %u %u ", val1, val2);
                 break;
+            }
+            case TCPOPT_CC:
+            {
+                uint32_t val;
 
-            case TCPOPT_CC_NEW:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "CCNEW: %u ", EXTRACT_32BITS(tmp));
+                if (opts[i].data)
+                    val = extract_32_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "CC %u ", val);
                 break;
+            }
+            case TCPOPT_CC_NEW:
+            {
+                uint32_t val;
 
-            case TCPOPT_CC_ECHO:
-                memset((char*)tmp, 0, sizeof(tmp));
-                if (p->tcp_options[i].data)
-                    memcpy(tmp, p->tcp_options[i].data, 4);
-                TextLog_Print(log, "CCECHO: %u ", EXTRACT_32BITS(tmp));
+                if (opts[i].data)
+                    val = extract_32_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "CCNEW: %u ", val);
                 break;
+            }
+            case TCPOPT_CC_ECHO:
+            {
+                uint32_t val;
 
+                if (opts[i].data)
+                    val = extract_32_bits(opts[i].data);
+                else
+                    val = 0;
+
+                TextLog_Print(log, "CCECHO: %u ", val);
+                break;
+            }
             default:
-                if(p->tcp_options[i].len)
+            {
+                const uint8_t opts_len = opts[i].len;
+
+                if(opts_len)
                 {
-                    TextLog_Print(log, "Opt %d (%d): ", p->tcp_options[i].code,
-                            (int) p->tcp_options[i].len);
+                    TextLog_Print(log, "Opt %d (%d): ", opts[i].code,
+                            (int) opts_len);
 
-                    for(j = 0; j < p->tcp_options[i].len; j++)
+                    if (opts[i].data)
                     {
-                        if (p->tcp_options[i].data)
-                            TextLog_Print(log, "%02X", p->tcp_options[i].data[j]);
-                        else
-                            TextLog_Print(log, "%02X", 0);
+                        for(j = 0; (j +1) < opts_len; j += 2)
+                        {
+                            TextLog_Print(log, "%02X%02X ",  opts[i].data[j],
+                                                             opts[i].data[j+1]);
+                        }
+
+                        if (j < opts_len)
+                            TextLog_Print(log, "%02x", opts[i].data[j]);
+                    }
+                    else
+                    {
+                        for(j = 0; (j +1) < opts_len; j += 2)
+                        {
+                            TextLog_Print(log, "%02X%02X ", 0, 0);
+                        }
 
-                        if ((j + 1) % 2 == 0)
-                            TextLog_Putc(log, ' ');
+                        if (j < opts_len)
+                            TextLog_Print(log, "%02x", opts[i].data[j]);
                     }
 
                     TextLog_Putc(log, ' ');
@@ -823,12 +904,13 @@ static void LogTcpOptions(TextLog*  log, Packet * p)
                     TextLog_Print(log, "Opt %d ", p->tcp_options[i].code);
                 }
                 break;
+            }
         }
     }
-
     TextLog_NewLine(log);
 }
 
+
 /*--------------------------------------------------------------------
  * Function: LogTCPHeader(TextLog* )
  *
@@ -849,7 +931,7 @@ void LogTCPHeader(TextLog*  log, Packet * p)
         return;
     }
     /* print TCP flags */
-    CreateTCPFlagString(p, tcpFlags);
+    CreateTCPFlagString(p->tcph, tcpFlags);
     TextLog_Puts(log, tcpFlags); /* We don't care about the NULL */
 
     /* print other TCP info */
index 9b2c317fc5e5dca702def554e5ead5943e379f7c..844cf96db1ebcac500d46065fd991518669149cd 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <stdint.h>
 #include "log/text_log.h"
+#include "main/snort_types.h"
 
 struct Packet;
 struct Event;
@@ -53,8 +54,10 @@ void LogTimeStamp(TextLog*, Packet*);
 void LogTrHeader(TextLog*, Packet*);
 void Log2ndHeader(TextLog*, Packet*);
 void LogIpAddrs(TextLog*, Packet*);
+SO_PUBLIC void LogIpOptions(TextLog*, const Packet* const);
 void LogIPHeader(TextLog*, Packet*);
 void LogTCPHeader(TextLog*, Packet*);
+SO_PUBLIC void LogTcpOptions(TextLog*,  const Packet* const);
 void LogUDPHeader(TextLog*, Packet*);
 void LogICMPHeader(TextLog*, Packet*);
 void LogArpHeader(TextLog*, Packet*);
index ef10558e8633a220d9f6b891a3e35147ddbe86e1..34368ce22b47cde01a6e473e50c5f6571cb776ac 100644 (file)
@@ -51,8 +51,8 @@ void ErrorMessageThrottled(ThrottleInfo*,const char*, ...) __attribute__((format
 // FIXIT-M do not call FatalError() during runtime
 NORETURN void FatalError(const char*, ...) __attribute__((format (printf, 1, 2)));
 
-void PrintPacketData(const uint8_t*, const uint32_t);
-char* ObfuscateIpToText(const sfip_t*);
+SO_PUBLIC void PrintPacketData(const uint8_t*, const uint32_t);
+SO_PUBLIC char* ObfuscateIpToText(const sfip_t*);
 
 class Dumper
 {
index 46a0871fee793e7ad4cab94f69419d30c745f76a..74b2fa3b9e593664c8c64a60c4b5cbaa73776c36 100644 (file)
@@ -383,7 +383,7 @@ void CsvLogger::alert(Packet *p, const char *msg, Event *event)
         {
             if (p->tcph != NULL)
             {
-                CreateTCPFlagString(p, tcpFlags);
+                CreateTCPFlagString(p->tcph, tcpFlags);
                 TextLog_Print(csv_log, "%s", tcpFlags);
             }
         }
index 6b4a9d94b92c8c7cbf14391a2e1acf9972d95ce5..886eaff0134fb4528d2c6472f1996b72b032e132 100644 (file)
@@ -88,7 +88,7 @@ using namespace std;
 #include "managers/inspector_manager.h"
 #include "managers/ips_manager.h"
 #include "managers/mpse_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "managers/codec_manager.h"
 #include "managers/action_manager.h"
 #include "detection/sfrim.h"
index 0951d37336984d506881c3b2c62281068f518c27..1eb0d5ec06e170f5352ea8264b0ba6dd49788943 100644 (file)
@@ -23,8 +23,6 @@ add_library( managers
     module_manager.h
     mpse_manager.cc
     mpse_manager.h
-    packet_manager.cc
-    packet_manager.h
     plugin_manager.cc
     plugin_manager.h
     script_manager.cc
index 10a817eabb2f1c8a24985fd1a78fcab8c4b9b9af..af898d1b20926d83b4f084cfd512fbf56cc8061f 100644 (file)
@@ -17,7 +17,6 @@ inspector_manager.cc inspector_manager.h \
 ips_manager.cc ips_manager.h \
 module_manager.cc module_manager.h \
 mpse_manager.cc mpse_manager.h \
-packet_manager.cc packet_manager.h \
 plugin_manager.cc plugin_manager.h \
 script_manager.cc script_manager.h \
 so_manager.cc so_manager.h
index 223400d43e8829baccd19e56e139d4089bcc20e1..fdc224314d72befbed7191e6e61baf639ce906c1 100644 (file)
@@ -25,7 +25,7 @@
 #include <algorithm>
 #include "framework/codec.h"
 #include "managers/codec_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "log/messages.h"
 #include "parser/parser.h"
 #include "packet_io/sfdaq.h"
@@ -92,7 +92,7 @@ CodecManager::CodecApiWrapper& CodecManager::get_api_wrapper(const CodecApi* cd_
     }
 
 
-    ParseAbort("Attempting to instantiate Codec '%s',"
+    ParseAbort("Attempting to instantiate Codec '%s', "
                 "but codec has not been added!!", cd_api->base.name);
 }
 
@@ -118,7 +118,10 @@ void CodecManager::release_plugins()
     for ( CodecApiWrapper& wrap : s_codecs )
     {
         if(wrap.api->pterm)
+        {
             wrap.api->pterm();
+            wrap.init = false; // Future proofing this functin.
+        }
 
         uint8_t index = get_codec(wrap.api->base.name);
         if( index != 0)
@@ -129,21 +132,17 @@ void CodecManager::release_plugins()
     }
 
     // The default codec is NOT part of the plugin list
-    // Free this memory seperately
-    CodecApiWrapper& wrap = get_api_wrapper(default_codec);
+    if(default_codec->pterm)
+        default_codec->pterm();
 
-    if(wrap.api->pterm)
-        wrap.api->pterm();
-
-    uint8_t index = get_codec(wrap.api->base.name);
-    if( index != 0)
+    if (s_protocols[0])
     {
-        wrap.api->dtor(s_protocols[index]);
-        s_protocols[index] = nullptr;
+        default_codec->dtor(s_protocols[0]);
+        s_protocols[0] = nullptr;
     }
 
+
     s_codecs.clear();
-    s_protocols[0] = nullptr;
     s_proto_map.fill(0);
 }
 
@@ -191,8 +190,10 @@ void CodecManager::instantiate(const CodecApi* cd_api , Module* m, SnortConfig*
 void CodecManager::instantiate()
 {
     // hard code the default codec into the zero index
-    add_plugin(default_codec);
-    instantiate(default_codec, nullptr, nullptr);
+    CodecApiWrapper tmp_wrap;
+    tmp_wrap.api = default_codec;
+    tmp_wrap.init = false;
+    instantiate(tmp_wrap, nullptr, nullptr);
     s_protocols[0] = s_protocols[get_codec(default_codec->base.name)];
 
     // and instantiate every codec which does not have a module
index 0b7a78fa043773bdddc1f054f5f92029285f91a7..4f52ee2c49e2e32424fbe99a7e35283a74bb304c 100644 (file)
@@ -57,7 +57,7 @@
 #include "main/analyzer.h"
 #include "protocols/packet.h"
 #include "managers/data_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "event.h"
 #include "event_wrapper.h"
 #include "util.h"
index 4367a0d5704e56abe1feda90486698ba13923bb5..58829df83c51868b979be50d6909ad30034b5416 100644 (file)
@@ -39,7 +39,7 @@
 #include "snort.h"
 
 #include "managers/action_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "packet_io/sfdaq.h"
 #include "protocols/tcp.h"
 
index 5fe4962407275f7cee45623d5d7c0ae21ba89025..f01b188b0aa00836d091848140f238bff27366ab 100644 (file)
@@ -13,6 +13,7 @@ set (PROTOCOL_HEADERS
     linux_sll.h
     mpls.h
     packet.h
+    packet_manager.h
     protocol_ids.h
     tcp.h
     teredo.h
@@ -26,6 +27,7 @@ add_library (protocols STATIC
     ${PROTOCOL_HEADERS}
     layer.cc
     ip.cc
+    packet_manager.cc
 )
 
 install (FILES ${PROTOCOL_HEADERS}
index ce170a05fd5df56f8ca629077e25bbe99da00021..5cb15db0be171e7dcae6bfd898469af48b04aa5b 100644 (file)
@@ -17,6 +17,7 @@ gre.h \
 layer.h \
 mpls.h \
 packet.h \
+packet_manager.h \
 protocol_ids.h \
 tcp.h \
 teredo.h \
@@ -27,6 +28,7 @@ wlan.h
 
 libprotocols_a_SOURCES = \
 layer.cc \
+packet_manager.cc \
 ip.cc
 
 
index ed7e201a210c88974ff850bfd186f65ec72d03f3..572dce1a14e061e9232a9877d6206657937a1024 100644 (file)
@@ -1,6 +1,5 @@
 /*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License Version 2 as
index a8c3d1727d5234804ce2cfd95e4e9b824d024ca0..eb06e61bc57493cf341738f4d7778d1a850b0cee 100644 (file)
@@ -150,7 +150,7 @@ uint32_t IpApi::id(const Packet* const p) const
 uint16_t IpApi::off(const Packet* const p) const
 {
     if (ip4h)
-        return ip4h->get_id();
+        return (uint32_t)ip4h->get_id();
 
     // ensure we have an ipv6 frag
     if (p->ip6_extension_count == 0 || p->ip_frag_start == 0 || !ip6h)
similarity index 97%
rename from src/managers/packet_manager.cc
rename to src/protocols/packet_manager.cc
index 58384739716f2af6eadc6a42a1e7efff4fddfaaf..4657710b3b26bebfaa291c036c448484337ba8ab 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "framework/codec.h"
 #include "managers/codec_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "main/snort.h"
 #include "main/thread.h"
 #include "log/messages.h"
@@ -509,3 +509,9 @@ void PacketManager::accumulate()
     stats_mutex.unlock();
 }
 
+
+const char* PacketManager::get_proto_name(uint16_t protocol)
+{ return CodecManager::s_protocols[CodecManager::s_proto_map[protocol]]->get_name(); }
+
+const char* PacketManager::get_proto_name(uint8_t protocol)
+{ return CodecManager::s_protocols[CodecManager::s_proto_map[protocol]]->get_name(); }
similarity index 95%
rename from src/managers/packet_manager.h
rename to src/protocols/packet_manager.h
index d531a51635e97cae65608fb5ac6c2acf289abbfc..f70d44427138c878f6c259a8682c2a18de132a87 100644 (file)
@@ -97,6 +97,10 @@ public:
 
     // print codec information.  MUST be called after thread_term.
     static void dump_stats();
+    // Get the name of the given protocol
+    static const char* get_proto_name(uint16_t protocol);
+    // Get the name of the given protocol
+    static const char* get_proto_name(uint8_t protocol);
 
 private:
     //  STATISTICS!!
index 5ffa025b9dcba65c2b5662fc801564de153962e9..629b0849072851fb559f174bb7c61e5dfdde990c 100644 (file)
@@ -71,6 +71,7 @@ constexpr uint16_t PROTOCOL_TEREDO = 0x0101;
 constexpr uint16_t PROTOCOL_GTP = 0x0102;
 constexpr uint16_t IP_EMBEDDED_IN_ICMP4 = 0x0103;
 constexpr uint16_t IP_EMBEDDED_IN_ICMP6 = 0x0104;
+constexpr uint16_t ETHERNET_802_3 = 0x0105;  // CAPWAP sends data back to eth layer
 
 
 
index ad758c851a2dbcd0bd2cd0c3716e180cc7f4acfb..2a96a22879cc6d8af607243c283a9bb64cb893ad 100644 (file)
@@ -86,7 +86,7 @@
 #include "log_text.h"
 #include "detect.h"
 #include "protocols/packet.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "event.h"
 #include "util.h"
 #include "snort_debug.h"
index 845d6f4501d9176d68bc5519a0c2175a21ef1227..ef436a1891871e05e65f0d52d80dea7953d010fd 100644 (file)
@@ -68,7 +68,7 @@
 #include "snort.h"
 #include "time/packet_time.h"
 #include "protocols/packet.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "log_text.h"
 #include "packet_io/active.h"
 #include "normalize/normalize.h"
@@ -6682,7 +6682,7 @@ int TcpSession::process(Packet *p)
 
     STREAM5_DEBUG_WRAP(
         char flagbuf[9];
-        CreateTCPFlagString(p, flagbuf);
+        CreateTCPFlagString(p->tcph, flagbuf);
         DebugMessage((DEBUG_STREAM|DEBUG_STREAM_STATE),
             "Got TCP Packet 0x%X:%d ->  0x%X:%d %s\nseq: 0x%X   ack:0x%X  dsize: %u\n",
             p->ip_api.get_src(), p->sp, p->ip_api.get_dst(), p->dp, flagbuf,
index a9bd95cdaaea6976ace4bb23c45bfa8c63eaa680..7c7cbda4907f33533393d3d38a638f0fea9a1cae 100644 (file)
@@ -33,7 +33,7 @@
 #include "packet_io/trough.h"
 #include "target_based/sftarget_reader.h"
 #include "managers/module_manager.h"
-#include "managers/packet_manager.h"
+#include "protocols/packet_manager.h"
 #include "managers/codec_manager.h"
 #include "detection/fpcreate.h"
 #include "filters/sfthreshold.h"