LCOV - code coverage report
Current view: top level - src - TCP_Reassembler.h (source / functions) Hit Total Coverage
Test: app.info Lines: 10 15 66.7 %
Date: 2010-12-13 Functions: 7 12 58.3 %
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: TCP_Reassembler.h,v 1.1.2.8 2006/05/31 01:52:02 sommer Exp $
       2                 :            : 
       3                 :            : #ifndef TCP_REASSEMBLER_H
       4                 :            : #define TCP_REASSEMBLER_H
       5                 :            : 
       6                 :            : #include "Reassem.h"
       7                 :            : #include "TCP_Endpoint.h"
       8                 :            : 
       9                 :            : class BroFile;
      10                 :            : class Connection;
      11                 :            : class TCP_Analyzer;
      12                 :            : class Analyzer;
      13                 :            : 
      14                 :            : const int STOP_ON_GAP = 1;
      15                 :            : const int PUNT_ON_PARTIAL = 1;
      16                 :            : 
      17                 :            : class TCP_Reassembler : public Reassembler {
      18                 :            : public:
      19                 :            :         enum Type {
      20                 :            :                 Direct,         // deliver to destination analyzer itself
      21                 :            :                 Forward,        // forward to destination analyzer's children
      22                 :            :         };
      23                 :            : 
      24                 :            :         TCP_Reassembler(Analyzer* arg_dst_analyzer,
      25                 :            :                         TCP_Analyzer* arg_tcp_analyzer, Type arg_type,
      26                 :            :                         bool arg_is_orig, TCP_Endpoint* arg_endp);
      27                 :            : 
      28                 :            :         virtual ~TCP_Reassembler();
      29                 :            : 
      30                 :            :         void Done();
      31                 :            : 
      32                 :       1876 :         void SetDstAnalyzer(Analyzer* analyzer) { dst_analyzer = analyzer; }
      33                 :          0 :         void SetType(Type arg_type)     { type = arg_type; }
      34                 :            : 
      35                 :          0 :         TCP_Analyzer* GetTCPAnalyzer()  { return tcp_analyzer; }
      36                 :            : 
      37                 :            :         // Returns the volume of data buffered in the reassembler.
      38                 :            :         // First parameter returns data that is above a hole, and thus is
      39                 :            :         // waiting on the hole being filled.  Second parameter returns
      40                 :            :         // data that has been processed but is awaiting an ACK to free
      41                 :            :         // it up.
      42                 :            :         //
      43                 :            :         // If we're not processing contents, then naturally each of
      44                 :            :         // these is empty.
      45                 :            :         void SizeBufferedData(int& waiting_on_hole, int& waiting_on_ack) const;
      46                 :            : 
      47                 :            :         // How much data is pending delivery since it's not yet reassembled.
      48                 :            :         // Includes the data due to holes (so this value is a bit different
      49                 :            :         // from waiting_on_hole above; and is computed in a different fashion).
      50                 :      10446 :         int NumUndeliveredBytes() const
      51                 :            :                 {
      52         [ +  + ]:      10446 :                 if ( last_block )
      53                 :       9950 :                         return last_block->upper - last_reassem_seq;
      54                 :            :                 else
      55                 :      10446 :                         return 0;
      56                 :            :                 }
      57                 :            : 
      58                 :            :         void SetContentsFile(BroFile* f);
      59                 :            :         BroFile* GetContentsFile() const        { return record_contents_file; }
      60                 :            : 
      61                 :            :         void MatchUndelivered(int up_to_seq = -1);
      62                 :            : 
      63                 :            :         // Skip up to seq, as if there's a content gap.
      64                 :            :         // Can be used to skip HTTP data for performance considerations.
      65                 :            :         void SkipToSeq(int seq);
      66                 :            : 
      67                 :            :         int DataSent(double t, int seq, int len, const u_char* data,
      68                 :            :                         bool replaying=true);
      69                 :            :         void AckReceived(int seq);
      70                 :            : 
      71                 :            :         // Checks if we have delivered all contents that we can possibly
      72                 :            :         // deliver for this endpoint.  Calls TCP_Analyzer::EndpointEOF()
      73                 :            :         // when so.
      74                 :            :         void CheckEOF();
      75                 :            : 
      76                 :       1978 :         int HasUndeliveredData() const  { return HasBlocks(); }
      77                 :          0 :         int HadGap() const      { return had_gap; }
      78                 :            :         int DataPending() const;
      79                 :       2270 :         int DataSeq() const             { return LastReassemSeq(); }
      80                 :            : 
      81                 :            :         void DeliverBlock(int seq, int len, const u_char* data);
      82                 :            :         virtual void Deliver(int seq, int len, const u_char* data);
      83                 :            : 
      84                 :       8690 :         TCP_Endpoint* Endpoint()                { return endp; }
      85                 :       9077 :         const TCP_Endpoint* Endpoint() const    { return endp; }
      86                 :            : 
      87                 :       3454 :         int IsOrig() const      { return endp->IsOrig(); }
      88                 :            : 
      89                 :            :         bool IsSkippedContents(int seq, int length) const
      90                 :            :                 { return seq + length <= seq_to_skip; }
      91                 :            : 
      92                 :            : private:
      93                 :          0 :         TCP_Reassembler()       { }
      94                 :            : 
      95                 :          0 :         DECLARE_SERIAL(TCP_Reassembler);
      96                 :            : 
      97                 :            :         void Undelivered(int up_to_seq);
      98                 :            : 
      99                 :            :         void RecordToSeq(int start_seq, int stop_seq, BroFile* f);
     100                 :            :         void RecordBlock(DataBlock* b, BroFile* f);
     101                 :            :         void RecordGap(int start_seq, int upper_seq, BroFile* f);
     102                 :            : 
     103                 :            :         void BlockInserted(DataBlock* b);
     104                 :            :         void Overlap(const u_char* b1, const u_char* b2, int n);
     105                 :            : 
     106                 :            :         TCP_Endpoint* endp;
     107                 :            : 
     108                 :            :         unsigned int deliver_tcp_contents:1;
     109                 :            :         unsigned int had_gap:1;
     110                 :            :         unsigned int did_EOF:1;
     111                 :            :         unsigned int skip_deliveries:1;
     112                 :            : 
     113                 :            :         int seq_to_skip;
     114                 :            :         bool in_delivery;
     115                 :            : 
     116                 :            :         BroFile* record_contents_file;  // file on which to reassemble contents
     117                 :            : 
     118                 :            :         Analyzer* dst_analyzer;
     119                 :            :         TCP_Analyzer* tcp_analyzer;
     120                 :            : 
     121                 :            :         Type type;
     122                 :            :         bool is_orig;
     123                 :            : };
     124                 :            : 
     125                 :            : #endif

Generated by: LCOV version 1.8