From: Otto Date: Fri, 22 Jan 2021 11:25:42 +0000 (+0100) Subject: Warn if fastopen-connect is requested but could not be enabled and adapt X-Git-Tag: rec-4.5.0-beta1^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c33192f32a19dbf400173f97d7c1f1b7e1b120f3;p=thirdparty%2Fpdns.git Warn if fastopen-connect is requested but could not be enabled and adapt 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. --- diff --git a/pdns/sdig.cc b/pdns/sdig.cc index f57da7ef1e..e0b4cf604a 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -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); diff --git a/pdns/sstuff.hh b/pdns/sstuff.hh index 31f3d007b8..ced296ed6e 100644 --- a/pdns/sstuff.hh +++ b/pdns/sstuff.hh @@ -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");