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.
pull/15370/head
YannCharbon 2023-01-10 18:45:39 +01:00
parent 2e506ba793
commit b8b638dd41
1 changed files with 10 additions and 1 deletions

View File

@ -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;
}