LCOV - code coverage report
Current view: top level - src - UDP_Rewriter.h (source / functions) Hit Total Coverage
Test: app.info Lines: 0 15 0.0 %
Date: 2010-12-13 Functions: 0 12 0.0 %
Branches: 0 4 0.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id:$
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #ifndef udp_rewriter_h
       6                 :            : #define udp_rewriter_h
       7                 :            : 
       8                 :            : using namespace std;
       9                 :            : 
      10                 :            : #include <queue>
      11                 :            : #include <set>
      12                 :            : 
      13                 :            : #include <pcap.h>
      14                 :            : 
      15                 :            : #include "Val.h"
      16                 :            : #include "UDP.h"
      17                 :            : #include "Anon.h"
      18                 :            : #include "Rewriter.h"
      19                 :            : #include "PacketDumper.h"
      20                 :            : 
      21                 :            : class UDP_TracePacket : public BroObj, virtual public TracePacket {
      22                 :            : public:
      23                 :            :         UDP_TracePacket(UDP_Rewriter* trace_rewriter, double t, int is_orig,
      24                 :            :                     const struct pcap_pkthdr* hdr, int MTU, int initial_size);
      25                 :            :         ~UDP_TracePacket();
      26                 :            : 
      27                 :            :         int AppendLinkHeader(const u_char* chunk, int len);
      28                 :            :         int AppendIPHeader(const u_char* chunk, int len);
      29                 :            :         int AppendUDPHeader(const u_char* chunk, int len);
      30                 :            :         int AppendData(const u_char* chunk, int len);
      31                 :            : 
      32                 :            :         void Reuse();
      33                 :            :         int IsReuse() const     { return reuse; }
      34                 :            : 
      35                 :          0 :         double TimeStamp() const        { return timestamp; }
      36                 :          0 :         int IsOrig() const      { return is_orig; }
      37                 :            : 
      38                 :            :         const struct pcap_pkthdr* Header() const        { return &pcap_hdr; }
      39                 :            : 
      40                 :            :         const u_char* Buffer() const    { return pkt; }
      41                 :            :         int Length() const      { return buffer_offset; }
      42                 :            : 
      43                 :            :         // Note that Space() does not depend on buffer_size, but depends on MTU.
      44                 :            :         int Space() const       { return mtu - buffer_offset; }
      45                 :            : 
      46                 :          0 :         void Describe(ODesc* d) const   { packet_val->Describe(d); }
      47                 :            :         RecordVal* PacketVal();
      48                 :          0 :         UDP_Rewriter* TraceRewriter() const     { return trace_rewriter;}
      49                 :            : 
      50                 :            :         // has the packet been written to?
      51                 :          0 :         int IsModified() const  { return modified; }
      52                 :          0 :         void SetModified()              { modified = 1; }
      53                 :            : 
      54                 :            :         // BuildPacket() is called before dumping the packet. It sets length
      55                 :            :         // fields and computes checksums in UDP/IP headers.
      56                 :            :         int BuildPacket(struct pcap_pkthdr*& hdr, const u_char*& arg_pkt,
      57                 :            :                         int& length, ipaddr32_t anon_src, ipaddr32_t anon_dst);
      58                 :            : 
      59                 :            : private:
      60                 :            :         int Append(const u_char* chunk, int len);
      61                 :            : 
      62                 :            :         RecordVal* packet_val;
      63                 :            :         UDP_Rewriter* trace_rewriter;
      64                 :            :         double timestamp;
      65                 :            :         int packet_seq;
      66                 :            :         int is_orig;
      67                 :            :         struct pcap_pkthdr pcap_hdr;
      68                 :            :         int mtu;
      69                 :            :         u_char* pkt;    // of maximal length MTU
      70                 :            :         int ip_offset, udp_offset, data_offset;
      71                 :            :         int buffer_size;
      72                 :            :         int buffer_offset;
      73                 :            :         int reuse;      // whether it is an artificially replicated packet
      74                 :            :         int on_hold;    // do not dump it in Flush()
      75                 :            :         int seq_gap;
      76                 :            :         int modified;
      77                 :            : };
      78                 :            : 
      79                 :            : class UDP_Rewriter: public Rewriter {
      80                 :            : public:
      81                 :            :         UDP_Rewriter(Analyzer* analyzer, int arg_MTU, PacketDumper* dumper);
      82                 :            : 
      83                 :            :         virtual ~UDP_Rewriter();
      84                 :            : 
      85                 :            :         void Done();
      86                 :            : 
      87                 :            :         // these are the virt funcs in Rewriter....
      88                 :            :         void WriteData(int is_orig, int len, const u_char* data);
      89                 :            : 
      90                 :          0 :         void WriteData(int is_orig, const char* data)
      91                 :          0 :                 { WriteData(is_orig, strlen(data), data); }
      92                 :            : 
      93                 :          0 :         void WriteData(int is_orig, int len, const char* data)
      94                 :          0 :                 { WriteData(is_orig, len, (const u_char*) data); }
      95                 :            : 
      96                 :          0 :         void WriteData(int is_orig, const BroString* str)
      97                 :          0 :                 { WriteData(is_orig, str->Len(), str->Bytes()); }
      98                 :            : 
      99                 :          0 :         Analyzer* GetAnalyzer() const   { return analyzer; }
     100                 :            : 
     101                 :            :         // Not need for udp, but declared in the virtual
     102                 :            :         // and might be useful
     103                 :            :         void Push(int);
     104                 :            :         void AbortPackets(int);
     105                 :            :         void CommitPackets(int);
     106                 :            :         unsigned int ReserveSlot();
     107                 :            :         int SeekSlot(unsigned int);
     108                 :            :         int ReturnFromSlot();
     109                 :            :         int ReleaseSlot(unsigned int);
     110                 :            : 
     111         [ #  # ]:          0 :         TracePacket* CurrentPacket() const      { return current_packet; };
     112         [ #  # ]:          0 :         TracePacket* RewritePacket() const      { return next_packet; };
     113                 :            : 
     114                 :            :         // A UDP/IP packet.
     115                 :            :         void NextPacket(int is_orig, double t,
     116                 :            :                         const struct pcap_pkthdr* pcap_hdr,
     117                 :            :                         const u_char* pcap_pkt, // link level header
     118                 :            :                         int hdr_size,           // link level header size
     119                 :            :                         const struct ip* ip, const struct udphdr* tp);
     120                 :            : 
     121                 :            :         // Do not anonymize client/server IP address.
     122                 :            :         int LeaveAddrInTheClear(int is_orig);
     123                 :            : 
     124                 :            : protected:
     125                 :            :         void DoWriteData(int is_orig, int len, const u_char* data);
     126                 :            : 
     127                 :            :         Analyzer* analyzer;
     128                 :            :         PacketDumper* dumper;
     129                 :            : 
     130                 :            :         int packets_rewritten;
     131                 :            :         int MTU;
     132                 :            :         ipaddr32_t anon_addr[2];
     133                 :            : 
     134                 :            :         UDP_TracePacket* current_packet;
     135                 :            :         UDP_TracePacket* next_packet;
     136                 :            : };
     137                 :            : 
     138                 :            : #endif

Generated by: LCOV version 1.8