Skip to content

Commit 09f6fdf

Browse files
authored
[Darwin][Network.framework] Append interface scope for IPv6 multicast and match incoming packets by interface in Connections (#39430)
1 parent 42cf80b commit 09f6fdf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
#endif // INET_CONFIG_ENABLE_IPV4
235235
{
236236
aAddress.ToString(addrStr);
237-
if (interfaceIndex != InterfaceId::Null() && aAddress.IsIPv6LinkLocal()) {
237+
if (interfaceIndex != InterfaceId::Null() && (aAddress.IsIPv6LinkLocal() || aAddress.IsIPv6Multicast())) {
238238
char interface[InterfaceId::kMaxIfNameLength + 1] = {}; // +1 to prepend '%'
239239
interface[0] = '%';
240240
interface[1] = 0;

src/platform/Darwin/inet/UDPEndPointImplNetworkFrameworkConnection.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,22 @@
336336

337337
IPAddress remoteAddress;
338338
IPAddress::GetIPAddressFromSockAddr(*nw_endpoint_get_address(remoteEndpoint), remoteAddress);
339+
VerifyOrReturnValue(pktInfo.DestAddress == remoteAddress, false);
340+
339341
const uint16_t remotePort = nw_endpoint_get_port(remoteEndpoint);
342+
VerifyOrReturnValue(pktInfo.DestPort == remotePort, false);
343+
344+
if (pktInfo.Interface != InterfaceId::Null()) {
345+
uint32_t interfaceIndex = 0;
346+
__auto_type * sa = nw_endpoint_get_address(remoteEndpoint);
347+
if (sa && sa->sa_family == AF_INET6) {
348+
__auto_type in6 = reinterpret_cast<const struct sockaddr_in6 *>(sa);
349+
interfaceIndex = static_cast<uint32_t>(in6->sin6_scope_id);
350+
VerifyOrReturnValue(interfaceIndex == pktInfo.Interface.GetPlatformInterface(), false);
351+
}
352+
}
340353

341-
return pktInfo.DestAddress == remoteAddress && pktInfo.DestPort == remotePort;
354+
return true;
342355
}
343356

344357
void UDPEndPointImplNetworkFrameworkConnection::ConnectionWrapper::RefreshTimeout()

0 commit comments

Comments
 (0)