1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Cedar/Proto: add ProtoLog(), write message to log on session creation/deletion

Example:

[OpenVPN] 192.168.122.100:47390 -> 0.0.0.0:1194 (UDP): Session created.
[OpenVPN] 192.168.122.100:47390 -> 0.0.0.0:1194 (UDP): Session deleted.

[OpenVPN] 192.168.122.100:49866 -> 192.168.122.1:1194 (TCP): Session created.
[OpenVPN] 192.168.122.100:49866 -> 192.168.122.1:1194 (TCP): Session deleted.
This commit is contained in:
Davide Beatrici 2020-08-06 03:23:55 +02:00
parent a8c6a0c1b3
commit cda0062367
9 changed files with 100 additions and 1 deletions

View File

@ -2,6 +2,46 @@
#include "Proto_OpenVPN.h" #include "Proto_OpenVPN.h"
void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...)
{
wchar_t message[MAX_SIZE * 2];
if (proto == NULL)
{
return;
}
if (session != NULL)
{
wchar_t *proto_name;
UINT current_len;
va_list args;
proto_name = CopyStrToUni(session->Impl->Name());
UniFormat(message, sizeof(message), _UU("LP_PREFIX_SESSION"), proto_name, &session->SrcIp, session->SrcPort, &session->DstIp, session->DstPort, L"UDP");
Free(proto_name);
current_len = UniStrLen(message);
va_start(args, name);
UniFormatArgs(message + current_len, sizeof(message) - current_len, _UU(name), args);
va_end(args);
}
else
{
va_list args;
UniStrCpy(message, sizeof(message), _UU("LP_PREFIX_SESSION"));
UniStrCat(message, sizeof(message), _UU(name));
va_start(args, name);
UniFormatArgs(message, sizeof(message), message, args);
va_end(args);
}
WriteServerLog(proto->Cedar, message);
}
int ProtoOptionCompare(void *p1, void *p2) int ProtoOptionCompare(void *p1, void *p2)
{ {
PROTO_OPTION *option_1, *option_2; PROTO_OPTION *option_1, *option_2;
@ -373,6 +413,8 @@ PROTO_SESSION *ProtoSessionNew(const PROTO *proto, const PROTO_CONTAINER *contai
session->Lock = NewLock(); session->Lock = NewLock();
session->Thread = NewThread(ProtoSessionThread, session); session->Thread = NewThread(ProtoSessionThread, session);
ProtoLog(proto, session, "LP_SESSION_CREATED");
return session; return session;
} }
@ -399,6 +441,8 @@ void ProtoSessionDelete(PROTO_SESSION *session)
DeleteLock(session->Lock); DeleteLock(session->Lock);
ProtoLog(session->Proto, session, "LP_SESSION_DELETED");
Free(session); Free(session);
} }
@ -455,6 +499,7 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol)
{ {
const PROTO_CONTAINER *container = NULL; const PROTO_CONTAINER *container = NULL;
wchar_t *proto_name;
LIST *options; LIST *options;
if (protocol != NULL) if (protocol != NULL)
@ -507,6 +552,10 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol)
} }
UnlockList(options); UnlockList(options);
proto_name = CopyStrToUni(container->Name);
ProtoLog(proto, NULL, "LP_SESSION_CREATED", proto_name, &sock->RemoteIP, sock->RemotePort, &sock->LocalIP, sock->LocalPort, L"TCP");
Free(proto_name);
} }
SetTimeout(sock, TIMEOUT_INFINITE); SetTimeout(sock, TIMEOUT_INFINITE);
@ -596,6 +645,12 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol)
ReleaseFifo(send_fifo); ReleaseFifo(send_fifo);
Free(buf); Free(buf);
{
wchar_t *proto_name = CopyStrToUni(impl->Name());
ProtoLog(proto, NULL, "LP_SESSION_DELETED", proto_name, &sock->RemoteIP, sock->RemotePort, &sock->LocalIP, sock->LocalPort, L"TCP");
Free(proto_name);
}
return true; return true;
} }

View File

