-
Notifications
You must be signed in to change notification settings - Fork 7.3k
net_mgmt: event handling is broken #88534
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
Comments
Yes, but that is why in the event callback one needs to check what event if being fired. This is documented in https://docs.zephyrproject.org/latest/connectivity/networking/api/net_mgmt.html#listening-to-network-events |
It may be documented there, but it isn't mentioned anywhere on the function doxygen. If you can't properly differentiate between different events as part of the API, why pretend that you can? It should just be subscribing for events at the "layer code" level. There is also the question of what the semantics of zephyr/samples/net/cellular_modem/src/main.c Lines 298 to 313 in d453fb9
|
Why not change the registration function to take an arbitrary-length bit array so that we are not stuck at 64 events max? This is essentially what Bluetooth does today. |
Robert and I pondered this a bit offline and we need to overhaul this as Jordan noticed.
Comments / ideas? |
My 2 cents. Callbacks registered at the "layer code" level, with individual events filtered out inside the callbacks. |
@JordanYates IMHO your proposal sounds reasonable. Looking at the PR #88495, it would need some tweaks, are you able to work on this? |
@JordanYates gentle ping, will you update the PR? |
Sorry, I don't really have the time at the moment to make changes with that sort of scope, there are almost 100 instances of |
@JordanYates no worries, I can take a look at this. |
Describe the bug
The current mechanism for subscribing to net_mgmt events is currently broken, in that code that register for callbacks (
net_mgmt_init_event_callback
) on certain events will also result in callbacks being run on other, seemingly random events. This also affects the event waiting functions,net_mgmt_event_wait
andnet_mgmt_event_wait_on_iface
.The core of the problem is that these APIs are defined at the bitmask level, i.e. the internal code is checking bitmasks to determine whether an event matches the requested events:
zephyr/subsys/net/ip/net_mgmt.c
Lines 203 to 204 in 781011b
The problem is that ALL of the events are defined as integer values, not bitmasks. The following example is from the Wi-Fi layer, but it is the same for all the others:
zephyr/include/zephyr/net/wifi_mgmt.h
Lines 320 to 325 in 781011b
zephyr/include/zephyr/net/wifi_mgmt.h
Lines 360 to 366 in 781011b
As a result, if you register for callbacks like so,
net_mgmt_init_event_callback(&cb, wifi_mgmt_event_handler, NET_EVENT_WIFI_CMD_AP_STA_CONNECTED);
, whereNET_EVENT_WIFI_CMD_AP_STA_CONNECTED
== 15, you end up being notified when any of the following events occur, since they all share bits with 15.Potential Solutions
Converting events from integers to bitmasks (as implied by the API), would resolve the issue.
Unfortunately, the command mask only has space for 16 unique events per layer:
zephyr/include/zephyr/net/net_mgmt.h
Line 44 in 781011b
The Wi-Fi management layer already defines 17 unique events, and the IPv6 layer defines over 20.
Converting the event mask to 64 bits would give up to 32 additional possible masks to each layer.
This would be a rather intrusive change, requiring updates to every callback definition to change the API signature to accept the 64bit parameter.
Concerns have also been raise that we will eventually run out of events again: #88495 (comment)
net_mgmt_init_event_callback
to register for layers, not eventsUpdate the semantics of
net_mgmt_init_event_callback
so that instead of registering for individual events, users register for the base layer and perform their own event filtering in the callback. This would allow the event IDs to remain integers, but it a significant API change.It additionally would make the waiting functions (
net_mgmt_event_wait
,net_mgmt_event_wait_on_iface
) not possible to implement for more than a single event (not that they currently work properly).Additional context
Initial attempt to fix: #88495
The text was updated successfully, but these errors were encountered: