This commit is contained in:
2025-11-13 15:12:00 +01:00
parent 5c8409b312
commit c85f622a60
7 changed files with 19 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ namespace ColumnLynx::Net::TCP {
std::array<uint8_t, 32>* aesKey, std::array<uint8_t, 32>* aesKey,
uint64_t* sessionIDRef, uint64_t* sessionIDRef,
bool* insecureMode, bool* insecureMode,
VirtualInterface* tun = nullptr) std::shared_ptr<VirtualInterface> tun = nullptr)
: :
mResolver(ioContext), mResolver(ioContext),
mSocket(ioContext), mSocket(ioContext),
@@ -74,6 +74,6 @@ namespace ColumnLynx::Net::TCP {
int mMissedHeartbeats = 0; int mMissedHeartbeats = 0;
bool mIsHostDomain; bool mIsHostDomain;
Protocol::TunConfig mTunConfig; Protocol::TunConfig mTunConfig;
VirtualInterface* mTun = nullptr; std::shared_ptr<VirtualInterface> mTun = nullptr;
}; };
} }

View File

@@ -19,7 +19,7 @@ namespace ColumnLynx::Net::UDP {
const std::string& port, const std::string& port,
std::array<uint8_t, 32>* aesKeyRef, std::array<uint8_t, 32>* aesKeyRef,
uint64_t* sessionIDRef, uint64_t* sessionIDRef,
VirtualInterface* tunRef = nullptr) std::shared_ptr<VirtualInterface> tunRef = nullptr)
: mSocket(ioContext), mResolver(ioContext), mHost(host), mPort(port), mAesKeyRef(aesKeyRef), mSessionIDRef(sessionIDRef), mTunRef(tunRef) { mStartReceive(); } : mSocket(ioContext), mResolver(ioContext), mHost(host), mPort(port), mAesKeyRef(aesKeyRef), mSessionIDRef(sessionIDRef), mTunRef(tunRef) { mStartReceive(); }
void start(); void start();
@@ -37,7 +37,7 @@ namespace ColumnLynx::Net::UDP {
std::string mPort; std::string mPort;
std::array<uint8_t, 32>* mAesKeyRef; std::array<uint8_t, 32>* mAesKeyRef;
uint64_t* mSessionIDRef; uint64_t* mSessionIDRef;
VirtualInterface* mTunRef; std::shared_ptr<VirtualInterface> mTunRef = nullptr;
std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed
}; };
} }

View File

@@ -13,7 +13,7 @@
namespace ColumnLynx::Net::UDP { namespace ColumnLynx::Net::UDP {
class UDPServer { class UDPServer {
public: public:
UDPServer(asio::io_context& ioContext, uint16_t port, bool* hostRunning, bool ipv4Only = false, VirtualInterface* tun = nullptr) UDPServer(asio::io_context& ioContext, uint16_t port, bool* hostRunning, bool ipv4Only = false, std::shared_ptr<VirtualInterface> tun = nullptr)
: mSocket(ioContext), mHostRunning(hostRunning), mTun(tun) : mSocket(ioContext), mHostRunning(hostRunning), mTun(tun)
{ {
asio::error_code ec; asio::error_code ec;
@@ -53,6 +53,6 @@ namespace ColumnLynx::Net::UDP {
asio::ip::udp::endpoint mRemoteEndpoint; asio::ip::udp::endpoint mRemoteEndpoint;
std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed
bool* mHostRunning; bool* mHostRunning;
VirtualInterface* mTun; std::shared_ptr<VirtualInterface> mTun;
}; };
} }

1
panic_dump.txt Normal file
View File

@@ -0,0 +1 @@
=

View File

@@ -63,8 +63,8 @@ int main(int argc, char** argv) {
WintunInitialize(); WintunInitialize();
#endif #endif
VirtualInterface tun("utun1"); std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun0");
log("Using virtual interface: " + tun.getName()); log("Using virtual interface: " + tun->getName());
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper(); LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
@@ -72,8 +72,8 @@ int main(int argc, char** argv) {
uint64_t sessionID = 0; uint64_t sessionID = 0;
asio::io_context io; asio::io_context io;
auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, &sodiumWrapper, &aesKey, &sessionID, &insecureMode, &tun); auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, &sodiumWrapper, &aesKey, &sessionID, &insecureMode, tun);
auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, &aesKey, &sessionID, &tun); auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, &aesKey, &sessionID, tun);
client->start(); client->start();
udpClient->start(); udpClient->start();
@@ -89,7 +89,7 @@ int main(int argc, char** argv) {
// Client is running // Client is running
// TODO: SIGINT or SIGTERM seems to not kill this instantly! // TODO: SIGINT or SIGTERM seems to not kill this instantly!
while ((client->isConnected() || !client->isHandshakeComplete()) && !done) { while ((client->isConnected() || !client->isHandshakeComplete()) && !done) {
auto packet = tun.readPacket(); auto packet = tun->readPacket();
Nonce nonce{}; Nonce nonce{};
randombytes_buf(nonce.data(), nonce.size()); randombytes_buf(nonce.data(), nonce.size());

View File

@@ -61,8 +61,8 @@ int main(int argc, char** argv) {
WintunInitialize(); WintunInitialize();
#endif #endif
VirtualInterface tun("utun0"); std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun0");
log("Using virtual interface: " + tun.getName()); log("Using virtual interface: " + tun->getName());
// Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory) // Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory)
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper(); LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
@@ -74,7 +74,7 @@ int main(int argc, char** argv) {
asio::io_context io; asio::io_context io;
auto server = std::make_shared<TCPServer>(io, serverPort(), &sodiumWrapper, &hostRunning, ipv4Only); auto server = std::make_shared<TCPServer>(io, serverPort(), &sodiumWrapper, &hostRunning, ipv4Only);
auto udpServer = std::make_shared<UDPServer>(io, serverPort(), &hostRunning, ipv4Only, &tun); auto udpServer = std::make_shared<UDPServer>(io, serverPort(), &hostRunning, ipv4Only, tun);
asio::signal_set signals(io, SIGINT, SIGTERM); asio::signal_set signals(io, SIGINT, SIGTERM);
signals.async_wait([&](const std::error_code&, int) { signals.async_wait([&](const std::error_code&, int) {
@@ -84,6 +84,8 @@ int main(int argc, char** argv) {
hostRunning = false; hostRunning = false;
server->stop(); server->stop();
udpServer->stop(); udpServer->stop();
tun.reset();
tun = nullptr;
}); });
}); });
@@ -97,7 +99,7 @@ int main(int argc, char** argv) {
log("Server started on port " + std::to_string(serverPort())); log("Server started on port " + std::to_string(serverPort()));
while (!done) { while (!done) {
auto packet = tun.readPacket(); auto packet = tun->readPacket();
if (packet.empty()) { if (packet.empty()) {
continue; continue;
} }

View File

@@ -62,6 +62,7 @@ namespace ColumnLynx::Net::UDP {
// For now, just log the decrypted payload // For now, just log the decrypted payload
std::string payloadStr(plaintext.begin(), plaintext.end()); std::string payloadStr(plaintext.begin(), plaintext.end());
Utils::log("UDP: Received packet from " + mRemoteEndpoint.address().to_string() + " - Payload: " + payloadStr); Utils::log("UDP: Received packet from " + mRemoteEndpoint.address().to_string() + " - Payload: " + payloadStr);
if (mTun) { if (mTun) {
mTun->writePacket(plaintext); // Send to virtual interface mTun->writePacket(plaintext); // Send to virtual interface
} }