Skip to content

explicitly do AAAA lookups even if IPv6 is unavailable #1255

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/puppet_x/puppetlabs/firewall/utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,29 @@ def self.host_to_ip(value, proto = nil)
begin
value = PuppetX::Firewall::IPCidr.new(value)
rescue StandardError
family = case proto
when 'IPv4', 'iptables'
Socket::AF_INET
when 'IPv6', 'ip6tables'
Socket::AF_INET6
when nil
raise ArgumentError, 'Proto must be specified for a hostname'
else
raise ArgumentError, "Unsupported address family: #{proto}"
end
case proto
when 'IPv4', 'iptables'
family = Socket::AF_INET
rr = Resolv::DNS::Resource::IN::A
when 'IPv6', 'ip6tables'
family = Socket::AF_INET6
rr = Resolv::DNS::Resource::IN::AAAA
when nil
raise ArgumentError, 'Proto must be specified for a hostname'
else
raise ArgumentError, "Unsupported address family: #{proto}"
end

new_value = nil
Resolv.each_address(value) do |addr|
Resolv::DNS.new.each_resource(value, rr) do |addr|
begin # rubocop:disable Style/RedundantBegin
new_value = PuppetX::Firewall::IPCidr.new(addr, family)
new_value = PuppetX::Firewall::IPCidr.new(addr.address.to_s, family)
break
rescue StandardError # looking for the one that works # rubocop:disable Lint/SuppressedException
end
end

raise "Failed to resolve hostname #{value}" if new_value.nil?
raise "Failed to resolve hostname #{proto} #{value}" if new_value.nil?

value = new_value
end
Expand Down
Loading