You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Вадим Ястребов <wo...@mail.ru.INVALID> on 2021/05/14 16:09:58 UTC

devif_callback_alloc() not releasing callback structure?

Hello everyone!
 
I am still working on implementing 2 PHYs on IMXRT1064 and currently using netpkt example for transmitting the simplest packets.
 
Here is my problem:
 
Have 2 Ethernet interfaces (eth0 and eth1).
eth0 is UP, eth1 is DOWN.
Transmitting through eth1 results in packets coming out of interface that is UP (being eth0).
Expected behavior when transmitting through eth0.
 
eth0 is DOWN, eth1 is UP.
Transmitting through eth0 results in packets coming out of interface that is UP (being eth1).
Expected behavior when transmitting through eth1.
 
eth0 is UP, eth1 is UP.
Expected behavior when transmitting through eth0 and eth1.
 
When going through the code in devif_callback.c,
https://github.com/apache/incubator-nuttx/blob/3af0ef70ff5d5bd4d4d1cdb0152ee53182dc09dd/net/devif/devif_callback.c#L259-L270
I noticed an if condition which I am having difficulties understanding. The comment above it says something that, in my opinion, does not correspond to the code.
Shouldn’t line 266 be this one instead?
if (! netdev_verify (dev)  || ! (dev-> d_flags & IFF_UP))
 
Once I made that change, the packets stopped being sent through incorrect interfaces when the specified interface is DOWN.
However, now if I attempt to send packets with netpkt through an interface that is down multiple times (maybe 5-6? do not remember the precise number), at some point I will start getting ‘ERROR: Failed to allocate callback’ message. At this point, it doesn’t matter which interface I select, the error is always printed.
 
Then I noticed that line 270:
devif_callback_free ( NULL ,  NULL , list);
Will probably not do anything because the function checks the second argument for NULL right at the very beginning. This results in function not doing anything at all. Is that the expected behavior?
 
Please let me know your thoughts!
 
Regards,
Vadim Yastrebov
 
P.S. in  net/pkt/pkt_finddev.c
In function pkt_find_device(), originally, ‘eth0’ string was hardcoded when looking up the device. This prevented me from selecting the device for transmission. Instead, I used netdev_findbyindex() which now works just fine and is able to provide the correct device.