Problem when enabling/disabling NAT on esp-idf 4.3.2

BrunoOtavio
Posts: 8
Joined: Wed Sep 25, 2019 8:31 pm

Problem when enabling/disabling NAT on esp-idf 4.3.2

Postby BrunoOtavio » Thu Jun 02, 2022 1:14 pm

I'm trying to enable NAT by using lwip from esp-idf, but the function to do it seems that isn't working properly.
The first image shows the "if" that must work to execute the ip_napt_init function where the necessary structures are initialized, but here this 'if' is never executed, so the NAT is never enabled. This function do not returns a error when the process did not work properly, so I will know that it didn't work only when I try to disable the NAT, in this case, the ip_napt_deinit is called (more below in the same image).
Captura de Tela (54)_LI.jpg
Captura de Tela (54)_LI.jpg (1.64 MiB) Viewed 2377 times
The second image is the code from ip_napt_init
Captura de Tela (56).png
Captura de Tela (56).png (43.52 KiB) Viewed 2377 times
The third image is ip_napt_deinit function, the board is crashing because it tries to free a memory that wasn't allocate before.
Captura de Tela (55).png
Captura de Tela (55).png (9.42 KiB) Viewed 2377 times

mknezic
Posts: 2
Joined: Wed Nov 23, 2022 4:27 pm

Re: Problem when enabling/disabling NAT on esp-idf 4.3.2

Postby mknezic » Wed Nov 23, 2022 4:35 pm

Hi,

Most probably, your interface is either not up yet, or it has not been allocated an IP address. Quick workaround would be to sleep for a couple of seconds (until interface is up and DHCP allocates an IP address to it). Better solution would be to check the status of the interface using

Code: Select all

esp_netif_is_netif_up()
function. Then, all you need is to wait until the interface is up and running before calling

Code: Select all

ip_napt_enable()
for that interface. Hope it helps.

Regards,

Mladen

Who is online

Users browsing this forum: VinayDand and 430 guests