Skip to content

Commit

Permalink
increase socket buffer size for firemon, bug #2700
Browse files Browse the repository at this point in the history
  • Loading branch information
netblue30 committed Sep 29, 2019
1 parent 0fa479a commit bef5d86
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/firemon/firemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sys/stat.h>

pid_t skip_process = 0;
int arg_debug = 0;
static int arg_route = 0;
static int arg_arp = 0;
static int arg_tree = 0;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/firemon/firemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
31 changes: 25 additions & 6 deletions src/firemon/procevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/firemon/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/man/firemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bef5d86

Please sign in to comment.