[PATCH 1/2] IAPP: Set SO_REUSEPORT on listening socket

Jouni Malinen j at w1.fi
Sun Nov 15 09:16:22 PST 2015


On Tue, Nov 10, 2015 at 08:17:13PM +0200, Petko Bordjukov wrote:
> Make it possible for several instances of hostapd to listen on the same
> network interface.

> diff --git a/src/ap/iapp.c b/src/ap/iapp.c
> @@ -447,6 +448,15 @@ struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface)
>  	os_memset(&uaddr, 0, sizeof(uaddr));
>  	uaddr.sin_family = AF_INET;
>  	uaddr.sin_port = htons(IAPP_UDP_PORT);
> +
> +	if (setsockopt(iapp->udp_sock, SOL_SOCKET, SO_REUSEPORT, &reuseport,
> +		       sizeof(reuseport)) < 0) {

SO_REUSEPORT is a pretty recent addition. Wouldn't this break build with
older header files? As such, this should probably be protected with
#ifdef SO_REUSEPORT or something similar.

> +		wpa_printf(MSG_INFO, "iapp_init - setsockopt[UDP,SO_REUSEPORT]: %s",
> +			   strerror(errno));
> +		iapp_deinit(iapp);
> +		return NULL;
> +	}

And this should not return failure on error since anything older than
Linux 3.9 would fail here. It sounds like it would be safe to ignore the
error and continue to get the existing behavior.

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list