mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-06 07:44:57 +03:00
Add interface for easy protocol implementation
This commit adds a protocol interface to the server, its purpose is to manage TCP connections and the various third-party protocols. More specifically, ProtoHandleConnection() takes care of exchanging the packets between the local and remote endpoint; the protocol implementation only has to parse them and act accordingly. The interface knows which protocol is the connection for by calling IsPacketForMe(), a function implemented for each protocol.
This commit is contained in:
@ -421,6 +421,7 @@ typedef struct TUBEPAIR_DATA TUBEPAIR_DATA;
|
||||
typedef struct UDPLISTENER UDPLISTENER;
|
||||
typedef struct UDPLISTENER_SOCK UDPLISTENER_SOCK;
|
||||
typedef struct UDPPACKET UDPPACKET;
|
||||
typedef struct TCP_RAW_DATA TCP_RAW_DATA;
|
||||
typedef struct INTERRUPT_MANAGER INTERRUPT_MANAGER;
|
||||
typedef struct TUBE_FLUSH_LIST TUBE_FLUSH_LIST;
|
||||
typedef struct ICMP_RESULT ICMP_RESULT;
|
||||
|
@ -18980,6 +18980,40 @@ UDPLISTENER_SOCK *DetermineUdpSocketForSending(UDPLISTENER *u, UDPPACKET *p)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void FreeTcpRawData(TCP_RAW_DATA *trd)
|
||||
{
|
||||
// Validate arguments
|
||||
if (trd == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReleaseFifo(trd->Data);
|
||||
Free(trd);
|
||||
}
|
||||
|
||||
TCP_RAW_DATA *NewTcpRawData(IP *src_ip, UINT src_port, IP *dst_ip, UINT dst_port)
|
||||
{
|
||||
TCP_RAW_DATA *trd;
|
||||
// Validate arguments
|
||||
if (dst_ip == NULL || dst_port == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
trd = ZeroMalloc(sizeof(TCP_RAW_DATA));
|
||||
|
||||
Copy(&trd->SrcIP, src_ip, sizeof(IP));
|
||||
trd->SrcPort = src_port;
|
||||
|
||||
Copy(&trd->DstIP, dst_ip, sizeof(IP));
|
||||
trd->DstPort = dst_port;
|
||||
|
||||
trd->Data = NewFifoFast();
|
||||
|
||||
return trd;
|
||||
}
|
||||
|
||||
// Release of the UDP packet
|
||||
void FreeUdpPacket(UDPPACKET *p)
|
||||
{
|
||||
|
@ -456,6 +456,16 @@ struct TUBEPAIR_DATA
|
||||
SOCK_EVENT *SockEvent1, *SockEvent2; // SockEvent
|
||||
};
|
||||
|
||||
// TCP raw data
|
||||
struct TCP_RAW_DATA
|
||||
{
|
||||
IP SrcIP; // Source IP address
|
||||
IP DstIP; // Destination IP address
|
||||
UINT SrcPort; // Source port
|
||||
UINT DstPort; // Destination port
|
||||
FIFO *Data; // Data body
|
||||
};
|
||||
|
||||
// UDP listener socket entry
|
||||
struct UDPLISTENER_SOCK
|
||||
{
|
||||
@ -1411,6 +1421,8 @@ void AddPortToUdpListener(UDPLISTENER *u, UINT port);
|
||||
void DeletePortFromUdpListener(UDPLISTENER *u, UINT port);
|
||||
void DeleteAllPortFromUdpListener(UDPLISTENER *u);
|
||||
void UdpListenerSendPackets(UDPLISTENER *u, LIST *packet_list);
|
||||
TCP_RAW_DATA *NewTcpRawData(IP *src_ip, UINT src_port, IP *dst_ip, UINT dst_port);
|
||||
void FreeTcpRawData(TCP_RAW_DATA *trd);
|
||||
UDPPACKET *NewUdpPacket(IP *src_ip, UINT src_port, IP *dst_ip, UINT dst_port, void *data, UINT size);
|
||||
void FreeUdpPacket(UDPPACKET *p);
|
||||
UDPLISTENER_SOCK *DetermineUdpSocketForSending(UDPLISTENER *u, UDPPACKET *p);
|
||||
|
Reference in New Issue
Block a user