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 FQDN resolution, scan all IPs associated with host for FQDN #1053

Closed
wants to merge 2 commits into from

Conversation

jseely
Copy link
Contributor

@jseely jseely commented Sep 8, 2017

Description

Currently on Windows Server 2016, the FQDN is being set as the machine name instead of the FQDN. This boils down to the underlying winsock library calls which, when given an IPv6 address, return only the machine name instead of the FQDN.

The work around involves calling Socket.gethostbyaddr with the IPv4 address returned in the h_addr_list instead of the IPv6 address.

Check List

@jseely jseely requested a review from a team September 8, 2017 18:07
Signed-off-by: Justin Seely <justin.seely@gmail.com>
@tas50
Copy link
Contributor

tas50 commented Sep 8, 2017

@jseely This looks like a great change. Can you add a spec for the decision that mocks out what the response would like like under the ipv4 vs. ipv6 conditions?

@jseely
Copy link
Contributor Author

jseely commented Sep 9, 2017

@tas50 So I thought of a new approach to take on this that is more resilient, instead of choosing just one IP address to attempt a host lookup with, we now will try them all until we find one that contains a period (ie. is an FQDN). If none of them do it falls back to the machine name, as it currently does.

As for IPv6 vs IPv4 responses I don't think I've tested this exhaustively enough to make statements about its function across all possible configurations of all versions of Windows in all environments. But from my experimentation with Server 2012R2 and Server 2016 VMs in Azure with IPv4 and IPv6 addresses associated to the host record, when IPv4 addresses are used to perform the gethostbyaddr lookup it correctly returns the FQDN, however, when IPv6 addresses are used it returns back the machine name only.

This could be a network configuration issue on Azure, or a bug in the win sock library. Either way I think this new approach guarantees better success in looking up an FQDN then the current model.

The current lookup process assumes that if the h_name field (first field in the array) of gethostbyname is not an FQDN; then the h_name field of gethostbyaddr using the last address in the h_addr_list from the first call will be an FQDN. In many cases (all the ones where the last address in h_addr_list was IPv4 for me) this is a correct assumption.

The new lookup process does not make this assumption, if the h_name field of gethostbyname is not an FQDN; then we will loop over all the addresses in h_addr_list until we find one where h_name is an FQDN; if no h_addr_list address have an FQDN associated to them we fall back to machine name (which is the current failure case in the current process).

** Let me know if this covers what you wanted out of a spec, or if I need to provide something more detailed in a specific format.

@jseely jseely force-pushed the master branch 2 times, most recently from 3076a06 to e15b51a Compare September 9, 2017 04:32
Signed-off-by: Justin Seely <justin.seely@gmail.com>
@jseely jseely changed the title Fix FQDN resolution for IPv6 enabled Windows machines Fix FQDN resolution, scan all IPs associated with host for FQDN Sep 29, 2017
@tas50
Copy link
Contributor

tas50 commented Oct 24, 2017

@jseely It sounds like you've tested this in detail. I just want to make sure we get some unit tests around the logic within your change. A few years down the line someone might make a slight change there without the background of what you've gone through. If we get some specs added here we can ensure we don't introduce a regression later on.

break
end
end
if !found_fqdn
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be fqdn info.first unless fqdn and eliminate the found_fqdn variable entirely? (i don't know if bare fqdn is a getter or not in this context...)

@lock
Copy link

lock bot commented Jan 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Triage: Needs Information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants