Skip to content

Commit f5d2b54

Browse files
committed
(FACT-3171) Rework the way we filter ignored IP addresses
Instead of String comparison, check if IP addresses are included into the ignored ranges. No functional change.
1 parent d3447d7 commit f5d2b54

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/facter/util/resolvers/networking/networking.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,23 @@ def find_valid_binding(bindings)
6464
bindings.empty? ? nil : bindings.first
6565
end
6666

67+
IPV4_LINK_LOCAL_ADDR = IPAddr.new('169.254.0.0/16').freeze # RFC5735
68+
IPV6_LINK_LOCAL_ADDR = IPAddr.new('fe80::/16').freeze # RFC4291
69+
6770
def ignored_ip_address(addr)
68-
addr.empty? || addr.start_with?('127.', '169.254.') || addr.start_with?('fe80') || addr.eql?('::1')
71+
return true if addr.empty?
72+
73+
ip = IPAddr.new(addr)
74+
return true if ip.loopback?
75+
76+
[
77+
IPV4_LINK_LOCAL_ADDR,
78+
IPV6_LINK_LOCAL_ADDR
79+
].each do |range|
80+
return true if range.include?(ip)
81+
end
82+
83+
false
6984
end
7085

7186
def calculate_mask_length(netmask)

0 commit comments

Comments
 (0)