File tree Expand file tree Collapse file tree 2 files changed +50
-5
lines changed
lib/facter/util/resolvers/networking
spec/facter/util/resolvers/networking Expand file tree Collapse file tree 2 files changed +50
-5
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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 :
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 )
You can’t perform that action at this time.
0 commit comments