From b8b638dd415b7b94eb74a188182a9fd5bf1feb0f Mon Sep 17 00:00:00 2001 From: YannCharbon Date: Tue, 10 Jan 2023 18:45:39 +0100 Subject: [PATCH] Fix default interface ID only being used partially If user sets the default interface ID for a socket (e.g. using setsockopt with SOCKET_INTERFACE_SELECT), the default interface should take over other interface selection mechanisms as a interface is bound to the socket. This applies for both IPv6 local and global scopes for unicast messages but not for multicast messages as these are bound to a multicast interface using SOCKET_IPV6_MULTICAST_IF socket option. --- .../sal-stack-nanostack/source/Core/ns_socket.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/connectivity/nanostack/sal-stack-nanostack/source/Core/ns_socket.c b/connectivity/nanostack/sal-stack-nanostack/source/Core/ns_socket.c index c520c20279b..a35a5b75d05 100644 --- a/connectivity/nanostack/sal-stack-nanostack/source/Core/ns_socket.c +++ b/connectivity/nanostack/sal-stack-nanostack/source/Core/ns_socket.c @@ -1570,8 +1570,17 @@ struct protocol_interface_info_entry *socket_interface_determine(const socket_t } } - /* Try a routing table entry for greater-than-realm scope */ + /* For greater-than-realm scope, use default interface if a default interface ID */ + /* has been set (e.g. using setsockopt), else try a routing table entry */ if (addr_ipv6_scope(buf->dst_sa.address, NULL) > IPV6_SCOPE_REALM_LOCAL) { + if (socket_ptr->default_interface_id != -1) { + cur_interface = protocol_stack_interface_info_get_by_id(socket_ptr->default_interface_id); + if (cur_interface) { + return cur_interface; + } else { + return NULL; + } + } if (ipv6_buffer_route(buf)) { return buf->interface; }