2019-07-26 09:36:54 +03:00
|
|
|
#ifndef PROTO_H
|
|
|
|
#define PROTO_H
|
|
|
|
|
|
|
|
// OpenVPN sends 2 bytes, thus this is the buffer size.
|
|
|
|
// If another protocol requires more bytes to be detected, the buffer size must be increased.
|
|
|
|
#define PROTO_CHECK_BUFFER_SIZE 2
|
|
|
|
|
|
|
|
#define PROTO_TCP_BUFFER_SIZE (128 * 1024)
|
|
|
|
|
2020-05-11 08:07:04 +03:00
|
|
|
typedef enum PROTO_MODE
|
|
|
|
{
|
|
|
|
PROTO_MODE_UNKNOWN = 0,
|
|
|
|
PROTO_MODE_TCP = 1,
|
|
|
|
PROTO_MODE_UDP = 2
|
|
|
|
} PROTO_MODE;
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-05-01 08:14:38 +03:00
|
|
|
typedef struct PROTO
|
|
|
|
{
|
|
|
|
CEDAR *Cedar;
|
|
|
|
LIST *Impls;
|
2020-05-11 09:22:44 +03:00
|
|
|
HASH_LIST *Sessions;
|
|
|
|
UDPLISTENER *UdpListener;
|
2020-05-01 08:14:38 +03:00
|
|
|
} PROTO;
|
|
|
|
|
2019-07-26 09:36:54 +03:00
|
|
|
typedef struct PROTO_IMPL
|
|
|
|
{
|
|
|
|
bool (*Init)(void **param, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se);
|
|
|
|
void (*Free)(void *param);
|
|
|
|
char *(*Name)();
|
2020-05-11 08:07:04 +03:00
|
|
|
bool (*IsPacketForMe)(const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
2020-05-11 09:22:44 +03:00
|
|
|
bool (*ProcessData)(void *param, TCP_RAW_DATA *in, FIFO *out);
|
|
|
|
bool (*ProcessDatagrams)(void *param, LIST *in, LIST *out);
|
2019-07-26 09:36:54 +03:00
|
|
|
} PROTO_IMPL;
|
|
|
|
|
2020-05-11 09:22:44 +03:00
|
|
|
typedef struct PROTO_SESSION
|
|
|
|
{
|
|
|
|
void *Param;
|
|
|
|
PROTO *Proto;
|
|
|
|
PROTO_IMPL *Impl;
|
|
|
|
IP SrcIp;
|
|
|
|
USHORT SrcPort;
|
|
|
|
IP DstIp;
|
|
|
|
USHORT DstPort;
|
|
|
|
LIST *DatagramsIn;
|
|
|
|
LIST *DatagramsOut;
|
|
|
|
SOCK_EVENT *SockEvent;
|
|
|
|
INTERRUPT_MANAGER *InterruptManager;
|
|
|
|
THREAD *Thread;
|
|
|
|
LOCK *Lock;
|
|
|
|
volatile bool Halt;
|
|
|
|
} PROTO_SESSION;
|
|
|
|
|
2020-05-01 08:14:38 +03:00
|
|
|
int ProtoImplCompare(void *p1, void *p2);
|
2020-05-11 09:22:44 +03:00
|
|
|
int ProtoSessionCompare(void *p1, void *p2);
|
|
|
|
|
|
|
|
UINT ProtoSessionHash(void *p);
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-05-01 08:14:38 +03:00
|
|
|
PROTO *ProtoNew(CEDAR *cedar);
|
|
|
|
void ProtoDelete(PROTO *proto);
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-05-01 08:14:38 +03:00
|
|
|
bool ProtoImplAdd(PROTO *proto, PROTO_IMPL *impl);
|
2020-05-11 08:07:04 +03:00
|
|
|
PROTO_IMPL *ProtoImplDetect(PROTO *proto, const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-05-11 09:22:44 +03:00
|
|
|
PROTO_SESSION *ProtoNewSession(PROTO *proto, PROTO_IMPL *impl, const IP *src_ip, const USHORT src_port, const IP *dst_ip, const USHORT dst_port);
|
|
|
|
void ProtoDeleteSession(PROTO_SESSION *session);
|
|
|
|
|
|
|
|
bool ProtoSetListenIP(PROTO *proto, const IP *ip);
|
|
|
|
bool ProtoSetUdpPorts(PROTO *proto, const LIST *ports);
|
|
|
|
|
2020-07-12 04:05:51 +03:00
|
|
|
bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol);
|
2020-05-11 09:22:44 +03:00
|
|
|
void ProtoHandleDatagrams(UDPLISTENER *listener, LIST *datagrams);
|
|
|
|
void ProtoSessionThread(THREAD *thread, void *param);
|
2019-07-26 09:36:54 +03:00
|
|
|
|
|
|
|
#endif
|