Skip to content

Commit

Permalink
Set to max buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyyeh authored Mar 2, 2024
1 parent 5ae186f commit d63272d
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,22 @@ const struct dhcpv6_relay_msg *parse_dhcpv6_relay(const uint8_t *buffer) {
return (const struct dhcpv6_relay_msg *)buffer;
}

/**
* @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 prepare_raw_socket(const struct sock_fprog *fprog);
*
Expand Down Expand Up @@ -516,12 +532,18 @@ int prepare_raw_socket(const struct sock_fprog *fprog)
return -1;
}

int optval_new = RAWSOCKET_RECV_SIZE;
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &optval_new, sizeof(optval_new)) == -1) {
syslog(LOG_WARNING, "setsockopt: Failed to set recv buffer size to %d, use default value\n", optval_new);
} else {
syslog(LOG_INFO, "setsockopt: change raw socket recv buffer size from %d to %d\n", optval, optval_new);
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(s, SOL_SOCKET, SO_RCVBUF, &maxBufferSize, sizeof(maxBufferSize)) == -1) {
syslog(LOG_ALERT, "setsockopt: failed to set rcvbuf size '%s'\n", strerror(errno));
} else {
syslog(LOG_INFO, "setsockopt: change raw socket recv buffer size from %d to %d\n", optval, maxBufferSize);
}
}

syslog(LOG_INFO, "RAW Socket:%d successfully initialized !!!\n", s);
return s;
}
Expand Down

0 comments on commit d63272d

Please sign in to comment.