Skip to content

Commit 70328b0

Browse files
authored
Merge pull request #2539 from smortex/fix-ipv6-link-local-unicast-address-filtering
(FACT-3171) Fix IPv6 link-local unicast address filtering
2 parents d3447d7 + c273b76 commit 70328b0

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
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::/10').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)

spec/facter/util/resolvers/networking/networking_spec.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
expect(networking_facts).to include(expected)
234234
end
235235

236-
context 'when there is a global ip address' do
236+
context 'when there is a link-local ip address' do
237237
let(:networking_facts) do
238238
{
239239
interfaces:
@@ -251,10 +251,40 @@
251251

252252
it 'expands the correct binding' do
253253
expected = {
254-
ip6: 'fe87::1',
254+
ip6: '::1',
255+
netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
256+
network6: '::1',
257+
scope6: 'host'
258+
}
259+
260+
networking_helper.expand_main_bindings(networking_facts)
261+
262+
expect(networking_facts[:interfaces]['lo0']).to include(expected)
263+
end
264+
end
265+
266+
context 'when there is a global ip address' do
267+
let(:networking_facts) do
268+
{
269+
interfaces:
270+
{ 'lo0' =>
271+
{ mtu: 16_384,
272+
bindings6:
273+
[{ address: '::1',
274+
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
275+
network: '::1' },
276+
{ address: '2001:0DB8::1',
277+
netmask: 'ffff:ffff:ffff:ffff::',
278+
network: '2001:0DB8::' }] } }
279+
}
280+
end
281+
282+
it 'expands the correct binding' do
283+
expected = {
284+
ip6: '2001:0DB8::1',
255285
netmask6: 'ffff:ffff:ffff:ffff::',
256-
network6: 'fe87::',
257-
scope6: 'link'
286+
network6: '2001:0DB8::',
287+
scope6: 'global'
258288
}
259289

260290
networking_helper.expand_main_bindings(networking_facts)

0 commit comments

Comments
 (0)