Skip to content

setopt: add CURLOPT_DOH_URL - #2668

Closed
bagder wants to merge 4 commits into
masterfrom
bagder/DOH
Closed

bagder wants to merge 4 commits into
masterfrom
bagder/DOH

Conversation

@bagder

@bagder bagder commented Jun 18, 2018 •

Copy link
Copy Markdown
Member

Support for DNS-over-HTTPS for name resolving when doing transfers.

Complies with dns-over-https-14, tested a bit against the cloudflare end-point.

Wiki page with status, TODO and more.

This is still early days.

simplest example:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://curl.haxx.se/");
    curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://dns.cloudflare.com/dns-query");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}

@bagder bagder added on-hold feature-window A merge of this requires an open feature window labels Jun 18, 2018
@bagder
bagder force-pushed the bagder/DOH branch 3 times, most recently from 6bf97fc to eca3d0b Compare June 24, 2018 21:21
@bagder bagder added the name lookup DNS and related tech label Jun 26, 2018
@bagder bagder changed the title setopt: add CURLOPT_DOH_URL [WIP] setopt: add CURLOPT_DOH_URL Jun 27, 2018
@bagder bagder removed the on-hold label Jun 27, 2018

@danielgustafsson danielgustafsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few scattered comments from skimming the code.

Comment thread lib/doh.c Outdated

static const char *doh_strerror(DOHcode code)
{
return errors[code];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this do bounds checking? While not at risk in the current coding, belts are stylish when coupled with suspenders..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're totally correct of course. I'll fix!

Comment thread lib/doh.c
result = CURLE_OUT_OF_MEMORY;
goto error;
}
p->serverdoh.size = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be set to 1 per the above allocation? (the addition in doh_write_cb() relies on this being "incorrect" but that seems a bit magic) On that note, is there a reason to allocate 1 rather than use a NULL ptr to indicate "reallocation required" since realloc() on a NULL ptr is identical to malloc()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right on the size assign. But I think it should rather allocate a sensible default size that can make it avoid the realloc in typical responses. I'll make it a 100 bytes I think.

Comment thread docs/libcurl/opts/CURLOPT_DOH_URL.3 Outdated
heap space.

Note that \fIcurl_easy_setopt(3)\fP won't actually parse the given string so
given a bad DOH URL, curl will not be detected a problem until it tries to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intended to say "will not detect a problem"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Comment thread lib/doh.c Outdated
}

#define ERROR_CHECK_SETOPT(x,y) result = curl_easy_setopt(doh, x, y); \
if(result) goto error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger -Wextra-semi warnings with clang.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix!

Comment thread lib/urldata.h Outdated
size_t size;
};

/* one of these for each DOH HTTP request */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but should this say "DOH HTTPS request"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or perhaps just "each DoH request" ...

@bagder

bagder commented Sep 1, 2018

Copy link
Copy Markdown
Member Author

The short name of the protocol became DoH while this patch was in development, I'm changing source comments to use the new abbreviation.

Comment thread lib/doh.c Resolved
Comment thread lib/doh.c Resolved
@danielgustafsson

danielgustafsson commented Sep 4, 2018 via email

Copy link
Copy Markdown
Contributor

@bagder bagder closed this in abff183 Sep 6, 2018
@bagder
bagder deleted the bagder/DOH branch September 6, 2018 07:18
@bagder bagder removed the feature-window A merge of this requires an open feature window label Sep 6, 2018
@lock lock Bot locked as resolved and limited conversation to collaborators Dec 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

name lookup DNS and related tech

Development

Successfully merging this pull request may close these issues.

3 participants