@@ -226,6 +226,23 @@ def get_vlan_addr_prefix(vlan_intf_name, ip_ver):
226226 return vlan_addr , vlan_prefix
227227
228228
229+ def get_link_local_addr (vlan_interface ):
230+ try :
231+ out = subprocess .check_output (['ip' , '-6' , 'addr' , 'show' , vlan_interface ])
232+ out = out .decode ('UTF-8' )
233+ for line in out .splitlines ():
234+ keys = line .split ()
235+ if keys [0 ] == 'inet6' :
236+ ip = IPNetwork (keys [1 ])
237+ if str (ip .ip ).startswith ("fe80" ):
238+ # Link local ipv6 address
239+ return str (ip .ip )
240+ except Exception :
241+ log .log_error ('failed to get %s addresses from o.s.' % vlan_interface )
242+
243+ return None
244+
245+
229246def get_vlan_addresses (vlan_interface ):
230247 vlan_id = get_vlan_interface_vlan_id (vlan_interface )
231248 vxlan_id = get_vlan_interface_vxlan_id (vlan_interface )
@@ -235,19 +252,10 @@ def get_vlan_addresses(vlan_interface):
235252 ipv6_addr , ipv6_prefix = get_vlan_addr_prefix (vlan_interface , 6 )
236253
237254 if len (ipv6_addr ):
238- try :
239- out = subprocess .check_output (['ip' , '-6' , 'addr' , 'show' , vlan_interface ])
240- out = out .decode ('UTF-8' )
241- for line in out .splitlines ():
242- keys = line .split ()
243- if keys [0 ] == 'inet6' :
244- ip = IPNetwork (keys [1 ])
245- if str (ip .ip ).startswith ("fe80" ) and str (ip .ip ) not in ipv6_addr :
246- # Link local ipv6 address
247- ipv6_addr .append (str (ip .ip ))
248- ipv6_prefix .append ('128' )
249- except Exception :
250- log .log_error ('failed to get %s addresses from o.s.' % vlan_interface )
255+ link_local_addr = get_link_local_addr (vlan_interface )
256+ if link_local_addr and link_local_addr not in ipv6_addr :
257+ ipv6_addr .append (link_local_addr )
258+ ipv6_prefix .append ('128' )
251259
252260 metadata = config_db .get_table ('DEVICE_METADATA' )
253261 mac_addr = metadata ['localhost' ]['mac' ]
0 commit comments