Skip to content

Commit

Permalink
fix libcurl problem with HTTP/2.0
Browse files Browse the repository at this point in the history
Google DNS use HTTP/2.0 and some versions of libcurl
fail to handle it correctly. Force libcurl to use HTTP/1.1 for now.
  • Loading branch information
kamarya committed Feb 8, 2020
1 parent e3adc07 commit fe0ab2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion inc/dnssec.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#define PIDFILE "/var/run/dnsd.pid"

#define LICENSE "DNSd Copyright (C) 2016 Behrooz Kamary Aliabadi.\n"\
#define LICENSE "DNSd Copyright (C) 2016 Behrooz Kamary.\n"\
"This program comes with ABSOLUTELY NO WARRANTY. \n"\
"You should have received a copy of the GNU General Public License\n"\
"along with this program. If not, see <http://www.gnu.org/licenses/>."
Expand Down
28 changes: 18 additions & 10 deletions src/dnssec.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ size_t body_callback (void* contents, size_t size, size_t nmemb, void* userp)
return chunk;
}

void https_query (struct dns_query* query)
int https_query (struct dns_query* query)
{

CURL* curl;
Expand Down Expand Up @@ -197,6 +197,10 @@ void https_query (struct dns_query* query)
// do not check the SSL certificate authenticity
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

// failed to work with libcurl/7.65.3 and HTTP/2.0
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

curl_easy_setopt(curl, CURLOPT_TIMEOUT, options.server_timeout);

if (options.https_proxy[0])
Expand All @@ -211,17 +215,21 @@ void https_query (struct dns_query* query)

res = curl_easy_perform(curl);

curl_easy_cleanup(curl);
curl_slist_free_all(headers);
LOG_DEBUG("curl_easy_perform() has returned.");

if (res != CURLE_OK)
{
LOG_ERROR("curl_easy_perform() failed: %s", curl_easy_strerror(res));
return EXIT_FAILURE;
}

curl_easy_cleanup(curl);
curl_slist_free_all(headers);
LOG_DEBUG("curl_easy_perform() has returned.");
return EXIT_SUCCESS;
}

curl_global_cleanup();

return EXIT_FAILURE;
}

int server()
Expand Down Expand Up @@ -351,11 +359,11 @@ int server()
// TODO support multiple questions; however it seems others don't.
if (ntohs(header->q_count) == 1)
{
https_query(&query);

char* answer = (char *)(buffer + sizeof(struct dns_question) + sizeof(struct dns_header) + dnlen + 1);

answer_length = json_to_answer(answer, header, max_len);
if (https_query(&query) == EXIT_SUCCESS)
{
char* answer = (char *)(buffer + sizeof(struct dns_question) + sizeof(struct dns_header) + dnlen + 1);
answer_length = json_to_answer(answer, header, max_len);
}
}

if (!answer_length)
Expand Down

0 comments on commit fe0ab2a

Please sign in to comment.