@@ -28,22 +28,20 @@ struct netif_add_and_up_parameters {
28
28
const ip4_addr_t *ipaddr;
29
29
const ip4_addr_t *netmask;
30
30
const ip4_addr_t *gw;
31
- struct netif **wg_netif;
32
- struct netif *wg_netif_struct;
31
+ struct netif *wg_netif;
33
32
void *state;
34
33
};
35
34
36
35
static esp_err_t netif_add_and_up_in_lwip_ctx (void *ctx) {
37
36
netif_add_and_up_parameters *param = static_cast <netif_add_and_up_parameters *>(ctx);
38
37
39
38
// 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 ) {
42
40
return ESP_FAIL;
43
41
}
44
42
45
43
// 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 );
47
45
48
46
return ESP_OK;
49
47
}
@@ -142,15 +140,15 @@ bool WireGuard::begin(const IPAddress& localIP,
142
140
ip_2_ip4 (&ipaddr),
143
141
ip_2_ip4 (&netmask),
144
142
ip_2_ip4 (&gateway),
145
- &wg_netif,
146
- &wg_netif_struct,
143
+ this ->wg_netif ,
147
144
&wg,
148
145
};
149
- esp_netif_tcpip_exec (netif_add_and_up_in_lwip_ctx, ¶ms);
150
- if ( wg_netif == nullptr ) {
146
+ esp_err_t err = esp_netif_tcpip_exec (netif_add_and_up_in_lwip_ctx, ¶ms);
147
+ if (err != ESP_OK ) {
151
148
log_e (TAG " failed to initialize WG netif." );
152
149
return false ;
153
150
}
151
+ this ->wg_netif = &this ->wg_netif_struct ;
154
152
155
153
peer.public_key = remotePeerPublicKey;
156
154
peer.preshared_key = preshared_key;
0 commit comments