Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix host resolution on Darwin, use dig wherever possible #1986

Merged
merged 3 commits into from
Jul 5, 2017

Conversation

adamleff
Copy link
Contributor

@adamleff adamleff commented Jul 5, 2017

The host and dig commands do not return non-zero if a query returns NXDOMAIN or NOERROR, but the DarwinHostProvider was expecting it when deciding whether to fall back to IPv4 if a IPv6 query failed. Therefore, the host resource would not function properly when resolving hostnames on Darwin. The logic has been changed to use dig short output and query for both v6 and v4 addresses.

Additionally, the LinuxHostProvider has been modified to prefer dig if it's available to keep behavior similar between Darwin and Linux whenever possible. This has the added benefit of providing v6 and v4 resolution if possible where getent hosts only returns v6 if v6 records exist.

The `host` and `dig` commands do not return non-zero if a query returns NXDOMAIN
or NOERROR, but the DarwinHostProvider was expecting it when deciding whether to
fall back to IPv4 if a IPv6 query failed. Therefore, the `host` resource would
not function properly when resolving hostnames on Darwin. The logic has been
changed to use `dig` short output and query for both v6 and v4 addresses.

Additionally, the LinuxHostProvider has been modified to prefer `dig` if it's
available to keep behavior similar between Darwin and Linux whenever possible.
This has the added benefit of providing v6 and v4 resolution if possible where
`getent hosts` only returns v6 if v6 records exist.

Signed-off-by: Adam Leff <adam@leff.co>
@@ -138,6 +140,26 @@ def missing_requirements(_protocol)
# be enumerated in a skip_resource message
[]
end

def resolve_with_dig(hostname)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like we need a new UnixHostProvider class to map those functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I can totally do that. You thinking DarwinHostProvider and LinuxHostProvider would subclass from it, and we'd move both resolve_with_bind and resolve_with_getent into it?

Copy link
Contributor

Choose a reason for hiding this comment

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

exactly, that was my thinking.

Signed-off-by: Adam Leff <adam@leff.co>
@adamleff adamleff requested a review from chris-rock July 5, 2017 14:10
Signed-off-by: Adam Leff <adam@leff.co>
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Very nice addition. Awesome work @adamleff

@adamleff adamleff added the Type: Bug Feature not working as expected label Jul 5, 2017
@adamleff adamleff merged commit c280e9a into master Jul 5, 2017
@adamleff adamleff deleted the adamleff/fix-host-darwin branch July 5, 2017 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants