shill: Increase receive buffer size for RTNL socket

We have seen some rare but nasty occurences of ENOBUFS errors on shill's
RTNL socket. While it is hard to say how exactly those errors come to
pass, we hope to be able to mitigate them by increasing the socket's
receive buffer size.

As an ancient kernel bug (http://marc.info/?m=134860874327843) currently
makes it default to a low hard limit on receive buffer size, we need to
leverage our root UID by using SO_RCVBUFFORCE.

BUG=chromium-os:36328
TEST=None

Change-Id: I5ac21e69d64a8e09a24b4c25152a51d61b5844e1
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40042
Reviewed-by: Paul Stewart <pstew@chromium.org>
diff --git a/rtnl_handler.cc b/rtnl_handler.cc
index 647a4a4..0587f5b 100644
--- a/rtnl_handler.cc
+++ b/rtnl_handler.cc
@@ -35,6 +35,9 @@
 
 namespace shill {
 
+// Keep this large enough to avoid overflows on IPv6 SNM routing update spikes
+const int RTNLHandler::kReceiveBufferSize = 256 * 1024;
+
 namespace {
 base::LazyInstance<RTNLHandler> g_rtnl_handler = LAZY_INSTANCE_INITIALIZER;
 }  // namespace
@@ -72,6 +75,10 @@
     return;
   }
 
+  if (sockets->SetReceiveBuffer(rtnl_socket_, kReceiveBufferSize)) {
+    LOG(ERROR) << "Failed to increase receive buffer size";
+  }
+
   memset(&addr, 0, sizeof(addr));
   addr.nl_family = AF_NETLINK;
   addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE |