[5/7] hostap: Ensure netlink recv buf size is large enough.

Submitted by Ben Greear on July 6, 2012, 4:52 p.m.

Details

Message ID 1341593561-14090-5-git-send-email-greearb@candelatech.com
State Not Applicable
Headers show

Commit Message

Ben Greear July 6, 2012, 4:52 p.m.
From: Ben Greear <greearb@candelatech.com>

I was getting this error on wpa_supplicant startup when configured
for 200+ stations:

1333514002.074458: netlink: recvfrom failed: No buffer space available

So, increase rcv buffer size to 1MB so we don't drop netlink
packets.

Signed-hostap: Ben Greear <greearb@candelatech.com>
---
 src/drivers/netlink.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

Comments

Jouni Malinen July 7, 2012, 3:16 p.m.
On Fri, Jul 06, 2012 at 09:52:39AM -0700, greearb@candelatech.com wrote:
> I was getting this error on wpa_supplicant startup when configured
> for 200+ stations:
> 
> 1333514002.074458: netlink: recvfrom failed: No buffer space available
> 
> So, increase rcv buffer size to 1MB so we don't drop netlink
> packets.

This looks like a very special corner case and unnecessary (and
potentially undesired) change for more common use cases. If there is a
megabyte of pending netlink messages in the buffer, something has went
seriously wrong for normal use case and it sounds like a better idea to
drop the messages than try to keep collecting more of them.

If this is needed for special cases, it would sound more reasonable to
increase the buffer once a huge number of virtual interfaces is enabled
at the same time.
Ben Greear July 7, 2012, 3:39 p.m.
On 07/07/2012 08:16 AM, Jouni Malinen wrote:
> On Fri, Jul 06, 2012 at 09:52:39AM -0700, greearb@candelatech.com wrote:
>> I was getting this error on wpa_supplicant startup when configured
>> for 200+ stations:
>>
>> 1333514002.074458: netlink: recvfrom failed: No buffer space available
>>
>> So, increase rcv buffer size to 1MB so we don't drop netlink
>> packets.
>
> This looks like a very special corner case and unnecessary (and
> potentially undesired) change for more common use cases. If there is a
> megabyte of pending netlink messages in the buffer, something has went
> seriously wrong for normal use case and it sounds like a better idea to
> drop the messages than try to keep collecting more of them.
>
> If this is needed for special cases, it would sound more reasonable to
> increase the buffer once a huge number of virtual interfaces is enabled
> at the same time.

How about a command-line arg to allow users to set the size?

Thanks,
Ben

Patch hide | download patch | download mbox

diff --git a/src/drivers/netlink.c b/src/drivers/netlink.c
index dd662f3..930acc4 100644
--- a/src/drivers/netlink.c
+++ b/src/drivers/netlink.c
@@ -92,6 +92,7 @@  struct netlink_data * netlink_init(struct netlink_config *cfg)
 {
 	struct netlink_data *netlink;
 	struct sockaddr_nl local;
+	int rsize;
 
 	netlink = os_zalloc(sizeof(*netlink));
 	if (netlink == NULL)
@@ -118,6 +119,18 @@  struct netlink_data * netlink_init(struct netlink_config *cfg)
 		return NULL;
 	}
 
+	/* Set the rcv buffer large so we don't drop netlink messages
+	 * on heavily loaded systems.
+	 */
+	rsize = 1024 * 1024;
+	if (setsockopt(netlink->sock, SOL_SOCKET, SO_RCVBUF,
+		       (char *)&rsize, sizeof(rsize)) < 0) {
+		wpa_printf(MSG_ERROR,
+			   "netlink: Failed setting rcv buffer to: %i: %s\n",
+			   rsize, strerror(errno));
+		/* Not the end of the world..continue */
+	}
+
 	eloop_register_read_sock(netlink->sock, netlink_receive, netlink,
 				 NULL);