LCOV - code coverage report
Current view: top level - src - TCP_Endpoint.h (source / functions) Hit Total Coverage
Test: app.info Lines: 22 25 88.0 %
Date: 2010-12-13 Functions: 12 15 80.0 %
Branches: 12 12 100.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: TCP_Endpoint.h 6219 2008-10-01 05:39:07Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #ifndef tcpendpoint_h
       6                 :            : #define tcpendpoint_h
       7                 :            : 
       8                 :            : typedef enum {
       9                 :            :         TCP_ENDPOINT_INACTIVE,  // no SYN (or other packets) seen for this side
      10                 :            :         TCP_ENDPOINT_SYN_SENT,  // SYN seen, but no ack
      11                 :            :         TCP_ENDPOINT_SYN_ACK_SENT,      // SYN ack seen, no initial SYN
      12                 :            :         TCP_ENDPOINT_PARTIAL,   // data seen, but no SYN
      13                 :            :         TCP_ENDPOINT_ESTABLISHED,       // SYN ack seen (implicit for SYN
      14                 :            :                                         // sent by responder)
      15                 :            :         TCP_ENDPOINT_CLOSED,    // FIN seen
      16                 :            :         TCP_ENDPOINT_RESET      // RST seen
      17                 :            : } EndpointState;
      18                 :            : 
      19                 :            : class Connection;
      20                 :            : class TCP_Reassembler;
      21                 :            : class IP_Hdr;
      22                 :            : class TCP_Analyzer;
      23                 :            : 
      24                 :            : // One endpoint of a TCP connection.
      25                 :            : class TCP_Endpoint {
      26                 :            : public:
      27                 :            :         TCP_Endpoint(TCP_Analyzer* analyzer, int is_orig);
      28                 :            :         ~TCP_Endpoint();
      29                 :            : 
      30                 :            :         void Done();
      31                 :            : 
      32                 :          0 :         TCP_Analyzer* TCP()     { return tcp_analyzer; }
      33                 :            : 
      34                 :            :         void SetPeer(TCP_Endpoint* p);
      35                 :            : 
      36                 :            :         EndpointState State() const     { return state; }
      37                 :            :         void SetState(EndpointState new_state);
      38                 :            :         bro_int_t Size() const;
      39                 :          4 :         int IsActive() const
      40 [ +  + ][ +  + ]:          4 :                 { return state != TCP_ENDPOINT_INACTIVE && ! did_close; }
      41                 :            : 
      42                 :            :         double StartTime() const        { return start_time; }
      43                 :            :         double LastTime() const         { return last_time; }
      44                 :            : 
      45                 :      40654 :         uint32 StartSeq() const         { return start_seq; }
      46                 :      22157 :         uint32 LastSeq() const          { return last_seq; }
      47                 :      25692 :         uint32 AckSeq() const           { return ack_seq; }
      48                 :            : 
      49                 :       2582 :         void InitStartSeq(uint32 seq)   { start_seq = seq; }
      50                 :       2582 :         void InitLastSeq(uint32 seq)    { last_seq = seq; }
      51                 :       2582 :         void InitAckSeq(uint32 seq)     { ack_seq = seq; }
      52                 :            : 
      53                 :       9209 :         void UpdateLastSeq(uint32 seq)
      54                 :            :                 {
      55         [ +  + ]:       9209 :                 if ( seq < last_seq )
      56                 :         16 :                         ++last_seq_high;
      57                 :       9209 :                 last_seq = seq;
      58                 :       9209 :                 }
      59                 :            : 
      60                 :       7355 :         void UpdateAckSeq(uint32 seq)
      61                 :            :                 {
      62         [ +  + ]:       7355 :                 if ( seq < ack_seq )
      63                 :          6 :                         ++ack_seq_high;
      64                 :       7355 :                 ack_seq = seq;
      65                 :       7355 :                 }
      66                 :            : 
      67                 :            :         // True if none of this endpoint's data has been acknowledged.
      68                 :            :         // We allow for possibly one octet being ack'd in the case of
      69                 :            :         // an initial SYN exchange.
      70                 :      16179 :         int NoDataAcked() const
      71 [ +  + ][ +  + ]:      16179 :                 { return ack_seq == start_seq || ack_seq == start_seq + 1; }
      72                 :            : 
      73                 :            :         Connection* Conn() const;
      74                 :            : 
      75                 :       7627 :         int HasContents() const         { return contents_processor != 0; }
      76                 :            :         int HadGap() const;
      77                 :            : 
      78                 :      46246 :         inline int IsOrig() const               { return is_orig; }
      79                 :            : 
      80                 :          0 :         int HasDoneSomething() const    { return last_time != 0.0; }
      81                 :            : 
      82                 :            :         void AddReassembler(TCP_Reassembler* contents_processor);
      83                 :            : 
      84                 :            :         int DataPending() const;
      85                 :            :         int HasUndeliveredData() const;
      86                 :            :         void CheckEOF();
      87                 :            : 
      88                 :            :         // Returns the volume of data buffered in the reassembler.
      89                 :            :         // First parameter returns data that is above a hole, and thus is
      90                 :            :         // waiting on the hole being filled.  Second parameter returns
      91                 :            :         // data that has been processed but is awaiting an ACK to free
      92                 :            :         // it up.
      93                 :            :         //
      94                 :            :         // If we're not processing contents, then naturally each of
      95                 :            :         // these is empty.
      96                 :            :         void SizeBufferedData(int& waiting_on_hole, int& waiting_on_ack);
      97                 :            : 
      98                 :            :         int ValidChecksum(const struct tcphdr* tp, int len) const;
      99                 :            : 
     100                 :            :         // Returns true if the data was used (and hence should be recorded
     101                 :            :         // in the save file), false otherwise.
     102                 :            :         int DataSent(double t, int seq, int len, int caplen, const u_char* data,
     103                 :            :                         const IP_Hdr* ip, const struct tcphdr* tp);
     104                 :            : 
     105                 :            :         void AckReceived(int seq);
     106                 :            : 
     107                 :            :         void SetContentsFile(BroFile* f);
     108                 :          0 :         BroFile* GetContentsFile() const        { return contents_file; }
     109                 :            : 
     110                 :            :         // Codes used for tracking history.  For responders, we shift these
     111                 :            :         // over by 16 bits in order to fit both originator and responder
     112                 :            :         // into a Connection's hist_seen field.
     113                 :            : #define HIST_SYN_PKT 0x1
     114                 :            : #define HIST_FIN_PKT 0x2
     115                 :            : #define HIST_RST_PKT 0x4
     116                 :            : #define HIST_FIN_RST_PKT 0x8
     117                 :            : #define HIST_DATA_PKT 0x10
     118                 :            : #define HIST_ACK_PKT 0x20
     119                 :            : #define HIST_MULTI_FLAG_PKT 0x40
     120                 :            : #define HIST_CORRUPT_PKT 0x80
     121                 :            :         int CheckHistory(uint32 mask, char code);
     122                 :            :         void AddHistory(char code);
     123                 :            : 
     124                 :            :         //### combine into a set of flags:
     125                 :            :         EndpointState state, prev_state;
     126                 :            :         TCP_Endpoint* peer;
     127                 :            :         TCP_Reassembler* contents_processor;
     128                 :            :         TCP_Analyzer* tcp_analyzer;
     129                 :            :         BroFile* contents_file;
     130                 :            :         uint32 checksum_base;
     131                 :            : 
     132                 :            :         double start_time, last_time;
     133                 :            :         const uint32* src_addr; // the other endpoint
     134                 :            :         const uint32* dst_addr; // this endpoint
     135                 :            :         uint32 window; // current congestion window (*scaled*, not pre-scaling)
     136                 :            :         int window_scale;  // from the TCP option
     137                 :            :         uint32 window_ack_seq; // at which ack_seq number did we record 'window'
     138                 :            :         uint32 window_seq; // at which sending sequence number did we record 'window'
     139                 :            :         int contents_start_seq; // relative seq # where contents file starts
     140                 :            :         int FIN_seq;            // relative seq # to start_seq
     141                 :            :         int SYN_cnt, FIN_cnt, RST_cnt;
     142                 :            :         int did_close;          // whether we've reported it closing
     143                 :            :         int is_orig;
     144                 :            : 
     145                 :            :         // Sequence numbers associated with last control packets.
     146                 :            :         // Used to determine whether ones seen again are interesting,
     147                 :            :         // for tracking history.
     148                 :            :         uint32 hist_last_SYN, hist_last_FIN, hist_last_RST;
     149                 :            : 
     150                 :            : protected:
     151                 :            :         uint32 start_seq, last_seq, ack_seq;    // in host order
     152                 :            :         uint32 last_seq_high, ack_seq_high;
     153                 :            : };
     154                 :            : 
     155                 :            : #define ENDIAN_UNKNOWN 0
     156                 :            : #define ENDIAN_LITTLE 1
     157                 :            : #define ENDIAN_BIG 2
     158                 :            : #define ENDIAN_CONFUSED 3
     159                 :            : 
     160                 :            : #endif

Generated by: LCOV version 1.8