-
Notifications
You must be signed in to change notification settings - Fork 2k
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
net/gnrc_netif: add bus for interface events, gnrc_netif_up()/gnrc_netif_down() functions #17902
base: master
Are you sure you want to change the base?
Conversation
The approach makes sense to me and can be easily extended to other netif link layers (e.g 802.15.4). |
f8afd7c
to
b9ff0ca
Compare
86a9be4
to
c17dc4c
Compare
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.
first round of comments :)
msg_bus_subscribe(&sub, GNRC_IPV6_EVENT_ADDR_VALID); | ||
#endif | ||
|
||
while (gnrc_netapi_set(netif->pid, NETOPT_STATE, 0, &state, sizeof(state)) == -EBUSY) {} |
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.
Must it be NETOPT_STATE
or can it be NETOPT_LINK
? Because our ifconfig <i> {up | down}
command generates NETOPT_LINK
.
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.
Uh interesting.
My use case was setting STATE_SLEEP which should also generate a link down event…
NETOPT_LINK
is read-only on all 3 drivers that implement it.
5a25d0c
to
b54778a
Compare
b54778a
to
bb2697b
Compare
With 8de8d05 we can now also make use of the bus mechanism in This makes the To register with the interface events, we have to wait for the interfaces to be initialized. Especially on esp32 this can take surprisingly long. If you don't agree with this, I can drop the commit. |
Murdock results❌ FAILED 8de8d05 gnrc_ipv6_nib: make use of gnrc_netif_bus for interface events
ArtifactsThis only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now. |
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.
lgtm. Some comments inline.
I think the opportunistic approach to wait for interfaces to become ready is a dragon that at least should be documented.
if ((state == NETOPT_STATE_SLEEP) || (state == NETOPT_STATE_OFF) || | ||
(state == NETOPT_STATE_STANDBY)) { | ||
event = GNRC_NETIF_EVENT_LINK_STATE_CHANGED_DOWN; | ||
} else { |
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.
} else { | |
} | |
else { |
DEBUG_PUTS("ipv6: wait for interfaces to be ready"); | ||
while (gnrc_netif_iter(NULL) == NULL) { | ||
ztimer_sleep(ZTIMER_MSEC, 250); | ||
} |
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.
This looks fragile. But I also do not know any way to reliably wait for interface registration to complete off the top of my head or even if such feature exists :/
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.
The interfaces could send a message when they are initialized, then we can handle the registration here.
gnrc_ipv6_nib_iface_up(msg.content.ptr); | ||
break; | ||
case GNRC_IPV6_NIB_IFACE_DOWN: | ||
case GNRC_NETIF_EVENT_LINK_STATE_CHANGED_DOWN: |
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.
Care to fix the indent here, since you touch the code anyway?
typedef enum { | ||
/** | ||
* @brief Link state changed to UP | ||
* | ||
* The event is generated when the link state on the interface became online. | ||
*/ | ||
GNRC_NETIF_EVENT_LINK_STATE_CHANGED_DOWN, | ||
|
||
/** | ||
* @brief Link state changed to DOWN | ||
* | ||
* The event is generated when the link state on the interface become offline. | ||
*/ | ||
GNRC_NETIF_EVENT_LINK_STATE_CHANGED_UP, | ||
} gnrc_netif_event_t; |
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.
Documentation seems to be swapped
int res = 0; | ||
|
||
netopt_state_t state_prev; | ||
while (gnrc_netapi_get(netif->pid, NETOPT_STATE, 0, &state_prev, sizeof(state_prev)) == -EBUSY) {} |
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.
This line and the one below are a bit too long (warning of > 100 characters)
Contribution description
It can be useful to know when an interface is up / down, e.g. to (re)start or stop the DHCP client.
This adds a bus to gnrc netif where users interested in interface events (up/down) can subscripe.
It also adds convenience functions
gnrc_netif_up()
,gnrc_netif_down()
that block until the interface event is generated (or timeout).Testing procedure
Issues/PRs references
includes #17893