Skip to content

Commit

Permalink
Merge pull request #17 from ConorShore/AddSubnetAndGateway
Browse files Browse the repository at this point in the history
Added wg subnet and gateway options
  • Loading branch information
ciniml authored May 29, 2022
2 parents a330797 + 4710cdc commit 3048281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit 3048281

Please sign in to comment.