Branch data Line data Source code
1 : : // $Id: SteppingStone.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 steppingstone_h
6 : : #define steppingstone_h
7 : :
8 : : #include "Queue.h"
9 : : #include "TCP.h"
10 : :
11 : : class NetSessions;
12 : :
13 : : class SteppingStoneEndpoint;
14 : : class SteppingStoneManager;
15 : :
16 : 0 : declare(PQueue,SteppingStoneEndpoint);
17 [ # # ][ # # ]: 0 : declare(PDict,SteppingStoneEndpoint);
18 : :
19 : : class SteppingStoneEndpoint : public BroObj {
20 : : public:
21 : : SteppingStoneEndpoint(TCP_Endpoint* e, SteppingStoneManager* m);
22 : : ~SteppingStoneEndpoint();
23 : : void Done();
24 : :
25 : : int DataSent(double t, int seq, int len, int caplen, const u_char* data,
26 : : const IP_Hdr* ip, const struct tcphdr* tp);
27 : :
28 : : protected:
29 : : void Event(EventHandlerPtr f, int id1, int id2 = -1);
30 : : void CreateEndpEvent(int is_orig);
31 : :
32 : : TCP_Endpoint* endp;
33 : : int stp_max_top_seq;
34 : : double stp_last_time;
35 : : double stp_resume_time;
36 : : SteppingStoneManager* stp_manager;
37 : :
38 : : // Hashes for inbound/outbound endpoints that are correlated
39 : : // at least once with this endpoint. They are necessary for
40 : : // removing correlated endpoint pairs in Bro, since there is
41 : : // no LOOP in Bro language.
42 : : int stp_id;
43 : : HashKey* stp_key;
44 : : PDict(SteppingStoneEndpoint) stp_inbound_endps;
45 : : PDict(SteppingStoneEndpoint) stp_outbound_endps;
46 : : };
47 : :
48 : : class SteppingStone_Analyzer : public TCP_ApplicationAnalyzer {
49 : : public:
50 : : SteppingStone_Analyzer(Connection* c);
51 [ # # ][ # # ]: 0 : virtual ~SteppingStone_Analyzer() {};
52 : :
53 : : virtual void Init();
54 : : virtual void Done();
55 : :
56 : 0 : static Analyzer* InstantiateAnalyzer(Connection* conn)
57 : 0 : { return new SteppingStone_Analyzer(conn); }
58 : :
59 : 939 : static bool Available() { return stp_correlate_pair; }
60 : :
61 : : protected:
62 : : // We support both packet and stream input and can be put in place even
63 : : // if the TCP analyzer is not yet reassebmling.
64 : : virtual void DeliverPacket(int len, const u_char* data, bool is_orig,
65 : : int seq, const IP_Hdr* ip, int caplen);
66 : : virtual void DeliverStream(int len, const u_char* data, bool is_orig);
67 : :
68 : : int orig_stream_pos;
69 : : int resp_stream_pos;
70 : :
71 : : SteppingStoneManager* stp_manager;
72 : : SteppingStoneEndpoint* orig_endp;
73 : : SteppingStoneEndpoint* resp_endp;
74 : : };
75 : :
76 : : // Manages ids for the possible stepping stone connections.
77 : 0 : class SteppingStoneManager {
78 : : public:
79 : 0 : SteppingStoneManager() { endp_cnt = 0; }
80 : :
81 : 0 : PQueue(SteppingStoneEndpoint)& OrderedEndpoints()
82 : 0 : { return ordered_endps; }
83 : :
84 : : // Use postfix ++, since the first ID needs to be even.
85 : 0 : int NextID() { return endp_cnt++; }
86 : :
87 : : protected:
88 : : PQueue(SteppingStoneEndpoint) ordered_endps;
89 : : int endp_cnt;
90 : : };
91 : :
92 : : #endif /* steppingstone_h */
|