Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Test #47

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
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
Loading