mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-09-19 09:49:21 +03:00
Cedar: introduce options API in Proto
PROTO_OPTION is a structure that describes an option (who would've guessed?). It's designed in a way that allows it to occupy as low memory as possible, while providing great flexibility. The idea is similar to the one implemented in LIST for trivial types, with the difference that PROTO_OPTION doesn't require casting due to the use of union.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#ifndef PROTO_H
|
||||
#define PROTO_H
|
||||
|
||||
#define PROTO_OPTION_TOGGLE_NAME "Enabled"
|
||||
|
||||
// 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
|
||||
@ -9,11 +11,18 @@
|
||||
|
||||
typedef enum PROTO_MODE
|
||||
{
|
||||
PROTO_MODE_UNKNOWN = 0,
|
||||
PROTO_MODE_TCP = 1,
|
||||
PROTO_MODE_UDP = 2
|
||||
PROTO_MODE_UNKNOWN,
|
||||
PROTO_MODE_TCP,
|
||||
PROTO_MODE_UDP
|
||||
} PROTO_MODE;
|
||||
|
||||
typedef enum PROTO_OPTION_VALUE
|
||||
{
|
||||
PROTO_OPTION_UNKNOWN,
|
||||
PROTO_OPTION_STRING,
|
||||
PROTO_OPTION_BOOL
|
||||
} PROTO_OPTION_VALUE;
|
||||
|
||||
typedef struct PROTO
|
||||
{
|
||||
CEDAR *Cedar;
|
||||
@ -22,10 +31,22 @@ typedef struct PROTO
|
||||
UDPLISTENER *UdpListener;
|
||||
} PROTO;
|
||||
|
||||
typedef struct PROTO_OPTION
|
||||
{
|
||||
char *Name;
|
||||
PROTO_OPTION_VALUE Type;
|
||||
union
|
||||
{
|
||||
bool Bool;
|
||||
char *String;
|
||||
};
|
||||
} PROTO_OPTION;
|
||||
|
||||
typedef struct PROTO_IMPL
|
||||
{
|
||||
const char *(*Name)();
|
||||
bool (*Init)(void **param, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
|
||||
const PROTO_OPTION *(*Options)();
|
||||
bool (*Init)(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
|
||||
void (*Free)(void *param);
|
||||
bool (*IsPacketForMe)(const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
||||
bool (*ProcessData)(void *param, TCP_RAW_DATA *in, FIFO *out);
|
||||
@ -35,6 +56,7 @@ typedef struct PROTO_IMPL
|
||||
typedef struct PROTO_CONTAINER
|
||||
{
|
||||
const char *Name;
|
||||
LIST *Options;
|
||||
const PROTO_IMPL *Impl;
|
||||
} PROTO_CONTAINER;
|
||||
|
||||
@ -56,11 +78,14 @@ typedef struct PROTO_SESSION
|
||||
volatile bool Halt;
|
||||
} PROTO_SESSION;
|
||||
|
||||
int ProtoOptionCompare(void *p1, void *p2);
|
||||
int ProtoContainerCompare(void *p1, void *p2);
|
||||
int ProtoSessionCompare(void *p1, void *p2);
|
||||
|
||||
UINT ProtoSessionHash(void *p);
|
||||
|
||||
bool ProtoEnabled(const PROTO *proto, const char *name);
|
||||
|
||||
PROTO *ProtoNew(CEDAR *cedar);
|
||||
void ProtoDelete(PROTO *proto);
|
||||
|
||||
|
Reference in New Issue
Block a user