When using ASyncUDP with Wireguard, packet receive causes Guru Meditation

Using PIO in a Windows environment.
Have done -
pio pkg update -g -p espressif32

When a packet is received via Wireguard - it works OK with Wireguard disabled -

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400895c3  PS      : 0x00060330  A0      : 0x800e7101  A1      : 0x3ffceeb0  
A2      : 0x00000000  A3      : 0x3ffb5644  A4      : 0x00000000  A5      : 0x00000001
A6      : 0x00060f20  A7      : 0x00000001  A8      : 0x800e6f42  A9      : 0x3ffcee60  
A10     : 0x00000001  A11     : 0x3ffb51f0  A12     : 0x3ffb51a4  A13     : 0x00000000
A14     : 0x3ffb51f0  A15     : 0x00000000  SAR     : 0x00000010  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40089611  LEND    : 0x40089621  LCOUNT  : 0xfffffff3


Backtrace: 0x400895c0:0x3ffceeb0 0x400e70fe:0x3ffceec0 0x400e6d3d:0x3ffceee0 0x400e6d90:0x3ffcef00 0x400e6dee:0x3ffcef20 
0x400d7eba:0x3ffcef40 0x400d81a3:0x3ffcef70 0x400d81db:0x3ffcf000 0x400d8210:0x3ffcf020

  #0  0x400895c0:0x3ffceeb0 in strcmp at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strcmp.S:467
  #1  0x400e70fe:0x3ffceec0 in esp_netif_get_handle_from_ifkey at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_netif/esp_netif_objects.c:182
  #2  0x400e6d3d:0x3ffceee0 in netif_from_if at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/tcpip_adapter/tcpip_adapter_compat.c:76
  #3  0x400e6d90:0x3ffcef00 in netif_from_if at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/tcpip_adapter/tcpip_adapter_compat.c:74
  #4  0x400e6dee:0x3ffcef20 in tcpip_adapter_get_netif at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/tcpip_adapter/tcpip_adapter_compat.c:226
  #5  0x400d7eba:0x3ffcef40 in AsyncUDPPacket::AsyncUDPPacket(AsyncUDP*, pbuf*, ip_addr const*, unsigned short, netif*) at C:/Users/Andy/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src/AsyncUDP.cpp:334
  #6  0x400d81a3:0x3ffcef70 in AsyncUDP::_recv(udp_pcb*, pbuf*, ip_addr const*, unsigned short, netif*) at C:/Users/Andy/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src/AsyncUDP.cpp:700
  #7  0x400d81db:0x3ffcf000 in AsyncUDP::_s_recv(void*, udp_pcb*, pbuf*, ip_addr const*, unsigned short, netif*) at C:/Users/Andy/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src/AsyncUDP.cpp:709
  #8  0x400d8210:0x3ffcf020 in _udp_task(void*) at C:/Users/Andy/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src/AsyncUDP.cpp:137

If I use a J-Link I get -

strcmp () at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strcmp.S:470
470 /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strcmp.S: No such file or directory.

Any ideas?

Thanks

Andy.

All this says is that somehow it couldn’t load the data pointed to a by pointer, which when looking at the stacktrace is likely that one of the strcmp() arguments was NULL or pointing at invalid memory. Without a minimal example for reproduction and more tracing, it’s near impossible to say why this would happen.

You were right to open an issue at When ASyncUDP with Wireguard, packet receive causes Guru Meditation · Issue #8397 · espressif/arduino-esp32 · GitHub in which this issue should be discussed with Arduino-ESP32 devs.

Thanks for the quick reply!

Will await a Github reply :wink:

I suspect it is only looking to bind to the default netif, and not looking the second one that wg creates.

As I expected I did not hear anything on GitHub so I used this instead -

IPAddress remote_ip {0, 0, 0, 0};			// IP address of the local WG interface
IPAddress local_ip {0, 0, 0, 0};           	// IP address of the remote WG interface
uint8_t rx_buffer[1600];					// received data

void udp_rtp_init(uint16_t port)
{
  err_t err;
   
  /* Create a new UDP control block  */
  upcb_rtp = udp_new();
  ip_set_option(upcb_rtp, SOF_BROADCAST);

  if(upcb_rtp)
  {
	udp_rtp_port = port;
	if(upcb_rtp)
	{
		udp_rtp_port = port;
		/* Bind the upcb to the UDP_PORT port */
		IP4_ADDR( &udp_rtp_addr.u_addr.ip4,  remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]);
		IP4_ADDR( &wg_local_addr.u_addr.ip4,  local_ip[0], local_ip[1],local_ip[2], local_ip[3]);
		err = udp_bind(upcb_rtp, &wg_local_addr, port);
 
		if(err == ERR_OK)
		{
			/* Set a receive callback for the upcb */
			udp_recv(upcb_rtp, udp_rtp_receive_callback, NULL);
		}
		else
		{
			printf("can not bind pcb");
		}
		upcb_rtp->remote_port = udp_rtp_port;
  }
  else
  {
    printf("can not create pcb");
  } 
}

void udp_rtp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, short unsigned int port)
{
  uint16_t i, j;

  j = p->len;
  memcpy(rx_buffer, p->payload, p->len);


  return;
}

void udp_rtp_tx(unsigned char *data, unsigned short int len)
{
  if(udp_ready == true)
  {
    if (upcb_rtp->remote_port != (uint16_t)0)
    {
      struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
      memcpy(p->payload, data, len);
      udp_sendto(upcb_rtp, p, &udp_rtp_addr, udp_rtp_port);
      pbuf_free(p);
    }
  }
}