8000 Protect againt calling LWIP_Ethernet::begin twice (#2158) · MaikHo/arduino-pico@016bf80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 016bf80

Browse files
Protect againt calling LWIP_Ethernet::begin twice (earlephilhower#2158)
As seen in debug of earlephilhower#2149, if the LwipIntfDev is already _started, return false for a ::begin() call. Also, protect netif_add/_remove on the very small possibilty of being called by LwipIntfDev devices while the CYW43 driver is doing work.
1 parent d850de1 commit 016bf80

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cores/rp2040/lwip_wrap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,16 @@ extern "C" {
358358
__real_raw_remove(pcb);
359359
}
360360

361+
extern struct netif *__real_netif_add(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input);
362+
struct netif *__wrap_netif_add(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input) {
363+
LWIPMutex m;
364+
return __real_netif_add(netif, ipaddr, netmask, gw, state, init, input);
365+
}
366+
367+
extern void __real_netif_remove(struct netif *netif);
368+
void __wrap_netif_remove(struct netif *netif) {
369+
LWIPMutex m;
370+
__real_netif_remove(netif);
371+
}
372+
361373
}; // extern "C"

lib/platform_wrap.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@
203203
-Wl,--wrap=raw_sendto
204204
-Wl,--wrap=raw_remove
205205

206+
-Wl,--wrap=netif_add
207+
-Wl,--wrap=netif_remove
208+
206209
-Wl,--wrap=cyw43_cb_process_ethernet
207210
-Wl,--wrap=cyw43_cb_tcpip_set_link_up
208211
-Wl,--wrap=cyw43_cb_tcpip_set_link_down

libraries/lwIP_Ethernet/src/LwipIntfDev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ bool LwipIntfDev<RawDev>::config(IPAddress local_ip, IPAddress dns) {
310310
extern char wifi_station_hostname[];
311311
template<class RawDev>
312312
bool LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu) {
313+
if (_started) {
314+
// ERROR - Need to ::end before calling ::begin again
315+
return false;
316+
}
317+
313318
lwip_init();
314319
__startEthernetContext();
315320

0 commit comments

Comments
 (0)
0