Try using SO_RCVBUF if SO_RCVBUFFORCE fails
When running in a container, the process might not have the
CAP_NET_ADMIN capability, which would cause setting the SO_RCVBUFFORCE
socket option to fail. But rmem_max is set to a high enough value which
allows SO_RCVBUF to succeed.
This patch tries with SO_RCVBUF after attempting to use SO_RCVBUFFORCE.
Bug: 62417946
Test: netd no longer asserts
Change-Id: I02c5f22ba7af62e8c5c5c8b176cea9aef89d84f8
(cherry picked from commit b41155d4af0e00fc6f65d7d67b80e7b866f847d6)
diff --git a/server/NetlinkManager.cpp b/server/NetlinkManager.cpp
index 698de9f..0a10b0c 100644
--- a/server/NetlinkManager.cpp
+++ b/server/NetlinkManager.cpp
@@ -86,8 +86,12 @@
return NULL;
}
- if (setsockopt(*sock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0) {
- ALOGE("Unable to set uevent socket SO_RCVBUFFORCE option: %s", strerror(errno));
+ // When running in a net/user namespace, SO_RCVBUFFORCE will fail because
+ // it will check for the CAP_NET_ADMIN capability in the root namespace.
+ // Try using SO_RCVBUF if that fails.
+ if (setsockopt(*sock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0 &&
+ setsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)) < 0) {
+ ALOGE("Unable to set uevent socket SO_RCVBUF option: %s", strerror(errno));
close(*sock);
return NULL;
}