Skip to content

Commit 75b5949

Browse files
committed
Remove unnecessary netif_add_and_up_parameters member.
1 parent 6e7a893 commit 75b5949

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/WireGuard.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@ struct netif_add_and_up_parameters {
2828
const ip4_addr_t *ipaddr;
2929
const ip4_addr_t *netmask;
3030
const ip4_addr_t *gw;
31-
struct netif **wg_netif;
32-
struct netif *wg_netif_struct;
31+
struct netif *wg_netif;
3332
void *state;
3433
};
3534

3635
static esp_err_t netif_add_and_up_in_lwip_ctx(void *ctx) {
3736
netif_add_and_up_parameters *param = static_cast<netif_add_and_up_parameters *>(ctx);
3837

3938
// Register the new WireGuard network interface with lwIP
40-
*param->wg_netif = netif_add(param->wg_netif_struct, param->ipaddr, param->netmask, param->gw, param->state, &wireguardif_init, &ip_input);
41-
if (!param->wg_netif) {
39+
if (netif_add(param->wg_netif, param->ipaddr, param->netmask, param->gw, param->state, &wireguardif_init, &ip_input) == nullptr) {
4240
return ESP_FAIL;
4341
}
4442

4543
// Mark the interface as administratively up, link up flag is set automatically when peer connects
46-
netif_set_up(*param->wg_netif);
44+
netif_set_up(param->wg_netif);
4745

4846
return ESP_OK;
4947
}
@@ -142,15 +140,15 @@ bool WireGuard::begin(const IPAddress& localIP,
142140
ip_2_ip4(&ipaddr),
143141
ip_2_ip4(&netmask),
144142
ip_2_ip4(&gateway),
145-
&wg_netif,
146-
&wg_netif_struct,
143+
this->wg_netif,
147144
&wg,
148145
};
149-
esp_netif_tcpip_exec(netif_add_and_up_in_lwip_ctx, &params);
150-
if( wg_netif == nullptr ) {
146+
esp_err_t err = esp_netif_tcpip_exec(netif_add_and_up_in_lwip_ctx, &params);
147+
if (err != ESP_OK) {
151148
log_e(TAG "failed to initialize WG netif.");
152149
return false;
153150
}
151+
this->wg_netif = &this->wg_netif_struct;
154152

155153
peer.public_key = remotePeerPublicKey;
156154
peer.preshared_key = preshared_key;

0 commit comments

Comments
 (0)