summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klötzke2019-12-16 22:56:49 +0100
committerDenys Vlasenko2020-11-22 13:12:51 +0100
commit12aa68d10fdcc5bd2d9385506d11aed3a0c2eaf1 (patch)
treef1b778c61fc1be4005759e300a3bf3f347d6fde4
parent9bf4499dd7c72db7636555ec386804540a3266fe (diff)
downloadbusybox-12aa68d10fdcc5bd2d9385506d11aed3a0c2eaf1.zip
busybox-12aa68d10fdcc5bd2d9385506d11aed3a0c2eaf1.tar.gz
libbb: set netlink socket revbuf size before binding
As soon as the socket is bound it will receive messages. Make sure the recieve buffer size is increased before the first message is received. Signed-off-by: Jan Klötzke <jan@kloetzke.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/xconnect.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index e9a2470..5dd9cfd 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -422,17 +422,14 @@ int FAST_FUNC create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf)
struct sockaddr_nl sa;
int fd;
- memset(&sa, 0, sizeof(sa));
- sa.nl_family = AF_NETLINK;
- sa.nl_pid = getpid();
- sa.nl_groups = grp;
fd = xsocket(AF_NETLINK, SOCK_DGRAM, proto);
- xbind(fd, (struct sockaddr *) &sa, sizeof(sa));
- close_on_exec_on(fd);
+ /* Set receive buffer size before binding the socket
+ * We want to have enough space before we start receiving messages.
+ */
if (rcvbuf != 0) {
- // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl
- setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, rcvbuf);
+ setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, rcvbuf);
+ /* SO_RCVBUFFORCE (root only) can go above net.core.rmem_max */
setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, rcvbuf);
# if 0
{
@@ -444,6 +441,13 @@ int FAST_FUNC create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf)
# endif
}
+ memset(&sa, 0, sizeof(sa));
+ sa.nl_family = AF_NETLINK;
+ sa.nl_pid = getpid();
+ sa.nl_groups = grp;
+ xbind(fd, (struct sockaddr *) &sa, sizeof(sa));
+ close_on_exec_on(fd);
+
return fd;
}
#endif