mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-06 07:44:57 +03:00
merge upstream v4.19-9582-beta
This commit is contained in:
@ -423,6 +423,7 @@ typedef struct STRMAP_ENTRY STRMAP_ENTRY;
|
||||
typedef struct SHARED_BUFFER SHARED_BUFFER;
|
||||
typedef struct HASH_LIST HASH_LIST;
|
||||
typedef struct HASH_ENTRY HASH_ENTRY;
|
||||
typedef struct PRAND PRAND;
|
||||
|
||||
// Str.h
|
||||
typedef struct TOKEN_LIST TOKEN_LIST;
|
||||
|
@ -134,6 +134,70 @@
|
||||
|
||||
static UINT fifo_current_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
|
||||
|
||||
// New PRand
|
||||
PRAND *NewPRand(void *key, UINT key_size)
|
||||
{
|
||||
PRAND *r;
|
||||
UCHAR dummy[256];
|
||||
if (key == NULL || key_size == 0)
|
||||
{
|
||||
key = "DUMMY";
|
||||
key_size = 5;
|
||||
}
|
||||
|
||||
r = ZeroMalloc(sizeof(PRAND));
|
||||
|
||||
HashSha1(r->Key, key, key_size);
|
||||
|
||||
r->Rc4 = NewCrypt(key, key_size);
|
||||
|
||||
Zero(dummy, sizeof(dummy));
|
||||
|
||||
Encrypt(r->Rc4, dummy, dummy, 256);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// Free PRand
|
||||
void FreePRand(PRAND *r)
|
||||
{
|
||||
if (r == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FreeCrypt(r->Rc4);
|
||||
|
||||
Free(r);
|
||||
}
|
||||
|
||||
// Generate PRand
|
||||
void PRand(PRAND *p, void *data, UINT size)
|
||||
{
|
||||
if (p == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Zero(data, size);
|
||||
|
||||
Encrypt(p->Rc4, data, data, size);
|
||||
}
|
||||
|
||||
// Generate UINT PRand
|
||||
UINT PRandInt(PRAND *p)
|
||||
{
|
||||
UINT r;
|
||||
if (p == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRand(p, &r, sizeof(UINT));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// Check whether the specified key item is in the hash list
|
||||
bool IsInHashListKey(HASH_LIST *h, UINT key)
|
||||
{
|
||||
@ -2368,6 +2432,28 @@ UINT PeekFifo(FIFO *f, void *p, UINT size)
|
||||
return read_size;
|
||||
}
|
||||
|
||||
// Read all data from FIFO
|
||||
BUF *ReadFifoAll(FIFO *f)
|
||||
{
|
||||
BUF *buf;
|
||||
UCHAR *tmp;
|
||||
UINT size;
|
||||
if (f == NULL)
|
||||
{
|
||||
return NewBuf();
|
||||
}
|
||||
|
||||
size = FifoSize(f);
|
||||
tmp = Malloc(size);
|
||||
ReadFifo(f, tmp, size);
|
||||
|
||||
buf = MemToBuf(tmp, size);
|
||||
|
||||
Free(tmp);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Read from the FIFO
|
||||
UINT ReadFifo(FIFO *f, void *p, UINT size)
|
||||
{
|
||||
@ -3128,6 +3214,21 @@ bool WriteBufInt(BUF *b, UINT value)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Write a short integer in the the buffer
|
||||
bool WriteBufShort(BUF *b, USHORT value)
|
||||
{
|
||||
// Validate arguments
|
||||
if (b == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = Endian16(value);
|
||||
|
||||
WriteBuf(b, &value, sizeof(USHORT));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Write a UCHAR to the buffer
|
||||
bool WriteBufChar(BUF *b, UCHAR uc)
|
||||
{
|
||||
@ -3194,6 +3295,23 @@ UINT ReadBufInt(BUF *b)
|
||||
return Endian32(value);
|
||||
}
|
||||
|
||||
// Read a short integer from the buffer
|
||||
USHORT ReadBufShort(BUF *b)
|
||||
{
|
||||
USHORT value;
|
||||
// Validate arguments
|
||||
if (b == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ReadBuf(b, &value, sizeof(USHORT)) != sizeof(USHORT))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Endian16(value);
|
||||
}
|
||||
|
||||
// Write the buffer to a buffer
|
||||
void WriteBufBuf(BUF *b, BUF *bb)
|
||||
{
|
||||
@ -3459,6 +3577,23 @@ BUF *ReadRemainBuf(BUF *b)
|
||||
return ReadBufFromBuf(b, size);
|
||||
}
|
||||
|
||||
// Get the length of the rest
|
||||
UINT ReadBufRemainSize(BUF *b)
|
||||
{
|
||||
// Validate arguments
|
||||
if (b == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (b->Size < b->Current)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return b->Size - b->Current;
|
||||
}
|
||||
|
||||
// Clone the buffer
|
||||
BUF *CloneBuf(BUF *b)
|
||||
{
|
||||
|
@ -236,6 +236,13 @@ struct HASH_LIST
|
||||
LIST *AllList;
|
||||
};
|
||||
|
||||
// PRAND
|
||||
struct PRAND
|
||||
{
|
||||
UCHAR Key[20];
|
||||
CRYPT *Rc4;
|
||||
};
|
||||
|
||||
// Function prototype
|
||||
HASH_LIST *NewHashList(GET_HASH *get_hash_proc, COMPARE *compare_proc, UINT bits, bool make_list);
|
||||
void ReleaseHashList(HASH_LIST *h);
|
||||
@ -250,6 +257,11 @@ void UnlockHashList(HASH_LIST *h);
|
||||
bool IsInHashListKey(HASH_LIST *h, UINT key);
|
||||
void *HashListKeyToPointer(HASH_LIST *h, UINT key);
|
||||
|
||||
PRAND *NewPRand(void *key, UINT key_size);
|
||||
void FreePRand(PRAND *r);
|
||||
void PRand(PRAND *p, void *data, UINT size);
|
||||
UINT PRandInt(PRAND *p);
|
||||
|
||||
LIST *NewCandidateList();
|
||||
void FreeCandidateList(LIST *o);
|
||||
int ComapreCandidate(void *p1, void *p2);
|
||||
@ -310,11 +322,13 @@ void FreeBuf(BUF *b);
|
||||
bool BufToFile(IO *o, BUF *b);
|
||||
BUF *FileToBuf(IO *o);
|
||||
UINT ReadBufInt(BUF *b);
|
||||
USHORT ReadBufShort(BUF *b);
|
||||
UINT64 ReadBufInt64(BUF *b);
|
||||
UCHAR ReadBufChar(BUF *b);
|
||||
bool WriteBufInt(BUF *b, UINT value);
|
||||
bool WriteBufInt64(BUF *b, UINT64 value);
|
||||
bool WriteBufChar(BUF *b, UCHAR uc);
|
||||
bool WriteBufShort(BUF *b, USHORT value);
|
||||
bool ReadBufStr(BUF *b, char *str, UINT size);
|
||||
bool WriteBufStr(BUF *b, char *str);
|
||||
void WriteBufLine(BUF *b, char *str);
|
||||
@ -332,10 +346,12 @@ BUF *CloneBuf(BUF *b);
|
||||
BUF *MemToBuf(void *data, UINT size);
|
||||
BUF *RandBuf(UINT size);
|
||||
BUF *ReadRemainBuf(BUF *b);
|
||||
UINT ReadBufRemainSize(BUF *b);
|
||||
bool CompareBuf(BUF *b1, BUF *b2);
|
||||
|
||||
UINT PeekFifo(FIFO *f, void *p, UINT size);
|
||||
UINT ReadFifo(FIFO *f, void *p, UINT size);
|
||||
BUF *ReadFifoAll(FIFO *f);
|
||||
void ShrinkFifoMemory(FIFO *f);
|
||||
UCHAR *GetFifoPointer(FIFO *f);
|
||||
UCHAR *FifoPtr(FIFO *f);
|
||||
|
@ -5842,6 +5842,11 @@ SSL_PIPE *NewSslPipe(bool server_mode, X *x, K *k, DH_CTX *dh)
|
||||
SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
|
||||
}
|
||||
|
||||
if (server_mode == false)
|
||||
{
|
||||
SSL_CTX_set_options(ssl_ctx, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
|
||||
}
|
||||
|
||||
ssl = SSL_new(ssl_ctx);
|
||||
}
|
||||
Unlock(openssl_lock);
|
||||
@ -8907,10 +8912,36 @@ void UnixSelect(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2)
|
||||
if (c1 != NULL)
|
||||
{
|
||||
reads[num_read++] = p1 = c1->pipe_read;
|
||||
|
||||
if (c1->SpecialFlag)
|
||||
{
|
||||
if (c1->pipe_special_read2 != -1 && c1->pipe_special_read2 != 0)
|
||||
{
|
||||
reads[num_read++] = c1->pipe_special_read2;
|
||||
}
|
||||
|
||||
if (c1->pipe_special_read3 != -1 && c1->pipe_special_read3 != 0)
|
||||
{
|
||||
reads[num_read++] = c1->pipe_special_read3;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c2 != NULL)
|
||||
{
|
||||
reads[num_read++] = p2 = c2->pipe_read;
|
||||
|
||||
if (c2->SpecialFlag)
|
||||
{
|
||||
if (c2->pipe_special_read2 != -1 && c2->pipe_special_read2 != 0)
|
||||
{
|
||||
reads[num_read++] = c2->pipe_special_read2;
|
||||
}
|
||||
|
||||
if (c2->pipe_special_read3 != -1 && c2->pipe_special_read3 != 0)
|
||||
{
|
||||
reads[num_read++] = c2->pipe_special_read3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call the select
|
||||
@ -8991,6 +9022,8 @@ CANCEL *UnixNewCancel()
|
||||
|
||||
UnixNewPipe(&c->pipe_read, &c->pipe_write);
|
||||
|
||||
c->pipe_special_read2 = c->pipe_special_read3 = -1;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -12307,6 +12340,36 @@ SOCK *NewUDPEx2RandMachineAndExePath(bool ipv6, IP *ip, UINT num_retry, UCHAR ra
|
||||
return NewUDPEx2Rand(ipv6, ip, hash, sizeof(hash), num_retry);
|
||||
}
|
||||
|
||||
// Set the DF bit of the socket
|
||||
void ClearSockDfBit(SOCK *s)
|
||||
{
|
||||
#ifdef IP_PMTUDISC_DONT
|
||||
#ifdef IP_MTU_DISCOVER
|
||||
UINT value = IP_PMTUDISC_DONT;
|
||||
if (s == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setsockopt(s->socket, IPPROTO_IP, IP_MTU_DISCOVER, (char *)&value, sizeof(value));
|
||||
#endif // IP_MTU_DISCOVER
|
||||
#endif // IP_PMTUDISC_DONT
|
||||
}
|
||||
|
||||
// Set the header-include option
|
||||
void SetRawSockHeaderIncludeOption(SOCK *s, bool enable)
|
||||
{
|
||||
UINT value = BOOL_TO_INT(enable);
|
||||
if (s == NULL || s->IsRawSocket == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setsockopt(s->socket, IPPROTO_IP, IP_HDRINCL, (char *)&value, sizeof(value));
|
||||
|
||||
s->RawIP_HeaderIncludeFlag = enable;
|
||||
}
|
||||
|
||||
// Create and initialize the UDP socket
|
||||
// If port is specified as 0, system assigns a certain port.
|
||||
SOCK *NewUDP(UINT port)
|
||||
|
@ -313,6 +313,7 @@ struct SOCK
|
||||
UINT Reverse_MyServerPort; // Self port number when using the reverse socket
|
||||
UCHAR Ssl_Init_Async_SendAlert[2]; // Initial state of SSL send_alert
|
||||
bool AcceptOnlyTls; // Accept only TLS (disable SSLv3)
|
||||
bool RawIP_HeaderIncludeFlag;
|
||||
|
||||
#ifdef ENABLE_SSL_LOGGING
|
||||
// SSL Logging (for debug)
|
||||
@ -371,6 +372,7 @@ struct CANCEL
|
||||
void *hEvent; // Pointer to a Win32 event handle
|
||||
#else // OS_WIN32
|
||||
int pipe_read, pipe_write; // Pipe
|
||||
int pipe_special_read2, pipe_special_read3;
|
||||
#endif // OS_WIN32
|
||||
};
|
||||
|
||||
@ -1323,6 +1325,8 @@ SOCK *NewUDP4(UINT port, IP *ip);
|
||||
SOCK *NewUDP6(UINT port, IP *ip);
|
||||
SOCK *NewUDPEx2Rand(bool ipv6, IP *ip, void *rand_seed, UINT rand_seed_size, UINT num_retry);
|
||||
SOCK *NewUDPEx2RandMachineAndExePath(bool ipv6, IP *ip, UINT num_retry, UCHAR rand_port_id);
|
||||
void ClearSockDfBit(SOCK *s);
|
||||
void SetRawSockHeaderIncludeOption(SOCK *s, bool enable);
|
||||
UINT GetNewAvailableUdpPortRand();
|
||||
UINT NewRandPortByMachineAndExePath(UINT start_port, UINT end_port, UINT additional_int);
|
||||
void DisableUDPChecksum(SOCK *s);
|
||||
|
@ -2874,6 +2874,7 @@ bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size)
|
||||
{
|
||||
// Quit analysing since this is fragmented
|
||||
p->TypeL4 = L4_FRAGMENT;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -158,13 +158,14 @@ UINT64 Tick64ToTime64(UINT64 tick)
|
||||
}
|
||||
LockList(tk64->AdjustTime);
|
||||
{
|
||||
UINT i;
|
||||
for (i = 0;i < LIST_NUM(tk64->AdjustTime);i++)
|
||||
INT i;
|
||||
for (i = ((INT)LIST_NUM(tk64->AdjustTime) - 1); i >= 0; i--)
|
||||
{
|
||||
ADJUST_TIME *t = LIST_DATA(tk64->AdjustTime, i);
|
||||
if (t->Tick <= tick)
|
||||
{
|
||||
ret = t->Time + (tick - t->Tick);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@
|
||||
#define TICK64_H
|
||||
|
||||
// Maximum number of correction list entries
|
||||
#define MAX_ADJUST_TIME 5000
|
||||
#define MAX_ADJUST_TIME 1024
|
||||
|
||||
// Correction list entry
|
||||
struct ADJUST_TIME
|
||||
|
Reference in New Issue
Block a user