-
Notifications
You must be signed in to change notification settings - Fork 2.1k
lwip: add IPv4 support for netdev_tap
#14150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lwip: add IPv4 support for netdev_tap
#14150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that this PR solves the compile error on master when building tests/lwip
with the LWIP_IPV4=1
option set. But I couldn't test with proper traffic because the RIOT instance node won't get an address and always stays at 0.0.0.0. Even with a proper DHCP server setup this wont work. Looking at the code tells me that the dhcp client of lwip is only started via a NETDEV_EVENT_LINK_UP
event. But netdev_tap never actually triggers that. @miri64 where would be the most appropriate place to issue that event?
As I wrote in the testing procedures, I wasn't able to figure this out myself yesterday :-/. Maybe @gschorcht has some hints? |
"injecting" a |
Maybe just |
Hmm that would be more like telling the network device to go up. But then the indication from the tap device to the lwip netdev instance (i.e.
|
Ah, I mixed it up with the So I guess, we need to add that event then. |
@MichelRottleuthner do you want use your injection hack as a template for a PR? |
Not really. Its was just a really dirty hack to confirm if that event really is the missing part. snippetdiff --git a/cpu/native/netdev_tap/netdev_tap.c b/cpu/native/netdev_tap/netdev_tap.c
index 1afdc1e62..2a34475fb 100644
--- a/cpu/native/netdev_tap/netdev_tap.c
+++ b/cpu/native/netdev_tap/netdev_tap.c
@@ -204,11 +204,22 @@ static void _continue_reading(netdev_tap_t *dev)
_native_in_syscall--;
}
+bool first_recv = true;
+
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
netdev_tap_t *dev = (netdev_tap_t*)netdev;
(void)info;
+ if (first_recv) {
+ if (netdev->event_callback) {
+ netdev->event_callback(netdev, NETDEV_EVENT_LINK_UP);
+ } else {
+ DEBUG("no event callback!!\n");
+ }
+ first_recv = false;
+ }
+
if (!buf) {
if (len > 0) {
/* no memory available in pktbuf, discarding the frame */ I think a proper solution would do more something like the two steps I described above. @jia200x to me it feels like this pretty much touches what you worked on with MLME/MCPS (#11324) . Do you have some wise thoughts to share here? Is the ongoing MAC layer rework maybe already providing a generic solution to this? |
Since I rather would not like to touch the lwIP code proper, if necessary. |
But maybe you are right :-/.
|
Ah, if the call back is initialized earlier, the context should be as well ^^" |
I should test before I push >.< |
Ok, we have a bootstrapping problem: In my opinion, it does not make sense to initialize the context and callback after we call |
For now, I added a hack for |
I think this special case for native tap is ok for now. Though I question how stable the current approach is for other netdevs. On the ESP for example it probably only works because connecting to WiFi takes some time. Beware of any super fast connecting WiFis otherwise assertions may haunt you? :P |
Yepp. My thought exactly (edit: but not the focus of this PR). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with BOARD=native LWIP_IPV4=1 make -C tests/lwip all term
and a DHCP server serving the tap interface on the linux side. RIOT now gets a valid IPv4 address and I can communicate with it via the tcp and udp commands. Feel free to squash!
Squashed. |
f28879e
to
f5c4a05
Compare
Somehow :). The idea behind this is to provide an asynchronous API to control the MAC layer from the network interface. Not sure if I misunderstood the problem, but what's described here can be solved with this Request/Confirm pattern of the SAP API described in #11324. The generic solution could look like this:
For instance: netif_init()
{
/* It's assumed the `init` function of the device was called on startup. The device IRQs are disabled. */
if (!mac_init()) {
return -EINVAL;
}
dev->event_cb = _cb;
return dev->driver->on(dev); /* Turn on the device. It's safe to receive interrupts from here. */
}
netif_up() /* called on `ifconfig <if_id> up` */
{
return mlme_join(mac, join_ctx); /* This will generate a Confirm primitive */
}
mlme_join_cb(status) /* called when the mlme_join request finishes */
{
if (status == OK) {
netif_generate_link_up_event();
}
} |
So the hack as is can be merged and we move this over to the new API, once its there :-). |
Thanks @jia200x for providing the details!
Agree |
Contribution description
This PR adds the support for
netdev_tap
to pkg/lwip the same way as PR #12895 and #12950 already did for other Ethernet devices.Testing procedure
I only was able to compile test this, but there was no traffic visible in Wireshark.
Issues/PRs references
None, but came up during the review of #13701.