Skip to content

Commit

Permalink
Update buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqiangz committed Mar 5, 2024
1 parent a3c5381 commit 614735c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/dhcp_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <libexplain/ioctl.h>
#include <linux/filter.h>
#include <netpacket/packet.h>
#include <netpacket/packet.h>
#include <fstream>
#include "subscriberstatetable.h"
#include "select.h"

Expand Down Expand Up @@ -750,6 +752,22 @@ int dhcp_device_init(dhcp_device_context_t **context, const char *intf, uint8_t
return rv;
}

/**
* @code getMaxBufferSize();
*
* @get max buffer size from /proc/sys/net/core/rmem_max.
*/
size_t getMaxBufferSize() {
std::ifstream file("/proc/sys/net/core/rmem_max");
int maxBufferSize = 0;
if (file) {
file >> maxBufferSize;
} else {
syslog(LOG_ALERT, "Could not open /proc/sys/net/core/rmem_max");
}
return maxBufferSize;
}

/**
* @code dhcp_device_start_capture(snaplen, base, giaddr_ip);
*
Expand Down Expand Up @@ -798,6 +816,16 @@ int dhcp_device_start_capture(size_t snaplen, struct event_base *base, in_addr_t
exit(1);
}

size_t maxBufferSize = getMaxBufferSize();
if (maxBufferSize == 0) {
syslog(LOG_ALERT, "dhcp_device_start_capture: failed to get max buffer size, using default");
}
else {
if (setsockopt(tx_sock, SOL_SOCKET, SO_RCVBUF, &maxBufferSize, sizeof(maxBufferSize)) == -1) {
syslog(LOG_ALERT, "setsockopt: failed to set rcvbuf size '%s'\n", strerror(errno));
}
}

rx_ev = event_new(base, rx_sock, EV_READ | EV_PERSIST, read_rx_callback, &intfs);
tx_ev = event_new(base, tx_sock, EV_READ | EV_PERSIST, read_tx_callback, &intfs);

Expand Down

0 comments on commit 614735c

Please sign in to comment.