Skip to content

Commit 3048281

Browse files
authored
Merge pull request #17 from ConorShore/AddSubnetAndGateway
Added wg subnet and gateway options
2 parents a330797 + 4710cdc commit 3048281

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: src/WireGuard-ESP32.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class WireGuard
1010
private:
1111
bool _is_initialized = false;
1212
public:
13+
bool begin(const IPAddress& localIP, const IPAddress& Subnet, const IPAddress& Gateway, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort);
1314
bool begin(const IPAddress& localIP, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort);
1415
void end();
1516
bool is_initialized() const { return this->_is_initialized; }

Diff for: src/WireGuard.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ static uint8_t wireguard_peer_index = WIREGUARDIF_INVALID_INDEX;
2929

3030
#define TAG "[WireGuard] "
3131

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

3939
assert(privateKey != NULL);
4040
assert(remotePeerAddress != NULL);
@@ -119,6 +119,13 @@ bool WireGuard::begin(const IPAddress& localIP, const char* privateKey, const ch
119119
return true;
120120
}
121121

122+
bool WireGuard::begin(const IPAddress& localIP, const char* privateKey, const char* remotePeerAddress, const char* remotePeerPublicKey, uint16_t remotePeerPort) {
123+
// Maintain compatiblity with old begin
124+
auto subnet = IPAddress(255,255,255,255);
125+
auto gateway = IPAddress(0,0,0,0);
126+
return WireGuard::begin(localIP, subnet, gateway, privateKey, remotePeerAddress, remotePeerPublicKey, remotePeerPort);
127+
}
128+
122129
void WireGuard::end() {
123130
if( !this->_is_initialized ) return;
124131

0 commit comments

Comments
 (0)