76 lines
2.1 KiB
Diff
76 lines
2.1 KiB
Diff
|
|
From 9dada231f322a0889b2bcb5c6e02ac895695699a Mon Sep 17 00:00:00 2001
|
||
|
|
From: Lee Duncan <lduncan@suse.com>
|
||
|
|
Date: Thu, 10 Dec 2020 11:25:14 -0800
|
||
|
|
Subject: [PATCH] event_iface: only set rcv buf size if too small
|
||
|
|
|
||
|
|
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>
|
||
|
|
---
|
||
|
|
event_iface.c | 13 +++++++++++--
|
||
|
|
include/qbg_vdpnl.h | 1 +
|
||
|
|
2 files changed, 12 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/event_iface.c b/event_iface.c
|
||
|
|
index 1be2963..916bf4b 100644
|
||
|
|
--- a/event_iface.c
|
||
|
|
+++ b/event_iface.c
|
||
|
|
@@ -418,7 +418,8 @@ 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);
|
||
|
|
@@ -426,10 +427,18 @@ int event_iface_init()
|
||
|
|
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;
|
||
|
|
diff --git a/include/qbg_vdpnl.h b/include/qbg_vdpnl.h
|
||
|
|
index cb7efca..a9369d9 100644
|
||
|
|
--- a/include/qbg_vdpnl.h
|
||
|
|
+++ b/include/qbg_vdpnl.h
|
||
|
|
@@ -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) */
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|