engine/session.h

Go to the documentation of this file.
00001 #ifndef HLBR_SESSION_H
00002 #define HLBR_SESSION_H
00003 
00004 #include "../config.h"
00005 #include "hlbr.h"
00006 
00007 #define IP_START        1
00008 #define IP_GROW         1
00009 #define PORT_START      5
00010 #define PORT_GROW       10
00011 
00012 /* Timeout for a (TCP) session */
00013 #define SESSION_FORCE_TIMEOUT   60
00014 
00015 /* TCP session direction */
00016 #define SESSION_UNKNOWN                 0
00017 #define SESSION_IP1_SERVER              1
00018 #define SESSION_IP2_SERVER              2
00019 #define SESSION_IP1_SERVER_MAYBE        3
00020 #define SESSION_IP2_SERVER_MAYBE        4
00021 
00022 
00023 #define TCP_STATE_NEW           0
00024 #define TCP_STATE_SYN           1
00025 #define TCP_STATE_SYNACK        2
00026 #define TCP_STATE_DATA          3
00027 #define TCP_STATE_FIN           4
00028 #define TCP_STATE_RESET         6
00029 #define TCP_STATE_LATE          7
00030 
00031 struct ip_pair;
00032 struct ip_bin;
00033 
00034 #define TCP_PAYLOAD_BUFFER_SIZE 4*1460
00035 #define TCP_QUEUE_SIZE          16      // max number of TCP packets to 'queue'
00036 #define TCP_PAYLOAD_PIECES_SIZE 1024    // max number of TCP packets to put in the Queue (if it can hold them all)
00037 
00038 
00039 struct tcp_stream_piece {
00040         unsigned int    piece_start;    // seq number
00041         unsigned int    piece_end;
00042         int             PacketSlot;
00043 };
00044 
00065 struct tcp_stream {
00066         unsigned short int      NumPieces;
00067         struct tcp_stream_piece Pieces[TCP_QUEUE_SIZE];
00068         unsigned char           Payloads[TCP_PAYLOAD_BUFFER_SIZE];
00069         unsigned char           QueueSize;
00070         int                     Queue[TCP_PAYLOAD_PIECES_SIZE];
00071         unsigned int            TopSeq;
00072         unsigned int            LastSeq;
00073 };
00074 
00075 
00082 typedef struct port_pair {
00083         unsigned int            SessionID;
00084         unsigned short          Port1;
00085         unsigned short          Port2;
00086         struct ip_pair*         Parent;
00087         
00088         long int                FirstTime;
00089         long int                LastTime;
00090         unsigned char           Direction;
00091 
00092         unsigned char           Error; 
00093         /* Notes: this (Error) is being used to flag:
00094            - srv->cli:ServerAck doesn't match ClientSeq+1 during handshake1
00095            - srv->cli:ServerAck/ClientSeq don't match stored ones in handshake2
00096            - srv->cli:any unexpected packet order
00097            - cli->srv:any unexpected packet order (both with no fin/rst and
00098              with any of them)
00099         */
00100         
00101         unsigned short          TCPCount;
00102         unsigned short          UDPCount;
00103         unsigned short          ICMPCount;
00104         unsigned short          OtherCount;
00105 
00106         unsigned char           ServerState;
00107         unsigned int            ServerSeq;
00108         unsigned int            ServerAck;
00109         unsigned char           ServerFin;
00110         unsigned char           ClientState;
00111         unsigned int            ClientSeq;
00112         unsigned int            ClientAck;
00113         unsigned char           ClientFin;
00114 
00121         struct port_pair*       TimeNext;
00122         struct port_pair*       TimePrev;
00123 
00124         /* The two streams in a TCP session (cli->srv and srv->cli) */
00125         struct tcp_stream*      Stream0;
00126         struct tcp_stream*      Stream1;
00127         char                    noreassemble;
00128 } PP;
00129 
00137 typedef struct ip_pair {
00138         unsigned int    IP1;
00139         unsigned int    IP2;
00140         unsigned int    NumAllocated;
00141         unsigned int    NumPorts;
00142         PP**            Ports;
00143         struct ip_bin*  Parent;
00144 
00145         unsigned char   RefuseFromThisIP : 1;   
00146 } IPP;
00147 
00148 typedef struct ip_bin {
00149         unsigned int    NumAllocated;
00150         unsigned int    NumIPs;
00151         IPP**           Pairs;
00152 } IPB;
00153 
00154 typedef struct session_func{
00155         void (*Func) (PP* Port, void* Data);
00156         void*                                   Data;
00157         struct session_func*    Next;
00158 } SFunc;
00159 
00160 int InitSession();
00161 int AddSessionCreateHandler(void (*Func) (PP* Port, void* Data), void* Data);
00162 int AddSessionDestroyHandler(void (*Func) (PP* Port, void* Data), void* Data);
00163 int AssignSessionTCP(int, void*);
00164 int TCPRemount_unblock(int, int);
00165 
00166 
00167 #endif

Generated on Sat Jul 7 23:33:10 2007 for HLBR by  doxygen 1.5.2