]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Warn if fastopen-connect is requested but could not be enabled and adapt
authorOtto <otto.moerbeek@open-xchange.com>
Fri, 22 Jan 2021 11:25:42 +0000 (12:25 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 24 Mar 2021 10:14:23 +0000 (11:14 +0100)
sdig to work using tcp using a socket in non-blocking mode.

A fix was needed in the write logic for OpenBSD: We need to call
writenWithTimeout(), since OpenBSD does not allow to write to a
non-blocking socket that isn't connected yet. Additionally
writenWithTimeout() need to take into account that ENOTCONN can be
returned in that case.

pdns/sdig.cc
pdns/sstuff.hh

index f57da7ef1ee1413a892a87e232bcdb463029e67f..e0b4cf604ad488f99cc2c9bd443e8d21f6ffd19e 100644 (file)
@@ -38,14 +38,9 @@ static void usage()
 {
   cerr << "sdig" << endl;
   cerr << "Syntax: sdig IP-ADDRESS-OR-DOH-URL PORT QNAME QTYPE "
-<<<<<<< HEAD
           "[dnssec] [ednssubnet SUBNET/MASK] [hidesoadetails] [hidettl] [recurse] [showflags] "
           "[tcp] [dot] [insecure] [fastOpen] [subjectName name] [caStore file] [tlsProvider openssl|gnutls] "
           "[xpf XPFDATA] [class CLASSNUM] "
-=======
-          "[dnssec] [ednssubnet SUBNET/MASK] [hidesoadetails] [hidettl] "
-          "[recurse] [showflags] [tcp] [fastopen] [xpf XPFDATA] [class CLASSNUM] "
->>>>>>> 5b8fccd32 (sdig now works with fastopen)
           "[proxy UDP(0)/TCP(1) SOURCE-IP-ADDRESS-AND-PORT DESTINATION-IP-ADDRESS-AND-PORT]"
           "dumpluaraw"
        << endl;
@@ -268,7 +263,6 @@ try {
         hidettl = true;
       else if (strcmp(argv[i], "tcp") == 0)
         tcp = true;
-<<<<<<< HEAD
       else if (strcmp(argv[i], "dot") == 0)
         dot = true;
       else if (strcmp(argv[i], "insecure") == 0)
@@ -276,11 +270,6 @@ try {
       else if (strcmp(argv[i], "fastOpen") == 0)
         fastOpen = true;
       else if (strcmp(argv[i], "ednssubnet") == 0) {
-=======
-      if (strcmp(argv[i], "fastopen") == 0)
-        fastopen = true;
-      if (strcmp(argv[i], "ednssubnet") == 0) {
->>>>>>> 5b8fccd32 (sdig now works with fastopen)
         if (argc < i + 2) {
           cerr << "ednssubnet needs an argument" << endl;
           exit(EXIT_FAILURE);
index 31f3d007b8a5a182951a81d817e84ad3b6a95b99..ced296ed6e2c35c1d681451adcef0ac3ab3f3a64 100644 (file)
@@ -132,8 +132,11 @@ public:
   {
 #ifdef TCP_FASTOPEN_CONNECT
     int on = 1;
-    if (setsockopt(d_socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &on, sizeof(on)) < 0)
+    if (setsockopt(d_socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &on, sizeof(on)) < 0) {
       throw NetworkError("While setting TCP_FASTOPEN_CONNECT: " + stringerror());
+    }
+#else
+   throw NetworkError("While setting TCP_FASTOPEN_CONNECT: not compiled in");
 #endif
   }
 
@@ -276,7 +279,9 @@ public:
     while(bytes) {
       ret=::write(d_socket, ptr, bytes);
       if(ret < 0) {
-        if(errno==EAGAIN) {
+        // some systems (e.g. OpenBSD) return ENOTCONN on non-blocking sockets on which connect *has been* called
+        // we have to wait for the opportunity to write after the connect is done
+        if (errno == EAGAIN || errno == ENOTCONN) {
           ret=waitForRWData(d_socket, false, timeout, 0);
           if(ret < 0)
             throw NetworkError("Waiting for data write");