Skip to content

Commit

Permalink
Update to provide better support to sustained intensive network usage…
Browse files Browse the repository at this point in the history
…s (Such as FiveM..)
  • Loading branch information
wow committed Jan 8, 2022
1 parent 0029b3f commit 4f5ff65
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 222 deletions.
8 changes: 5 additions & 3 deletions GRE.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "GRE.h"

#define RecvBufSize 32768

[[noreturn]] void GRE::receiver(HMODULE wintun) {
InitializeWintun(wintun); // Required due to being initialized in another file and wintun won't provide any .lib

sockaddr_in SenderAddr{};
int SenderAddrSize = sizeof(SenderAddr);

char RecvBuf[8192];
int BufLen = 8192;
char RecvBuf[RecvBufSize];
int BufLen = RecvBufSize;
int rBufLen;
el::Logger* defaultLogger = el::Loggers::getLogger("default");

Expand Down Expand Up @@ -76,7 +78,7 @@
Session = WintunStartSession(Adapter, WINTUN_MAX_RING_CAPACITY / 2);

if (!Session) {
WintunFreeAdapter(Adapter);
WintunCloseAdapter(Adapter);
LOG(FATAL) << "Could not create session";
}
LOG(INFO) << "Successfully restarted WinTun Session.";
Expand Down
2 changes: 1 addition & 1 deletion GRE.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define IPPROTO_GRE 47
#define GRE_SIZE 4
#define SEND_BUFFER 16384
#define SEND_BUFFER 32768
extern bool reset_adapter;
extern WINTUN_SESSION_HANDLE Session;
extern WINTUN_ADAPTER_HANDLE Adapter;
Expand Down
30 changes: 8 additions & 22 deletions GRETunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <WS2tcpip.h>
#include <thread>
#include <filesystem>
#include "include/wintun.h"

#include "wintun_helper.h"
#include "GRE.h"
Expand Down Expand Up @@ -37,18 +38,6 @@ INITIALIZE_EASYLOGGINGPP
int main(int argc, char* argv[])
{
std::cout << "GRE Tunnel for Windows" << std::endl << std::endl;
if (strcmp(argv[1], "reset") == 0)
{
HMODULE MWintun = wt_LoadModule();
if (!InitializeWintun(MWintun)) {
std::cerr << "Failed to initialize WinTun: " << GetLastError() << std::endl <<
"Please make sure that wintun.dll exists" << std::endl;
return 0;
}
std::cout << "Reseting adapters" << std::endl;
WintunEnumAdapters(L"GRE_Tun", delete_callback, NULL);
return 0;
}
if (argc < 5 || argc > 7) {
std::cerr << "At least 2 arguments must be given" << std::endl <<
"Arguments: gre_tunnel.exe GRE_BIND_IP GRE_SERVER INTERFACE_IP GATEWAY_IP [CIDR (30)] [ADAPTER_NAME]" << std::endl;
Expand Down Expand Up @@ -104,13 +93,10 @@ int main(int argc, char* argv[])
return 0;
}

Adapter = WintunOpenAdapter(L"GRE_Tun", adapter_name);
Adapter = WintunCreateAdapter(L"GRE_Tunnel", adapter_name, NULL);
if (!Adapter) {
Adapter = WintunCreateAdapter(L"GRE_Tun", adapter_name, NULL, FALSE);
if (!Adapter) {
LOG(FATAL) << "Failed to create Wintun adapter: " << GetLastError();
return 0;
}
LOG(FATAL) << "Failed to create Wintun adapter: " << GetLastError();
return 0;
}

SetConsoleCtrlHandler(exit_handler, TRUE);
Expand All @@ -121,22 +107,22 @@ int main(int argc, char* argv[])
AddressRow.Address.Ipv4.sin_family = AF_INET;
inet_pton(AF_INET, bind_ip, &AddressRow.Address.Ipv4.sin_addr.S_un.S_addr);

AddressRow.OnLinkPrefixLength = 30;
AddressRow.OnLinkPrefixLength = cidr;
AddressRow.DadState = IpDadStatePreferred;
auto LastError = CreateUnicastIpAddressEntry(&AddressRow);

if (LastError != ERROR_SUCCESS && LastError != ERROR_OBJECT_ALREADY_EXISTS)
{
LOG(FATAL) << "Failed to assign IP: " << LastError;
WintunFreeAdapter(Adapter);
WintunCloseAdapter(Adapter);
return 0;
}

Session = WintunStartSession(Adapter, WINTUN_MAX_RING_CAPACITY / 2);
Session = WintunStartSession(Adapter, WINTUN_MAX_RING_CAPACITY);
if (!Session)
{
LOG(FATAL) << "Failed to create adapter";
WintunFreeAdapter(Adapter);
WintunCloseAdapter(Adapter);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion GRETunnel.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>wintun\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
Expand Down
2 changes: 1 addition & 1 deletion GRETunnel.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="wintun.h">
<Filter>Fichiers sources</Filter>
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 4f5ff65

Please sign in to comment.