mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-09-19 09:49:21 +03:00
Cedar/Proto: implement UDP system
When a datagram is received, the matching session is looked up in a hash list; if it's not found, a new session is created. This method allows to use a single UDP port for multiple protocols, as we do with TCP. Also, each session has its own dedicated thread, used to process the received datagrams and generate the ones that are then sent through the UDP listener. In addition to guaranteeing constant performance, separate threads also prevent a single one from blocking all sessions.
This commit is contained in:
@ -18,6 +18,8 @@ typedef struct PROTO
|
||||
{
|
||||
CEDAR *Cedar;
|
||||
LIST *Impls;
|
||||
HASH_LIST *Sessions;
|
||||
UDPLISTENER *UdpListener;
|
||||
} PROTO;
|
||||
|
||||
typedef struct PROTO_IMPL
|
||||
@ -26,11 +28,33 @@ typedef struct PROTO_IMPL
|
||||
void (*Free)(void *param);
|
||||
char *(*Name)();
|
||||
bool (*IsPacketForMe)(const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
||||
bool (*ProcessData)(void *param, TCP_RAW_DATA *received_data, FIFO *data_to_send);
|
||||
bool (*ProcessData)(void *param, TCP_RAW_DATA *in, FIFO *out);
|
||||
bool (*ProcessDatagrams)(void *param, LIST *in, LIST *out);
|
||||
void (*BufferLimit)(void *param, const bool reached);
|
||||
} PROTO_IMPL;
|
||||
|
||||
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;
|
||||
|
||||
int ProtoImplCompare(void *p1, void *p2);
|
||||
int ProtoSessionCompare(void *p1, void *p2);
|
||||
|
||||
UINT ProtoSessionHash(void *p);
|
||||
|
||||
PROTO *ProtoNew(CEDAR *cedar);
|
||||
void ProtoDelete(PROTO *proto);
|
||||
@ -38,6 +62,14 @@ void ProtoDelete(PROTO *proto);
|
||||
bool ProtoImplAdd(PROTO *proto, PROTO_IMPL *impl);
|
||||
PROTO_IMPL *ProtoImplDetect(PROTO *proto, const PROTO_MODE mode, const UCHAR *data, const UINT size);
|
||||
|
||||
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);
|
||||
|
||||
bool ProtoHandleConnection(PROTO *proto, SOCK *sock);
|
||||
void ProtoHandleDatagrams(UDPLISTENER *listener, LIST *datagrams);
|
||||
void ProtoSessionThread(THREAD *thread, void *param);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user