Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/WireGuard-ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WireGuard
private:
bool _is_initialized = false;
public:
bool begin(const IPAddress& localIP, const IPAddress& Subnet, const IPAddress& Gateway, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort);
bool begin(const IPAddress& localIP, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort);
void end();
bool is_initialized() const { return this->_is_initialized; }
Expand Down
13 changes: 10 additions & 3 deletions src/WireGuard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ static uint8_t wireguard_peer_index = WIREGUARDIF_INVALID_INDEX;

#define TAG "[WireGuard] "

bool WireGuard::begin(const IPAddress& localIP, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort) {
bool WireGuard::begin(const IPAddress& localIP, const IPAddress& Subnet, const IPAddress& Gateway, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort) {
struct wireguardif_init_data wg;
struct wireguardif_peer peer;
ip_addr_t ipaddr = IPADDR4_INIT(static_cast<uint32_t>(localIP));
ip_addr_t netmask = IPADDR4_INIT_BYTES(255, 255, 255, 255);
ip_addr_t gateway = IPADDR4_INIT_BYTES(0, 0, 0, 0);
ip_addr_t netmask = IPADDR4_INIT(static_cast<uint32_t>(Subnet));
ip_addr_t gateway = IPADDR4_INIT(static_cast<uint32_t>(Gateway));

assert(privateKey != NULL);
assert(remotePeerAddress != NULL);
Expand Down Expand Up @@ -119,6 +119,13 @@ bool WireGuard::begin(const IPAddress& localIP, const char* privateKey, const ch
return true;
}

bool WireGuard::begin(const IPAddress& localIP, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort) {
// Maintain compatiblity with old begin
auto subnet = IPAddress(255,255,255,255);
auto gateway = IPAddress(0,0,0,0);
return WireGuard::begin(localIP, subnet, gateway, privateKey, remotePeerAddress, remotePeerPublicKey, remotePeerPort);
}

void WireGuard::end() {
if( !this->_is_initialized ) return;

Expand Down