Skip to content

c-ares resolver: add option to use nameservers as fallback#19010

Merged
junr03 merged 23 commits intomainfrom
c-ares-fallback-nameservers
Dec 14, 2021
Merged

c-ares resolver: add option to use nameservers as fallback#19010
junr03 merged 23 commits intomainfrom
c-ares-fallback-nameservers

Conversation

@junr03
Copy link
Copy Markdown
Member

@junr03 junr03 commented Nov 15, 2021

Commit Message: c-ares resolver: add option to use name servers as fallback.
Risk Level: low - opt in behavior
Testing: existing and additional tests
Docs Changes: added
Release Notes: added

Signed-off-by: Jose Nino jnino@lyft.com

Signed-off-by: Jose Nino <jnino@lyft.com>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #19010 was opened by junr03.

see: more, trace.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #19010 was opened by junr03.

see: more, trace.

Jose Nino added 7 commits November 17, 2021 16:05
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03 junr03 marked this pull request as ready for review November 30, 2021 21:27
@junr03 junr03 requested a review from yanavlasov as a code owner November 30, 2021 21:27
Jose Nino added 3 commits November 30, 2021 13:28
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 2, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19010 (comment) was created by @junr03.

see: more, trace.

Signed-off-by: Jose Nino <jnino@lyft.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, some small comments as a first pass.

/wait

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 3, 2021

@mattklein123 updated! I cleaned up with a variant. I think usage is clearer now.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks some more comments.

/wait

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 6, 2021

/wait

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 6, 2021

/wait

Signed-off-by: Jose Nino <jnino@lyft.com>
Jose Nino added 2 commits December 8, 2021 09:19
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 8, 2021

This test made me realize the original implementation only worked on Android but not a general posix system. I have moved to an alternate implementation that uses c-ares' default (loopback) as a sentinel value for deciding if the fallback resolvers should be used.

A nice side effect is that I was able to do this using the c-ares API used for overriding resolvers so the code is generally simpler.

Jose Nino added 2 commits December 8, 2021 11:40
Signed-off-by: Jose Nino <jnino@lyft.com>
fix
Signed-off-by: Jose Nino <jnino@lyft.com>
Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks this looks good to me for the most part, a few comments

Comment on lines +29 to +31
// Otherwise, the resolvers listed in the resolvers list will override the default system
// resolvers. Defaults to false.
bool use_resolvers_as_fallback = 3;
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.

Just sanity checking: leaving this as false means the behavior of setting resolvers is unchanged yes?

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

Comment on lines +91 to +93
const bool ret = servers == nullptr || (servers->next == nullptr && servers->family == AF_INET &&
servers->addr.addr4.s_addr == htonl(INADDR_LOOPBACK) &&
servers->udp_port == 0 && servers->tcp_port == 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.

For my understanding what kind of nameserver is this? Is it actually useful for resolving names or just a sentinel?

Copy link
Copy Markdown
Member Author

@junr03 junr03 Dec 9, 2021

Choose a reason for hiding this comment

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

it is loopback on port 0. Which is what ares sets in init_by_defaults. So extremely likely not useful, I actually wish that c-ares defaulted to returning an error code instead of "init by default". It doesn't preclude someone from setting up a DNS name server on loopback on a different port.

Comment on lines +423 to +424
// Given that the local machine will have a working conf in resolve.conf the resolver will not
// use the fallback given.
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.

Any way to test the inverse? A case where we'll use the fallback

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.

I tried for a bit, but couldn't defeat all the fallbacks available on linux, i.e., I was not able to break the machine enough to get to init_by_defaults.

FWIW I have tested on android where the fallback is used. I can try to see if I can get there with a unit test again.

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 9, 2021

Thanks @snowp, updated!

@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 9, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19010 (comment) was created by @junr03.

see: more, trace.

Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 13, 2021

@lizan @htuch do you mind re-approving for API? Matt was ok with API earlier, but I needed to iterate on implementation a couple times.

@lizan
Copy link
Copy Markdown
Member

lizan commented Dec 14, 2021

/lgtm api

@junr03 junr03 dismissed mattklein123’s stale review December 14, 2021 23:52

got and updated approval from @snowp

@junr03 junr03 merged commit b1219ef into main Dec 14, 2021
@junr03 junr03 deleted the c-ares-fallback-nameservers branch January 11, 2022 18:41
joshperry pushed a commit to joshperry/envoy that referenced this pull request Feb 13, 2022
…y#19010)

Commit Message: c-ares resolver: add option to use name servers as fallback.
Risk Level: low - opt in behavior
Testing: existing and additional tests
Docs Changes: added
Release Notes: added

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Josh Perry <josh.perry@mx.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants