From: Otto Date: Fri, 5 Mar 2021 12:15:13 +0000 (+0100) Subject: sdig: implement TCP Fast Open for DoH X-Git-Tag: rec-4.5.0-alpha3~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5923e7674e0674553f9f9dd77138a16fcb9980d4;p=thirdparty%2Fpdns.git sdig: implement TCP Fast Open for DoH While at it, honour timeout parameter as well for DoT. --- diff --git a/pdns/minicurl.cc b/pdns/minicurl.cc index 68ad5f5e20..fff3636ff3 100644 --- a/pdns/minicurl.cc +++ b/pdns/minicurl.cc @@ -74,7 +74,7 @@ static string extractHostFromURL(const std::string& url) return url.substr(pos, endpos-pos); } -void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const ComboAddress* src, int timeout) +void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const ComboAddress* src, int timeout, bool fastopen) { if(rem) { struct curl_slist *hostlist = nullptr; // THIS SHOULD BE FREED @@ -112,6 +112,7 @@ void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const C curl_easy_setopt(d_curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(d_curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(d_curl, CURLOPT_TIMEOUT, static_cast(timeout)); + curl_easy_setopt(d_curl, CURLOPT_TCP_FASTOPEN, fastopen); clearHeaders(); d_data.clear(); @@ -132,9 +133,9 @@ std::string MiniCurl::getURL(const std::string& str, const ComboAddress* rem, co return ret; } -std::string MiniCurl::postURL(const std::string& str, const std::string& postdata, MiniCurlHeaders& headers, int timeout) +std::string MiniCurl::postURL(const std::string& str, const std::string& postdata, MiniCurlHeaders& headers, int timeout, bool fastopen) { - setupURL(str, nullptr, nullptr, timeout); + setupURL(str, nullptr, nullptr, timeout, fastopen); setHeaders(headers); curl_easy_setopt(d_curl, CURLOPT_POSTFIELDSIZE, postdata.size()); curl_easy_setopt(d_curl, CURLOPT_POSTFIELDS, postdata.c_str()); diff --git a/pdns/minicurl.hh b/pdns/minicurl.hh index 50b144a1cf..c2550d6bd2 100644 --- a/pdns/minicurl.hh +++ b/pdns/minicurl.hh @@ -39,13 +39,13 @@ public: ~MiniCurl(); MiniCurl& operator=(const MiniCurl&) = delete; std::string getURL(const std::string& str, const ComboAddress* rem=nullptr, const ComboAddress* src=nullptr, int timeout = 2); - std::string postURL(const std::string& str, const std::string& postdata, MiniCurlHeaders& headers, int timeout = 2); + std::string postURL(const std::string& str, const std::string& postdata, MiniCurlHeaders& headers, int timeout = 2, bool fastopen = false); private: CURL *d_curl; static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata); std::string d_data; struct curl_slist* d_header_list = nullptr; - void setupURL(const std::string& str, const ComboAddress* rem=nullptr, const ComboAddress* src=nullptr, int timeout = 2); + void setupURL(const std::string& str, const ComboAddress* rem=nullptr, const ComboAddress* src=nullptr, int timeout = 2, bool fastopen = false); void setHeaders(const MiniCurlHeaders& headers); void clearHeaders(); }; diff --git a/pdns/sdig.cc b/pdns/sdig.cc index c36e22ae23..dee241d2ae 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -376,7 +376,7 @@ try { mch.insert(std::make_pair("Accept", "application/dns-message")); string question(packet.begin(), packet.end()); // FIXME: how do we use proxyheader here? - reply = mc.postURL(argv[1], question, mch); + reply = mc.postURL(argv[1], question, mch, timeout, fastOpen); printReply(reply, showflags, hidesoadetails); #else throw PDNSException("please link sdig against libcurl for DoH support");