WIP: Set address IPs to Wireguard interface #6

Closed
Sirherobrine23 wants to merge 1 commits from interfaceIP into main
4 changed files with 92 additions and 17 deletions

@ -25,8 +25,8 @@
"includePath": [
"${env:appdata}/../Local/node-gyp/Cache/18.17.0/include/node",
"${workspaceFolder}/node_modules/node-addon-api",
"${workspaceFolder}/addons/genKey/**",
"${workspaceFolder}/addons/tools/**"
"${workspaceFolder}/addons/genKey",
"${workspaceFolder}/addons/tools"
]
},
{
@ -50,8 +50,8 @@
"/usr/include/node",
"${workspaceFolder}/node_modules/node-addon-api/**",
"${workspaceFolder}/node_modules/**",
"${workspaceFolder}/addons/genKey/**",
"${workspaceFolder}/addons/tools/**"
"${workspaceFolder}/addons/genKey",
"${workspaceFolder}/addons/tools"
]
},
{
@ -59,11 +59,12 @@
"includePath": [
"${workspaceFolder}/node_modules/node-addon-api",
"/usr/local/include/node",
"${workspaceFolder}/addons/genKey/**",
"${workspaceFolder}/addons/tools/**"
"${workspaceFolder}/addons/genKey",
"${workspaceFolder}/addons/tools"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
"NAPI_DISABLE_CPP_EXCEPTIONS",
"USERSPACE_GO"
],
"compilerArgs": [
"-fpermissive",

@ -7,6 +7,7 @@
"editor.insertSpaces": true,
"editor.minimap.enabled": false,
"editor.detectIndentation": false,
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 2 }",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
@ -23,8 +24,6 @@
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
},
"files.associations": {
"random": "cpp",
"limits": "cpp",
"xstring": "cpp"
}
"random": "cpp"
},
}

@ -1,13 +1,17 @@
/*
File just to define functions for systems not supported by the addon
*/
#include <napi.h>
#include <wginterface.hh>
#include <wgip.hh>
unsigned long maxName() {
return 16;
}
unsigned long maxName() { return 16; }
std::string versionDrive() {
return "Userspace";
}
std::string versionDrive() { return "Userspace"; }
void WgIP::deploy() {}
void WgIP::load() {}
void listDevices::Execute() {}
void deleteInterface::Execute() {}

71
addons/tools/wgip.hh Normal file

@ -0,0 +1,71 @@
#include <string>
#include <vector>
struct InterfaceIp {
std::string ipAddress;
int mask;
};
/**
* Get and Set Ip address to wireguard interface
*/
class WgIP {
public:
/**
* Interface IPs vector
*/
std::vector<InterfaceIp> InterfaceAddress;
/**
* Set ip address in interface and update local ip vector
*/
void deploy();
/**
* if interface exists get current ip address and insert in interface vector
*/
void load();
/**
* Set ip and mask to interface
*/
bool addIP(std::string ip, int mask) {
if (ip.length() == 0) return false;
if (ip.find("/") != std::string::npos) ip = ip.substr(0, ip.find("/"));
for (auto rIP : InterfaceAddress) {
if (rIP.ipAddress == ip) return false;
}
InterfaceIp nIp;
nIp.ipAddress = ip;
nIp.mask = mask;
InterfaceAddress.push_back(nIp);
return true;
}
/**
* Add ip to Interface vector
*
* if exist ip ignore
*/
bool addIP(std::string ip) {
if (ip.length() == 0) return false;
int mask;
if (ip.find("/") != std::string::npos) {
mask = std::to_integer(ip.substr(ip.find("/")+1));
ip = ip.substr(0, ip.find("/"));
}
for (auto rIP : InterfaceAddress) {
if (rIP.ipAddress == ip) return false;
}
InterfaceIp nIp;
nIp.ipAddress = ip;
nIp.mask = mask;
InterfaceAddress.push_back(nIp);
return true;
}
/**
* Remove ip from interface vector
*/
bool removeIP(std::string ip) { return false; }
};