Skip to content

Commit

Permalink
nfnetlink: allow specifying the socket buffer size
Browse files Browse the repository at this point in the history
Allow the user to specify the socket buffer size and increase the default
to 512KB.

Signed-off-by: Jo-Philipp Wich <[email protected]>
  • Loading branch information
jow- committed Apr 10, 2020
1 parent 33c77cb commit e757e06
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion nfnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ handle_ack(struct nl_msg *msg, void *arg)


int
nfnetlink_connect(void)
nfnetlink_connect(int bufsize)
{
nl = nl_socket_alloc();

Expand All @@ -354,6 +354,9 @@ nfnetlink_connect(void)
NFNLGRP_CONNTRACK_DESTROY, 0))
return -errno;

if (nl_socket_set_buffer_size(nl, bufsize, 0))
return -errno;

ufd.cb = handle_event;
ufd.fd = nl_socket_get_fd(nl);

Expand Down
2 changes: 1 addition & 1 deletion nfnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "database.h"


int nfnetlink_connect(void);
int nfnetlink_connect(int bufsize);
int nfnetlink_dump(bool allow_insert);

#endif /* __NFNETLINK_H__ */
15 changes: 13 additions & 2 deletions nlbwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct options opt = {
.commit_interval = 86400,
.refresh_interval = 30,

.netlink_buffer_size = 524288,

.tempdir = "/tmp",
.socket = "/var/run/nlbwmon.sock",
.protocol_db = "/usr/share/nlbwmon/protocols",
Expand Down Expand Up @@ -203,8 +205,17 @@ server_main(int argc, char **argv)
int optchr, err;
char *e;

while ((optchr = getopt(argc, argv, "i:r:s:o:p:G:I:L:PZ")) > -1) {
while ((optchr = getopt(argc, argv, "b:i:r:s:o:p:G:I:L:PZ")) > -1) {
switch (optchr) {
case 'b':
opt.netlink_buffer_size = (int)strtol(optarg, &e, 0);
if (e == optarg || *e || opt.netlink_buffer_size < 32768) {
fprintf(stderr, "Invalid netlink buffer size '%s'\n",
optarg);
return 1;
}
break;

case 'i':
err = parse_timearg(optarg, &opt.commit_interval);
if (err) {
Expand Down Expand Up @@ -321,7 +332,7 @@ server_main(int argc, char **argv)
exit(1);
}

err = nfnetlink_connect();
err = nfnetlink_connect(opt.netlink_buffer_size);

if (err) {
fprintf(stderr, "Unable to connect nfnetlink: %s\n",
Expand Down
2 changes: 2 additions & 0 deletions nlbwmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct options {
time_t refresh_interval;
struct interval archive_interval;

int netlink_buffer_size;

const char *protocol_db;
const char *tempdir;
const char *socket;
Expand Down

0 comments on commit e757e06

Please sign in to comment.