Skip to content
Snippets Groups Projects
Commit a2aba5c7 authored by Alin Nastac's avatar Alin Nastac Committed by Hans Dedecker
Browse files

system-linux: handle hotplug event socket ENOBUFS errors


Hotplug events are no longer handled after socket RX queue is
overrun. The issue has been fixed by:
  - setting SO_RCVBUF initially to 65535
  - doubling SO_RCVBUF value each time RX queue gets overrun

Signed-off-by: default avatarAlin Nastac <alin.nastac@gmail.com>
parent d0fa124e
No related branches found
No related tags found
No related merge requests found
Pipeline #182 failed
...@@ -181,6 +181,21 @@ create_event_socket(struct event_socket *ev, int protocol, ...@@ -181,6 +181,21 @@ create_event_socket(struct event_socket *ev, int protocol,
return true; return true;
} }
static bool
create_hotplug_event_socket(struct event_socket *ev, int protocol,
void (*cb)(struct uloop_fd *u, unsigned int events))
{
if (!create_raw_event_socket(ev, protocol, 1, cb, ULOOP_ERROR_CB))
return false;
/* Increase rx buffer size to 65K on event sockets */
ev->bufsize = 65535;
if (nl_socket_set_buffer_size(ev->sock, ev->bufsize, 0))
return false;
return true;
}
static bool static bool
system_rtn_aton(const char *src, unsigned int *dst) system_rtn_aton(const char *src, unsigned int *dst)
{ {
...@@ -249,8 +264,8 @@ int system_init(void) ...@@ -249,8 +264,8 @@ int system_init(void)
if (!create_event_socket(&rtnl_event, NETLINK_ROUTE, cb_rtnl_event)) if (!create_event_socket(&rtnl_event, NETLINK_ROUTE, cb_rtnl_event))
return -1; return -1;
if (!create_raw_event_socket(&hotplug_event, NETLINK_KOBJECT_UEVENT, 1, if (!create_hotplug_event_socket(&hotplug_event, NETLINK_KOBJECT_UEVENT,
handle_hotplug_event, 0)) handle_hotplug_event))
return -1; return -1;
// Receive network link events form kernel // Receive network link events form kernel
...@@ -630,13 +645,39 @@ handle_hotplug_event(struct uloop_fd *u, unsigned int events) ...@@ -630,13 +645,39 @@ handle_hotplug_event(struct uloop_fd *u, unsigned int events)
struct sockaddr_nl nla; struct sockaddr_nl nla;
unsigned char *buf = NULL; unsigned char *buf = NULL;
int size; int size;
int err;
socklen_t errlen = sizeof(err);
if (!u->error) {
while ((size = nl_recv(ev->sock, &nla, &buf, NULL)) > 0) {
if (nla.nl_pid == 0)
handle_hotplug_msg((char *) buf, size);
free(buf);
}
return;
}
while ((size = nl_recv(ev->sock, &nla, &buf, NULL)) > 0) { if (getsockopt(u->fd, SOL_SOCKET, SO_ERROR, (void *)&err, &errlen))
if (nla.nl_pid == 0) goto abort;
handle_hotplug_msg((char *) buf, size);
switch(err) {
case ENOBUFS:
/* Increase rx buffer size on netlink socket */
ev->bufsize *= 2;
if (nl_socket_set_buffer_size(ev->sock, ev->bufsize, 0))
goto abort;
break;
free(buf); default:
goto abort;
} }
u->error = false;
return;
abort:
uloop_fd_delete(&ev->uloop);
return;
} }
static int system_rtnl_call(struct nl_msg *msg) static int system_rtnl_call(struct nl_msg *msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment