Branch data Line data Source code
1 : : // $Id: Reassem.h 6703 2009-05-13 22:27:44Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef reassem_h
6 : : #define reassem_h
7 : :
8 : : #include "Active.h"
9 : : #include "Obj.h"
10 : :
11 : : class DataBlock {
12 : : public:
13 : : DataBlock(const u_char* data, int size, int seq,
14 : : DataBlock* next, DataBlock* prev);
15 : :
16 : : ~DataBlock();
17 : :
18 : 7962 : int Size() const { return upper - seq; }
19 : :
20 : : DataBlock* next; // next block with higher seq #
21 : : DataBlock* prev; // previous block with lower seq #
22 : : int seq, upper;
23 : : u_char* block;
24 : : };
25 : :
26 : :
27 : : enum ReassemblerType { REASSEM_IP, REASSEM_TCP };
28 : :
29 : : class Reassembler : public BroObj {
30 : : public:
31 : : Reassembler(int init_seq, const uint32* ip_addr,
32 : : ReassemblerType arg_type);
33 : : virtual ~Reassembler();
34 : :
35 : : void NewBlock(double t, int seq, int len, const u_char* data);
36 : :
37 : : // Throws away all blocks up to seq. Returns number of bytes
38 : : // if not all in-sequence, 0 if they were.
39 : : int TrimToSeq(int seq);
40 : :
41 : : // Delete all held blocks.
42 : : void ClearBlocks();
43 : :
44 : 1978 : int HasBlocks() const { return blocks != 0; }
45 : 2270 : int LastReassemSeq() const { return last_reassem_seq; }
46 : :
47 : : int TotalSize() const; // number of bytes buffered up
48 : :
49 : : void Describe(ODesc* d) const;
50 : :
51 : : bool Serialize(SerialInfo* info) const;
52 : : static Reassembler* Unserialize(UnserialInfo* info);
53 : :
54 : : // Sum over all data buffered in some reassembler.
55 : 0 : static unsigned int TotalMemoryAllocation() { return total_size; }
56 : :
57 : : protected:
58 : 0 : Reassembler() { }
59 : :
60 : : DECLARE_ABSTRACT_SERIAL(Reassembler);
61 : :
62 : : friend class DataBlock;
63 : :
64 : : virtual void Undelivered(int up_to_seq);
65 : :
66 : : virtual void BlockInserted(DataBlock* b) = 0;
67 : : virtual void Overlap(const u_char* b1, const u_char* b2, int n) = 0;
68 : :
69 : : DataBlock* AddAndCheck(DataBlock* b, int seq,
70 : : int upper, const u_char* data);
71 : :
72 : : DataBlock* blocks;
73 : : DataBlock* last_block;
74 : : int last_reassem_seq;
75 : : int trim_seq; // how far we've trimmed
76 : :
77 : : ReassemblyPolicy policy;
78 : :
79 : : static unsigned int total_size;
80 : : };
81 : :
82 : 8168 : inline DataBlock::~DataBlock()
83 : : {
84 : 8168 : Reassembler::total_size -= pad_size(upper - seq) + padded_sizeof(DataBlock);
85 [ + - ]: 8168 : delete [] block;
86 : 8168 : }
87 : :
88 : : #endif
|