[posix] bind infra IF socket to specific interface (#6089)

This is for ensuring sending ICMP6 packets on only the specified
infrastructure interface.
This commit is contained in:
kangping
2021-01-20 13:16:12 -08:00
committed by GitHub
parent 0bf8c416ab
commit 46b1807643
+7
View File
@@ -231,6 +231,13 @@ void platformInfraIfInit(otInstance *aInstance, const char *aIfName)
rval = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &kHopLimit, sizeof(kHopLimit));
VerifyOrDie(rval == 0, OT_EXIT_ERROR_ERRNO);
#ifdef __linux__
rval = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, sInfraIfName, strlen(sInfraIfName));
#else // __NetBSD__ || __FreeBSD__ || __APPLE__
rval = setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &sInfraIfIndex, sizeof(sInfraIfIndex));
#endif // __linux__
VerifyOrDie(rval == 0, OT_EXIT_ERROR_ERRNO);
sInfraIfIcmp6Socket = sock;
SuccessOrDie(InitLinkLocalAddress());
}