From 2c0daef37b331b0a826c7c0ab31cc2262b1131ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Fri, 14 Jun 2013 17:01:51 +0300 Subject: [PATCH] network: Rewrote ipv6enabled fact to use ping instead of ifconfig. --- network/lib/facter/ipv6enabled.rb | 47 ++++--------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/network/lib/facter/ipv6enabled.rb b/network/lib/facter/ipv6enabled.rb index 3f97e99..6327b7d 100644 --- a/network/lib/facter/ipv6enabled.rb +++ b/network/lib/facter/ipv6enabled.rb @@ -2,49 +2,14 @@ # # Purpose: Check if system has IPv6 enabled. # -# Based on ipaddress6 fact written Cody Herriges . - -def check_for_ipv6_address(output, token) - ret = false - output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| - ret = true - break - end - ret -end - Facter.add(:ipv6enabled) do - confine :kernel => :linux setcode do - output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"]) - - check_for_ipv6_address(output, 'inet6 addr:') + out = Facter::Util::Resolution.exec('ping6 -c 1 ::1 2> /dev/null | egrep " [0\.]*% packet loss"') + if out + "true" + else + "false" + end end end -Facter.add(:ipv6enabled) do - confine :kernel => %w{SunOS} - setcode do - output = Facter::Util::IP.exec_ifconfig(["-a"]) - - check_for_ipv6_address(output, 'inet6') - end -end - -Facter.add(:ipv6enabled) do - confine :kernel => %w{Darwin FreeBSD OpenBSD} - setcode do - output = Facter::Util::IP.exec_ifconfig(["-a"]) - - check_for_ipv6_address(output, 'inet6') - end -end - -Facter.add(:ipv6enabled) do - confine :kernel => :windows - setcode do - output = Facter::Util::Resolution.exec("#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address level=verbose") - - check_for_ipv6_address(output, 'Address') - end -end