2019-07-26 09:36:54 +03:00
|
|
|
#ifndef PROTO_H
|
|
|
|
#define PROTO_H
|
|
|
|
|
2021-04-05 05:48:25 +03:00
|
|
|
#include "CedarType.h"
|
|
|
|
|
|
|
|
#include "Mayaqua/MayaType.h"
|
|
|
|
#include "Mayaqua/Network.h"
|
|
|
|
|
2020-07-20 03:03:44 +03:00
|
|
|
#define PROTO_OPTION_TOGGLE_NAME "Enabled"
|
|
|
|
|
2019-07-26 09:36:54 +03:00
|
|
|
// 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
|
|
|
|
{
|
2020-07-20 03:03:44 +03:00
|
|
|
PROTO_MODE_UNKNOWN,
|
|
|
|
PROTO_MODE_TCP,
|
|
|
|
PROTO_MODE_UDP
|
2020-05-11 08:07:04 +03:00
|
|
|
} PROTO_MODE;
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-07-20 03:03:44 +03:00
|
|
|
typedef enum PROTO_OPTION_VALUE
|
|
|
|
{
|
|
|
|
PROTO_OPTION_UNKNOWN,
|
|
|
|
PROTO_OPTION_STRING,
|
2021-04-21 09:12:45 +03:00
|
|
|
PROTO_OPTION_BOOL,
|
|
|
|
PROTO_OPTION_UINT32
|
2020-07-20 03:03:44 +03:00
|
|
|
} PROTO_OPTION_VALUE;
|
|
|
|
|
2020-05-01 08:14:38 +03:00
|
|
|
typedef struct PROTO
|
|
|
|
{
|
|
|
|
CEDAR *Cedar;
|
2020-07-18 18:54:36 +03:00
|
|
|
LIST *Containers;
|
2020-05-11 09:22:44 +03:00
|
|
|
HASH_LIST *Sessions;
|
|
|
|
UDPLISTENER *UdpListener;
|
2020-05-01 08:14:38 +03:00
|
|
|
} PROTO;
|
|
|
|
|
2021-04-05 05:48:25 +03:00
|
|
|
struct PROTO_OPTION
|
2020-07-20 03:03:44 +03:00
|
|
|
{
|
|
|
|
char *Name;
|
|
|
|
PROTO_OPTION_VALUE Type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
bool Bool;
|
|
|
|
char *String;
|
2021-04-21 09:12:45 +03:00
|
|
|
UINT UInt32;
|
2020-07-20 03:03:44 +03:00
|
|
|
};
|
2021-04-05 05:48:25 +03:00
|
|
|
};
|
2020-07-20 03:03:44 +03:00
|
|
|
|
2019-07-26 09:36:54 +03:00
|
|
|
typedef struct PROTO_IMPL
|
|
|
|
{
|
2020-07-17 03:55:47 +03:00
|
|
|
const char *(*Name)();
|
2020-07-20 03:03:44 +03:00
|
|
|
const PROTO_OPTION *(*Options)();
|
2020-08-12 01:49:31 +03:00
|
|
|
char *(*OptionStringValue)(const char *name);
|
2020-07-20 03:03:44 +03:00
|
|
|
bool (*Init)(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
|
2019-07-26 09:36:54 +03:00
|
|
|
void (*Free)(void *param);
|
2020-07-29 21:00:46 +03:00
|
|
|
bool (*IsPacketForMe)(const PROTO_MODE mode, const void *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-07-18 18:54:36 +03:00
|
|
|
typedef struct PROTO_CONTAINER
|
|
|
|
{
|
|
|
|
const char *Name;
|
2020-07-20 03:03:44 +03:00
|
|
|
LIST *Options;
|
2020-07-18 18:54:36 +03:00
|
|
|
const PROTO_IMPL *Impl;
|
|
|
|
} PROTO_CONTAINER;
|
|
|
|
|
2020-05-11 09:22:44 +03:00
|
|
|
typedef struct PROTO_SESSION
|
|
|
|
{
|
|
|
|
void *Param;
|
2020-07-18 18:54:36 +03:00
|
|
|
const PROTO *Proto;
|
|
|
|
const PROTO_IMPL *Impl;
|
2020-05-11 09:22:44 +03:00
|
|
|
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-08-06 04:23:55 +03:00
|
|
|
void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...);
|
|
|
|
|
2020-07-20 03:03:44 +03:00
|
|
|
int ProtoOptionCompare(void *p1, void *p2);
|
2020-07-18 18:54:36 +03:00
|
|
|
int ProtoContainerCompare(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-07-20 03:03:44 +03:00
|
|
|
bool ProtoEnabled(const PROTO *proto, const char *name);
|
|
|
|
|
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-07-18 18:54:36 +03:00
|
|
|
PROTO_CONTAINER *ProtoContainerNew(const PROTO_IMPL *impl);
|
|
|
|
void ProtoContainerDelete(PROTO_CONTAINER *container);
|
|
|
|
|
|
|
|
const PROTO_CONTAINER *ProtoDetect(const PROTO *proto, const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
2019-07-26 09:36:54 +03:00
|
|
|
|
2020-08-06 03:41:13 +03:00
|
|
|
PROTO_SESSION *ProtoSessionNew(const PROTO *proto, const PROTO_CONTAINER *container, const IP *src_ip, const USHORT src_port, const IP *dst_ip, const USHORT dst_port);
|
|
|
|
void ProtoSessionDelete(PROTO_SESSION *session);
|
2020-05-11 09:22:44 +03:00
|
|
|
|
|
|
|
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
|