]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
connect: on linux, enable reporting of all ICMP errors on UDP sockets
authorCristian Rodríguez <crodriguez@owncloud.com>
Thu, 17 Dec 2020 14:27:03 +0000 (11:27 -0300)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 21 Dec 2020 14:24:08 +0000 (15:24 +0100)
The linux kernel does not report all ICMP errors back to userspace due
to historical reasons.

IP*_RECVERR sockopt must be turned on to have the correct behaviour
which is to pass all ICMP errors to userspace.

See https://bugzilla.kernel.org/show_bug.cgi?id=202355

Closes #6341

lib/connect.c

index 251145ce18c3502866a2d50696258ba4f0902038..f7aa26019906d12d95760617b46337598ee00e62 100644 (file)
@@ -1574,6 +1574,20 @@ CURLcode Curl_socket(struct connectdata *conn,
   }
 #endif
 
+#if defined(__linux__) && defined(IP_RECVERR)
+  if(addr->socktype == SOCK_DGRAM) {
+    int one = 1;
+    switch(addr->family) {
+      case AF_INET:
+        setsockopt(*sockfd, SOL_IP, IP_RECVERR, &one, sizeof(one));
+        break;
+      case AF_INET6:
+        setsockopt(*sockfd, SOL_IPV6, IPV6_RECVERR, &one, sizeof(one));
+        break;
+    }
+  }
+#endif
+
   return CURLE_OK;
 
 }