@@ -376,7 +376,8 @@ def device_devid(devname):
376376
377377def get_devicelist ():
378378 if util .is_FreeBSD () or util .is_DragonFlyBSD ():
379- return list (get_interfaces_by_mac ().values ())
379+ stdout , _stderr = subp .subp (["ifconfig" , "-l" ])
380+ return stdout .split ()
380381
381382 try :
382383 devs = os .listdir (get_sys_class_path ())
@@ -449,6 +450,10 @@ def find_candidate_nics_on_freebsd() -> List[str]:
449450 stdout , _stderr = subp .subp (["ifconfig" , "-l" , "-u" , "ether" ])
450451 values = stdout .split ()
451452 if values :
453+ values = sorted (values , key = natural_sort_key )
454+ if "hn0" in values :
455+ values .remove ("hn0" )
456+ values .insert (0 , "hn0" )
452457 return values
453458
454459 # On FreeBSD <= 10, 'ifconfig -l' ignores the interfaces with DOWN
@@ -929,7 +934,17 @@ def find_mac(flat_list):
929934 if m :
930935 yield (m .group ("mac" ), m .group ("ifname" ))
931936
932- results = {mac : ifname for mac , ifname in find_mac (flatten (out ))}
937+ results : dict [str , str ] = {}
938+ for mac , ifname in find_mac (flatten (out )):
939+ if mac in results :
940+ LOG .debug (
941+ "Duplicate MAC %s found on %s and %s; keeping first" ,
942+ mac ,
943+ results [mac ],
944+ ifname ,
945+ )
946+ continue
947+ results [mac ] = ifname
933948 return results
934949
935950
@@ -1117,6 +1132,24 @@ def filter_hyperv_vf_with_synthetic_interface(
11171132 on these names. Note that this will not affect mlx4/5 instances outside
11181133 of Hyper-V, as it only affects environments where hv_netvsc is present.
11191134 """
1135+ if util .is_FreeBSD ():
1136+ hn_macs = {i [1 ]: i [0 ] for i in interfaces if i [0 ].startswith ("hn" )}
1137+ interfaces_to_remove = [
1138+ i for i in interfaces if i [1 ] in hn_macs and i [0 ].startswith ("mce" )
1139+ ]
1140+
1141+ for interface in interfaces_to_remove :
1142+ name , mac , driver , _ = interface
1143+ filtered_logger (
1144+ "Ignoring %r VF interface due to synthetic hn interface %r "
1145+ "with mac address %r." ,
1146+ name ,
1147+ hn_macs [mac ],
1148+ mac ,
1149+ )
1150+ interfaces .remove (interface )
1151+ return
1152+
11201153 hv_netvsc_mac_to_name = {
11211154 i [1 ]: i [0 ] for i in interfaces if i [2 ] == "hv_netvsc"
11221155 }
0 commit comments