From 37975e38306a04644868fd5e48c96fbf1e2408dd Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Sun, 24 May 2026 13:59:33 +0200 Subject: [PATCH] Fix bind_interface support guard The bind_interface parser guard still checked SO_BINDTODEVICE, but the runtime implementation no longer uses SO_BINDTODEVICE. It uses getifaddrs() on non-Windows/non-AIX platforms instead. This caused bind_interface to be rejected at config parse time on platforms where the runtime implementation is available, including macOS. Add a HAVE_BIND_INTERFACE guard and use it consistently for parsing, the ifaddrs include, the bind helper, and the call site. This fixes test/broker/16-config-huge.py on macOS. Assisted-by: OpenAI Codex (GPT-5) Signed-off-by: Karl Mehltretter --- config.h | 4 ++++ src/conf.c | 2 +- src/net.c | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config.h b/config.h index 45145fe79a..851fba020d 100644 --- a/config.h +++ b/config.h @@ -16,6 +16,10 @@ # define HAVE_NETINET_IN_H #endif +#if !defined(WIN32) && !defined(_AIX) +# define HAVE_BIND_INTERFACE +#endif + #define OPENSSL_LOAD_CONF /* ============================================================ diff --git a/src/conf.c b/src/conf.c index 05627df458..bc2fddf792 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1291,7 +1291,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, return MOSQ_ERR_INVAL; } }else if(!strcmp(token, "bind_interface")){ -#ifdef SO_BINDTODEVICE +#ifdef HAVE_BIND_INTERFACE if(reload){ continue; /* Rebinding listeners not valid during reloading. */ } diff --git a/src/net.c b/src/net.c index 611e295d62..2011eea409 100644 --- a/src/net.c +++ b/src/net.c @@ -20,9 +20,6 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause #ifndef WIN32 # include -# ifndef _AIX -# include -# endif # include # include # include @@ -45,6 +42,10 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # include #endif +#ifdef HAVE_BIND_INTERFACE +# include +#endif + #if defined(WITH_UNIX_SOCKETS) || defined(WITH_TLS) # include "sys/stat.h" #endif @@ -718,15 +719,14 @@ int net__tls_load_verify(struct mosquitto__listener *listener) } -#if !defined(WIN32) && !defined(_AIX) +#ifdef HAVE_BIND_INTERFACE static int net__bind_interface(struct mosquitto__listener *listener, struct addrinfo *rp) { /* * This binds the listener sock to a network interface. - * The use of SO_BINDTODEVICE requires root access, which we don't have, so instead - * use getifaddrs to find the interface addresses, and use IP of the + * Use getifaddrs to find the interface addresses, then use the IP of the * matching interface in the later bind(). */ struct ifaddrs *ifaddr; @@ -874,7 +874,7 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener) return 1; } -#if !defined(WIN32) && !defined(_AIX) +#ifdef HAVE_BIND_INTERFACE if(listener->bind_interface){ /* It might be possible that an interface does not support all relevant sa_families. * We should successfully find at least one. */