Skip to content

Commit

Permalink
event_iface: only set rcv buf size if too small
Browse files Browse the repository at this point in the history
Instead of always setting the receive buffer size
to a small 8K, which causes problems when a flood of
netlink messages are received, set it to a
"minimal" value only if it is currently less
than that value.

The value used is 32 x the MAX_PAYLOAD size
of 4k, i.e. 128k.

A config value to modify this can be added if needed,
but doesn't seem warranted at this time.

Changes in V2:
* remove unneeded debugging/logging

Acked-by: Aaron Conole <aconole@redhat.com>
  • Loading branch information
gonzoleeman authored and apconole committed Dec 10, 2020
1 parent f91cf35 commit 9dada23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions event_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,27 @@ event_iface_receive(int sock, UNUSED void *eloop_ctx, UNUSED void *sock_ctx)
int event_iface_init()
{
int fd;
int rcv_size = MAX_PAYLOAD;
int rcv_size = 0;
socklen_t rcv_len = sizeof(int);
struct sockaddr_nl snl;

fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

if (fd < 0)
return fd;

if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcv_size, sizeof(int)) < 0) {
/* is receive buffer size too small? */
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcv_size, &rcv_len) < 0) {
close(fd);
return -EIO;
}
if (rcv_size < MIN_RCVBUF_SIZE) {
rcv_size = MIN_RCVBUF_SIZE >> 1; /* we get back 2x what we set */
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcv_size, rcv_len) < 0) {
close(fd);
return -EIO;
}
}

memset((void *)&snl, 0, sizeof(struct sockaddr_nl));
snl.nl_family = AF_NETLINK;
Expand Down
1 change: 1 addition & 0 deletions include/qbg_vdpnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/if_ether.h>

#define MAX_PAYLOAD 4096 /* Maximum Payload Size */
#define MIN_RCVBUF_SIZE (MAX_PAYLOAD << 5) /* SO_RCVBUF min */

enum {
vdpnl_nlf1 = 1, /* Netlink message format 1 (draft 0.2) */
Expand Down

0 comments on commit 9dada23

Please sign in to comment.