Skip to content
Open

Test #18

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/dhcp_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libexplain/ioctl.h>
#include <linux/filter.h>
#include <netpacket/packet.h>
#include <fstream>
#include "subscriberstatetable.h"
#include "select.h"

Expand Down Expand Up @@ -920,6 +921,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 @@ -969,6 +986,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