Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion lib/facter/util/resolvers/networking/networking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,23 @@ def find_valid_binding(bindings)
bindings.empty? ? nil : bindings.first
end

IPV4_LINK_LOCAL_ADDR = IPAddr.new('169.254.0.0/16').freeze # RFC5735
IPV6_LINK_LOCAL_ADDR = IPAddr.new('fe80::/10').freeze # RFC4291

def ignored_ip_address(addr)
addr.empty? || addr.start_with?('127.', '169.254.') || addr.start_with?('fe80') || addr.eql?('::1')
return true if addr.empty?

ip = IPAddr.new(addr)
return true if ip.loopback?

[
IPV4_LINK_LOCAL_ADDR,
IPV6_LINK_LOCAL_ADDR
].each do |range|
return true if range.include?(ip)
end

false
end

def calculate_mask_length(netmask)
Expand Down
38 changes: 34 additions & 4 deletions spec/facter/util/resolvers/networking/networking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
expect(networking_facts).to include(expected)
end

context 'when there is a global ip address' do
context 'when there is a link-local ip address' do
let(:networking_facts) do
{
interfaces:
Expand All @@ -251,10 +251,40 @@

it 'expands the correct binding' do
expected = {
ip6: 'fe87::1',
ip6: '::1',
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network6: '::1',
scope6: 'host'
}

networking_helper.expand_main_bindings(networking_facts)

expect(networking_facts[:interfaces]['lo0']).to include(expected)
end
end

context 'when there is a global ip address' do
let(:networking_facts) do
{
interfaces:
{ 'lo0' =>
{ mtu: 16_384,
bindings6:
[{ address: '::1',
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
network: '::1' },
{ address: '2001:0DB8::1',
netmask: 'ffff:ffff:ffff:ffff::',
network: '2001:0DB8::' }] } }
}
end

it 'expands the correct binding' do
expected = {
ip6: '2001:0DB8::1',
netmask6: 'ffff:ffff:ffff:ffff::',
network6: 'fe87::',
scope6: 'link'
network6: '2001:0DB8::',
scope6: 'global'
}

networking_helper.expand_main_bindings(networking_facts)
Expand Down