|
|
ee8720 |
From 682b0ccabdc7970f89544c0d19477515583a5f5b Mon Sep 17 00:00:00 2001
|
|
|
ee8720 |
From: Beniamino Galvani <bgalvani@redhat.com>
|
|
|
ee8720 |
Date: Thu, 25 Feb 2021 14:38:16 +0100
|
|
|
ee8720 |
Subject: [PATCH] libndp,ndptool: use poll() instead of select()
|
|
|
ee8720 |
|
|
|
ee8720 |
select() doesn't support file descriptors greater than 1023. If the
|
|
|
ee8720 |
program has many files open, the socket descriptor can be > 1023 and
|
|
|
ee8720 |
then FD_SET(fd, &rfds) causes a buffer overflow.
|
|
|
ee8720 |
|
|
|
ee8720 |
Switch to poll() and ppoll() which don't have this limitation.
|
|
|
ee8720 |
|
|
|
ee8720 |
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
|
|
|
ee8720 |
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
|
|
|
ee8720 |
---
|
|
|
ee8720 |
libndp/libndp.c | 20 +++++++++-----------
|
|
|
ee8720 |
utils/Makefile.am | 2 +-
|
|
|
ee8720 |
utils/Makefile.in | 2 +-
|
|
|
ee8720 |
utils/ndptool.c | 22 +++++++++-------------
|
|
|
ee8720 |
4 files changed, 20 insertions(+), 26 deletions(-)
|
|
|
ee8720 |
|
|
|
ee8720 |
diff --git a/libndp/libndp.c b/libndp/libndp.c
|
|
|
ee8720 |
index 06a3d23..6314717 100644
|
|
|
ee8720 |
--- a/libndp/libndp.c
|
|
|
ee8720 |
+++ b/libndp/libndp.c
|
|
|
ee8720 |
@@ -25,7 +25,7 @@
|
|
|
ee8720 |
#include <errno.h>
|
|
|
ee8720 |
#include <ctype.h>
|
|
|
ee8720 |
#include <sys/socket.h>
|
|
|
ee8720 |
-#include <sys/select.h>
|
|
|
ee8720 |
+#include <poll.h>
|
|
|
ee8720 |
#include <netinet/in.h>
|
|
|
ee8720 |
#include <netinet/icmp6.h>
|
|
|
ee8720 |
#include <arpa/inet.h>
|
|
|
ee8720 |
@@ -2107,22 +2107,20 @@ int ndp_call_eventfd_handler(struct ndp *ndp)
|
|
|
ee8720 |
NDP_EXPORT
|
|
|
ee8720 |
int ndp_callall_eventfd_handler(struct ndp *ndp)
|
|
|
ee8720 |
{
|
|
|
ee8720 |
- fd_set rfds;
|
|
|
ee8720 |
- int fdmax;
|
|
|
ee8720 |
- struct timeval tv;
|
|
|
ee8720 |
- int fd = ndp_get_eventfd(ndp);
|
|
|
ee8720 |
+ struct pollfd pfd;
|
|
|
ee8720 |
int ret;
|
|
|
ee8720 |
int err;
|
|
|
ee8720 |
|
|
|
ee8720 |
- memset(&tv, 0, sizeof(tv));
|
|
|
ee8720 |
- FD_ZERO(&rfds);
|
|
|
ee8720 |
- FD_SET(fd, &rfds);
|
|
|
ee8720 |
- fdmax = fd + 1;
|
|
|
ee8720 |
+ pfd = (struct pollfd) {
|
|
|
ee8720 |
+ .fd = ndp_get_eventfd(ndp),
|
|
|
ee8720 |
+ .events = POLLIN,
|
|
|
ee8720 |
+ };
|
|
|
ee8720 |
+
|
|
|
ee8720 |
while (true) {
|
|
|
ee8720 |
- ret = select(fdmax, &rfds, NULL, NULL, &tv;;
|
|
|
ee8720 |
+ ret = poll(&pfd, 1, 0);
|
|
|
ee8720 |
if (ret == -1)
|
|
|
ee8720 |
return -errno;
|
|
|
ee8720 |
- if (!FD_ISSET(fd, &rfds))
|
|
|
ee8720 |
+ if (!(pfd.revents & POLLIN))
|
|
|
ee8720 |
return 0;
|
|
|
ee8720 |
err = ndp_call_eventfd_handler(ndp);
|
|
|
ee8720 |
if (err)
|
|
|
ee8720 |
diff --git a/utils/Makefile.am b/utils/Makefile.am
|
|
|
ee8720 |
index cca00c2..75e452c 100644
|
|
|
ee8720 |
--- a/utils/Makefile.am
|
|
|
ee8720 |
+++ b/utils/Makefile.am
|
|
|
ee8720 |
@@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in
|
|
|
ee8720 |
|
|
|
ee8720 |
ACLOCAL_AMFLAGS = -I m4
|
|
|
ee8720 |
|
|
|
ee8720 |
-AM_CFLAGS = -I${top_srcdir}/include
|
|
|
ee8720 |
+AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE
|
|
|
ee8720 |
|
|
|
ee8720 |
ndptool_LDADD = $(top_builddir)/libndp/libndp.la
|
|
|
ee8720 |
|
|
|
ee8720 |
diff --git a/utils/Makefile.in b/utils/Makefile.in
|
|
|
ee8720 |
index e339b19..d81de50 100644
|
|
|
ee8720 |
--- a/utils/Makefile.in
|
|
|
ee8720 |
+++ b/utils/Makefile.in
|
|
|
ee8720 |
@@ -294,7 +294,7 @@ top_builddir = @top_builddir@
|
|
|
ee8720 |
top_srcdir = @top_srcdir@
|
|
|
ee8720 |
MAINTAINERCLEANFILES = Makefile.in
|
|
|
ee8720 |
ACLOCAL_AMFLAGS = -I m4
|
|
|
ee8720 |
-AM_CFLAGS = -I${top_srcdir}/include
|
|
|
ee8720 |
+AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE
|
|
|
ee8720 |
ndptool_LDADD = $(top_builddir)/libndp/libndp.la
|
|
|
ee8720 |
ndptool_SOURCES = ndptool.c
|
|
|
ee8720 |
all: all-am
|
|
|
ee8720 |
diff --git a/utils/ndptool.c b/utils/ndptool.c
|
|
|
ee8720 |
index 662ff01..618f167 100644
|
|
|
ee8720 |
--- a/utils/ndptool.c
|
|
|
ee8720 |
+++ b/utils/ndptool.c
|
|
|
ee8720 |
@@ -28,7 +28,7 @@
|
|
|
ee8720 |
#include <arpa/inet.h>
|
|
|
ee8720 |
#include <errno.h>
|
|
|
ee8720 |
#include <ndp.h>
|
|
|
ee8720 |
-#include <sys/select.h>
|
|
|
ee8720 |
+#include <poll.h>
|
|
|
ee8720 |
|
|
|
ee8720 |
enum verbosity_level {
|
|
|
ee8720 |
VERB1,
|
|
|
ee8720 |
@@ -59,13 +59,10 @@ static void empty_signal_handler(int signal)
|
|
|
ee8720 |
|
|
|
ee8720 |
static int run_main_loop(struct ndp *ndp)
|
|
|
ee8720 |
{
|
|
|
ee8720 |
- fd_set rfds;
|
|
|
ee8720 |
- fd_set rfds_tmp;
|
|
|
ee8720 |
- int fdmax;
|
|
|
ee8720 |
+ struct pollfd pfd;
|
|
|
ee8720 |
int ret;
|
|
|
ee8720 |
struct sigaction siginfo;
|
|
|
ee8720 |
sigset_t mask;
|
|
|
ee8720 |
- int ndp_fd;
|
|
|
ee8720 |
int err = 0;
|
|
|
ee8720 |
|
|
|
ee8720 |
sigemptyset(&siginfo.sa_mask);
|
|
|
ee8720 |
@@ -100,23 +97,22 @@ static int run_main_loop(struct ndp *ndp)
|
|
|
ee8720 |
|
|
|
ee8720 |
sigemptyset(&mask);
|
|
|
ee8720 |
|
|
|
ee8720 |
- FD_ZERO(&rfds);
|
|
|
ee8720 |
- ndp_fd = ndp_get_eventfd(ndp);
|
|
|
ee8720 |
- FD_SET(ndp_fd, &rfds);
|
|
|
ee8720 |
- fdmax = ndp_fd + 1;
|
|
|
ee8720 |
+ pfd = (struct pollfd) {
|
|
|
ee8720 |
+ .fd = ndp_get_eventfd(ndp),
|
|
|
ee8720 |
+ .events = POLLIN,
|
|
|
ee8720 |
+ };
|
|
|
ee8720 |
|
|
|
ee8720 |
for (;;) {
|
|
|
ee8720 |
- rfds_tmp = rfds;
|
|
|
ee8720 |
- ret = pselect(fdmax, &rfds_tmp, NULL, NULL, NULL, &mask);
|
|
|
ee8720 |
+ ret = ppoll(&pfd, 1, NULL, &mask);
|
|
|
ee8720 |
if (ret == -1) {
|
|
|
ee8720 |
if (errno == EINTR) {
|
|
|
ee8720 |
goto out;
|
|
|
ee8720 |
}
|
|
|
ee8720 |
- pr_err("Select failed\n");
|
|
|
ee8720 |
+ pr_err("Poll failed\n");
|
|
|
ee8720 |
err = -errno;
|
|
|
ee8720 |
goto out;
|
|
|
ee8720 |
}
|
|
|
ee8720 |
- if (FD_ISSET(ndp_fd, &rfds_tmp)) {
|
|
|
ee8720 |
+ if (pfd.revents & POLLIN) {
|
|
|
ee8720 |
err = ndp_call_eventfd_handler(ndp);
|
|
|
ee8720 |
if (err) {
|
|
|
ee8720 |
pr_err("ndp eventfd handler call failed\n");
|
|
|
ee8720 |
--
|
|
|
ee8720 |
2.26.2
|
|
|
ee8720 |
|