]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BSD: Turn on SO_RERROR for all sockets
authorRoy Marples <roy@marples.name>
Tue, 22 Jan 2019 14:51:42 +0000 (14:51 +0000)
committerRoy Marples <roy@marples.name>
Tue, 22 Jan 2019 14:51:42 +0000 (14:51 +0000)
So we can detect IPv6ND or DHCPv6 overflow as well as route(4)
overflow.

src/if-bsd.c
src/if.c

index facc945c2cdbe28152c76007c794f305ce47aed3..e4c95765b509d6fcffa763a5707b59515b733e6c 100644 (file)
@@ -170,16 +170,6 @@ if_opensockets_os(struct dhcpcd_ctx *ctx)
            &n, sizeof(n)) == -1)
                logerr("%s: SO_USELOOPBACK", __func__);
 
-#ifdef SO_RERROR
-       /* Tell recvmsg(2) to return ENOBUFS if the receiving socket overflows
-        * from too many route(4) messages so we can re-sync our state
-        * with reality. */
-       n = 1;
-       if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RERROR,
-           &n, sizeof(n)) == -1)
-               logerr("%s: SO_RERROR", __func__);
-#endif
-
 #if defined(RO_MSGFILTER)
        if (setsockopt(ctx->link_fd, PF_ROUTE, RO_MSGFILTER,
            &msgfilter, sizeof(msgfilter)) == -1)
index 7807d89b93ad036b380a113887907d5d3906834b..2aa281904d4b9021c7b7d8ff827cff3b3d8273ee 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -790,6 +790,9 @@ xsocket(int domain, int type, int protocol)
 #if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
        int xflags, xtype = type;
 #endif
+#ifdef SO_RERROR
+       int on;
+#endif
 
 #ifndef HAVE_SOCK_CLOEXEC
        if (xtype & SOCK_CLOEXEC)
@@ -814,6 +817,13 @@ xsocket(int domain, int type, int protocol)
                goto out;
 #endif
 
+#ifdef SO_RERROR
+       /* Tell recvmsg(2) to return ENOBUFS if the receiving socket overflows. */
+       on = 1;
+       if (setsockopt(s, SOL_SOCKET, SO_RERROR, &on, sizeof(on)) == -1)
+               logerr("%s: SO_RERROR", __func__);
+#endif
+
        return s;
 
 #if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)