From d63272ddfed20d14d14af9aa698def811871be26 Mon Sep 17 00:00:00 2001 From: kellyyeh <42761586+kellyyeh@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:03:42 -0800 Subject: [PATCH 1/2] Set to max buffer size --- src/relay.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/relay.cpp b/src/relay.cpp index 82735d4..fb04fc3 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -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); * @@ -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; } From 01c45269bf0e9c7656f271107aa24dc477e1c89a Mon Sep 17 00:00:00 2001 From: kellyyeh <42761586+kellyyeh@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:05:07 -0800 Subject: [PATCH 2/2] Update relay.cpp --- src/relay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/relay.cpp b/src/relay.cpp index fb04fc3..0d5fedf 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -540,7 +540,7 @@ int prepare_raw_socket(const struct sock_fprog *fprog) 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, "setsockopt: change raw socket recv buffer size from %d to %d\n", optval, maxBufferSize); } }