From 8e334caa2e9636c7b90ee855ae53da0d4dcd34d9 Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 6 Sep 2026 16:55:26 -0400 Subject: [PATCH] [posix] pass an interface index to IPV6_BOUND_IF (#13587) IPV6_BOUND_IF takes an interface index on every BSD (FreeBSD, NetBSD, macOS), but since #9887 the BSD branch of InfraNetif::CreateIcmp6Socket() has passed the interface name string instead. On macOS that makes the setsockopt() fail with EINVAL, so otbr-agent (with border routing enabled) dies at startup. Resolve the name with if_nametoindex() and pass the index, exiting with OT_EXIT_INVALID_ARGUMENTS for an unknown name as SetInfraNetif() does. --- src/posix/platform/infra_if.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/infra_if.cpp b/src/posix/platform/infra_if.cpp index 05a56da52..ed8f195b9 100644 --- a/src/posix/platform/infra_if.cpp +++ b/src/posix/platform/infra_if.cpp @@ -41,6 +41,7 @@ #include #include +#include #include // clang-format off #include @@ -182,7 +183,13 @@ int InfraNetif::CreateIcmp6Socket(const char *aInfraIfName) #ifdef __linux__ rval = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, aInfraIfName, strlen(aInfraIfName)); #else // __NetBSD__ || __FreeBSD__ || __APPLE__ - rval = setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, aInfraIfName, strlen(aInfraIfName)); + { + // IPV6_BOUND_IF takes an interface index, not a name. + unsigned int ifIndex = if_nametoindex(aInfraIfName); + + VerifyOrDie(ifIndex != 0, OT_EXIT_INVALID_ARGUMENTS); + rval = setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, &ifIndex, sizeof(ifIndex)); + } #endif // __linux__ VerifyOrDie(rval == 0, OT_EXIT_ERROR_ERRNO);