From bef5d86a10ec8f75fe341abb6ad58948107ec56e Mon Sep 17 00:00:00 2001 From: netblue30 Date: Sun, 29 Sep 2019 19:03:16 -0400 Subject: increase socket buffer size for firemon, bug #2700 --- src/firemon/firemon.c | 4 +++- src/firemon/firemon.h | 3 +++ src/firemon/procevent.c | 31 +++++++++++++++++++++++++------ src/firemon/usage.c | 1 + src/man/firemon.txt | 3 +++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/firemon/firemon.c b/src/firemon/firemon.c index b3c435d9e..dad3b0afb 100644 --- a/src/firemon/firemon.c +++ b/src/firemon/firemon.c @@ -26,6 +26,7 @@ #include pid_t skip_process = 0; +int arg_debug = 0; static int arg_route = 0; static int arg_arp = 0; static int arg_tree = 0; @@ -142,7 +143,8 @@ int main(int argc, char **argv) { printf("firemon version %s\n\n", VERSION); return 0; } - + else if (strcmp(argv[i], "--debug") == 0) + arg_debug = 1; // options without a pid argument else if (strcmp(argv[i], "--top") == 0) arg_top = 1; diff --git a/src/firemon/firemon.h b/src/firemon/firemon.h index 2e5647c2f..7f8bc698c 100644 --- a/src/firemon/firemon.h +++ b/src/firemon/firemon.h @@ -29,6 +29,9 @@ #include "../include/pid.h" #include "../include/common.h" +// main.c +extern int arg_debug; + // clear screen static inline void firemon_clrscr(void) { printf("\033[2J\033[1;1H"); diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c index b79f12362..762d22514 100644 --- a/src/firemon/procevent.c +++ b/src/firemon/procevent.c @@ -173,6 +173,20 @@ static int procevent_netlink_setup(void) { if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) goto errexit; + // set a large socket rx buffer + // the regular default value as set in /proc/sys/net/core/rmem_default will fill the + // buffer much quicker than we can process it + int bsize = 1024 * 1024; // 1MB + socklen_t blen = sizeof(int); + if (setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &bsize, blen) == -1) + fprintf(stderr, "Warning: cannot set rx buffer size, using default system value\n"); + else if (arg_debug) { + if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bsize, &blen) == -1) + fprintf(stderr, "Error: cannot read rx buffer size\n"); + else + printf("rx buffer size %d\n", bsize / 2); // the value returned is duble the real one, see man 7 socket + } + // send monitoring message struct nlmsghdr nlmsghdr; memset(&nlmsghdr, 0, sizeof(nlmsghdr)); @@ -244,14 +258,19 @@ static int procevent_monitor(const int sock, pid_t mypid) { } - if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) { + if ((len = recv(sock, buf, sizeof(buf), 0)) == 0) return 0; - } if (len == -1) { - if (errno == EINTR) { - return 0; - } else { - fprintf(stderr,"recv: %s\n", strerror(errno)); + if (errno == EINTR) + continue; + else if (errno == ENOBUFS) { + // rx buffer is full, the kernel started dropping messages + printf("*** Waning *** - message burst received, not all events are printed\n"); +//return -1; + continue; + } + else { + fprintf(stderr,"Error: rx socket recv call, errno %d, %s\n", errno, strerror(errno)); return -1; } } diff --git a/src/firemon/usage.c b/src/firemon/usage.c index 3b9fe96c0..196fc32c3 100644 --- a/src/firemon/usage.c +++ b/src/firemon/usage.c @@ -31,6 +31,7 @@ static char *help_str = "\t--caps - print capabilities configuration for each sandbox.\n\n" "\t--cgroup - print control group information for each sandbox.\n\n" "\t--cpu - print CPU affinity for each sandbox.\n\n" + "\t--debug - print debug messages.\n\n" "\t--help, -? - this help screen.\n\n" "\t--interface - print network interface information for each sandbox.\n\n" "\t--list - list all sandboxes.\n\n" diff --git a/src/man/firemon.txt b/src/man/firemon.txt index 214fcac44..40a00ec3f 100644 --- a/src/man/firemon.txt +++ b/src/man/firemon.txt @@ -25,6 +25,9 @@ Print control group information for each sandbox. \fB\-\-cpu Print CPU affinity for each sandbox. .TP +\fB\-\-debug +Print debug messages +.TP \fB\-?\fR, \fB\-\-help\fR Print options end exit. .TP -- cgit v1.2.3-54-g00ecf