machine: fix issues with network interface parsing

Don't parse non "ether" types.  Don't add interfaces that don't
have mac addresses and at least one IP address.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-12-05 17:12:21 -05:00
parent c0c34ea045
commit ac73036857
1 changed files with 4 additions and 1 deletions

View File

@ -424,7 +424,8 @@ class Machine:
for interface in decoded: for interface in decoded:
if ( if (
interface['operstate'] != "UP" or interface['operstate'] != "UP" or
interface['link_type'] == "loopback" interface['link_type'] != "ether" or
'address' not in interface
): ):
continue continue
addresses: List[Dict[str, Any]] = [ addresses: List[Dict[str, Any]] = [
@ -436,6 +437,8 @@ class Machine:
for addr in interface.get('addr_info', []) for addr in interface.get('addr_info', [])
if 'family' in addr and 'local' in addr if 'family' in addr and 'local' in addr
] ]
if not addresses:
continue
network[interface['ifname']] = { network[interface['ifname']] = {
'mac_address': interface['address'], 'mac_address': interface['address'],
'ip_addresses': addresses 'ip_addresses': addresses