-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Openthread border router fix socket close #99495
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
Merged
nashif
merged 3 commits into
zephyrproject-rtos:main
from
nxp-upstream:openthread_border_router_fix_socket_close
Nov 21, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -14,12 +14,14 @@ | |||
| #include <zephyr/net/net_if.h> | ||||
| #include <zephyr/net/net_ip.h> | ||||
| #include "sockets_internal.h" | ||||
| #include <platform-zephyr.h> | ||||
|
|
||||
| #define MAX_SERVICES CONFIG_OPENTHREAD_ZEPHYR_BORDER_ROUTER_TREL_SERVICES | ||||
|
|
||||
| static struct zsock_pollfd sockfd_udp[MAX_SERVICES]; | ||||
| static int trel_sock = -1; | ||||
| static struct otInstance *ot_instance_ptr; | ||||
| static struct net_if *ail_iface_ptr; | ||||
| static otPlatTrelCounters trel_counters; | ||||
| static bool trel_is_enabled; | ||||
| static void trel_receive_handler(struct net_socket_service_event *evt); | ||||
|
|
@@ -30,9 +32,9 @@ NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(trel_udp_service, trel_receive_handler, MA | |||
| void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort) | ||||
| { | ||||
| struct net_sockaddr_in6 addr = {.sin6_family = NET_AF_INET6, | ||||
| .sin6_port = 0, | ||||
| .sin6_addr = NET_IN6ADDR_ANY_INIT, | ||||
| .sin6_scope_id = 0}; | ||||
| .sin6_port = 0, | ||||
| .sin6_addr = NET_IN6ADDR_ANY_INIT, | ||||
| .sin6_scope_id = 0}; | ||||
| net_socklen_t len = sizeof(addr); | ||||
|
|
||||
| trel_sock = zsock_socket(NET_AF_INET6, NET_SOCK_DGRAM, NET_IPPROTO_UDP); | ||||
|
|
@@ -47,6 +49,11 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort) | |||
|
|
||||
| trel_is_enabled = true; | ||||
|
|
||||
| if (ail_iface_ptr != NULL && net_if_is_up(ail_iface_ptr)) { | ||||
| (void)trel_plat_init(ot_instance_ptr, ail_iface_ptr); | ||||
| } | ||||
|
|
||||
|
|
||||
|
Comment on lines
+55
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, single empty line is sufficient
Suggested change
|
||||
| exit: | ||||
| return; | ||||
|
|
||||
|
|
@@ -63,6 +70,9 @@ void otPlatTrelDisable(otInstance *aInstance) | |||
| sockfd_udp[0].fd = -1; | ||||
| trel_sock = -1; | ||||
|
|
||||
| net_socket_service_register(&trel_udp_service, sockfd_udp, | ||||
| ARRAY_SIZE(sockfd_udp), NULL); | ||||
|
|
||||
| trel_is_enabled = false; | ||||
|
|
||||
| exit: | ||||
|
|
@@ -75,15 +85,15 @@ void otPlatTrelSend(otInstance *aInstance, const uint8_t *aUdpPayload, uint16_t | |||
| VerifyOrExit(trel_is_enabled); | ||||
|
|
||||
| struct net_sockaddr_in6 dest_sock_addr = {.sin6_family = NET_AF_INET6, | ||||
| .sin6_port = net_htons(aDestSockAddr->mPort), | ||||
| .sin6_addr = {{{0}}}, | ||||
| .sin6_scope_id = 0}; | ||||
| .sin6_port = net_htons(aDestSockAddr->mPort), | ||||
| .sin6_addr = {{{0}}}, | ||||
| .sin6_scope_id = 0}; | ||||
|
|
||||
| memcpy(&dest_sock_addr.sin6_addr, &aDestSockAddr->mAddress, sizeof(otIp6Address)); | ||||
|
|
||||
| if (zsock_sendto(trel_sock, aUdpPayload, aUdpPayloadLen, 0, | ||||
| (struct net_sockaddr *)&dest_sock_addr, | ||||
| sizeof(dest_sock_addr)) == aUdpPayloadLen) { | ||||
| (struct net_sockaddr *)&dest_sock_addr, | ||||
| sizeof(dest_sock_addr)) == aUdpPayloadLen) { | ||||
| trel_counters.mTxBytes += aUdpPayloadLen; | ||||
| trel_counters.mTxPackets++; | ||||
| } else { | ||||
|
|
@@ -119,7 +129,7 @@ static void trel_receive_handler(struct net_socket_service_event *evt) | |||
| VerifyOrExit(openthread_border_router_allocate_message((void **)&req) == OT_ERROR_NONE); | ||||
|
|
||||
| len = zsock_recvfrom(trel_sock, req->buffer, sizeof(req->buffer), 0, | ||||
| (struct net_sockaddr *)&addr, &addrlen); | ||||
| (struct net_sockaddr *)&addr, &addrlen); | ||||
| VerifyOrExit(len > 0); | ||||
|
|
||||
| trel_counters.mRxBytes += len; | ||||
|
|
@@ -141,13 +151,14 @@ static void process_trel_message(struct otbr_msg_ctx *msg_ctx_ptr) | |||
| &msg_ctx_ptr->sock_addr); | ||||
| } | ||||
|
|
||||
| otError trel_plat_init(otInstance *instance, struct net_if *ail_iface_ptr) | ||||
| otError trel_plat_init(otInstance *instance, struct net_if *ail_iface) | ||||
| { | ||||
| otError error = OT_ERROR_NONE; | ||||
| struct net_ifreq if_req = {0}; | ||||
| char name[CONFIG_NET_INTERFACE_NAME_LEN + 1] = {0}; | ||||
|
|
||||
| ot_instance_ptr = instance; | ||||
| ail_iface_ptr = ail_iface; | ||||
|
|
||||
| VerifyOrExit(net_if_get_name(ail_iface_ptr, name, | ||||
| CONFIG_NET_INTERFACE_NAME_LEN) > 0, | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nitpicking here, if you'd add a trailing comma to the last item, it would be formatted like:
Which is a best nicer IMO.