@ -78,6 +78,8 @@ typedef struct PROTO_SESSION
volatile bool Halt; volatile bool Halt;
} PROTO_SESSION; } PROTO_SESSION;
void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...);
int ProtoOptionCompare(void *p1, void *p2); int ProtoOptionCompare(void *p1, void *p2);
int ProtoContainerCompare(void *p1, void *p2); int ProtoContainerCompare(void *p1, void *p2);
int ProtoSessionCompare(void *p1, void *p2); int ProtoSessionCompare(void *p1, void *p2);

View File

@ -1810,6 +1810,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (Proto log)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN Logs) # (OpenVPN Logs)
LO_PREFIX_RAW OpenVPN 模块: LO_PREFIX_RAW OpenVPN 模块:
LO_PREFIX_SESSION OpenVPN 会话%u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN 会话%u (%r:%u -> %r:%u):

View File

@ -1792,6 +1792,13 @@ LS_API_AUTH_OK HTTPS API client "%r:%u" (%S): Administration mode: "%S": The e
LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server refused a login attempt. Username: "%S", Method: "%S", Path: "%S" LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server refused a login attempt. Username: "%S", Method: "%S", Path: "%S"
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (Proto log)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN Logs) # (OpenVPN Logs)
LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_RAW OpenVPN Module:
LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u):

View File

@ -1796,6 +1796,11 @@ LS_API_AUTH_OK HTTPS API クライアント "%r:%u" (%S): 管理モード: "%S
LS_API_AUTH_ERROR HTTPS API クライアント "%r:%u" (%S): 組み込み HTTPS Web サーバーを用いてログインに失敗しました。使用されたユーザー名: "%S", メソッド: "%S", パス: "%S" LS_API_AUTH_ERROR HTTPS API クライアント "%r:%u" (%S): 組み込み HTTPS Web サーバーを用いてログインに失敗しました。使用されたユーザー名: "%S", メソッド: "%S", パス: "%S"
LS_API_RPC_CALL HTTPS API クライアント "%r:%u" (%S): JSON-API を呼び出しました。メソッド名: "%S", 結果エラーコード: %u (0 = 成功), 結果エラーメッセージ: "%s" LS_API_RPC_CALL HTTPS API クライアント "%r:%u" (%S): JSON-API を呼び出しました。メソッド名: "%S", 結果エラーコード: %u (0 = 成功), 結果エラーメッセージ: "%s"
# (Proto ログ)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN ログ) # (OpenVPN ログ)
LO_PREFIX_RAW OpenVPN モジュール: LO_PREFIX_RAW OpenVPN モジュール:
LO_PREFIX_SESSION OpenVPN セッション %u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN セッション %u (%r:%u -> %r:%u):

View File

@ -1778,6 +1778,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (Proto 로그)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN 로그) # (OpenVPN 로그)
LO_PREFIX_RAW OpenVPN 모듈: LO_PREFIX_RAW OpenVPN 모듈:
LO_PREFIX_SESSION OpenVPN 세션 %u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN 세션 %u (%r:%u -> %r:%u):

View File

@ -1793,6 +1793,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server r
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (Proto log)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN Logs) # (OpenVPN Logs)
LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_RAW OpenVPN Module:
LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u):

View File

@ -1793,6 +1793,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (Proto log)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN Logs) # (OpenVPN Logs)
LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_RAW OpenVPN Module:
LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u):

View File

@ -1813,7 +1813,13 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server
LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s"
# (OpenVPN Logs) # (Proto 日誌)
LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s):
LP_SESSION_CREATED Session created.
LP_SESSION_DELETED Session deleted.
# (OpenVPN 日誌)
LO_PREFIX_RAW OpenVPN 模組: LO_PREFIX_RAW OpenVPN 模組:
LO_PREFIX_SESSION OpenVPN 會話%u (%r:%u -> %r:%u): LO_PREFIX_SESSION OpenVPN 會話%u (%r:%u -> %r:%u):
LO_PREFIX_CHANNEL OpenVPN 會話%u (%r:%u -> %r:%u) 通道 %u: LO_PREFIX_CHANNEL OpenVPN 會話%u (%r:%u -> %r:%u) 通道 %u: