From 4f246e6a41008e336350fda00530ca3f322d3917 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 10 Mar 2021 13:40:47 -0500 Subject: [PATCH] Fix compatibility with some switch configurations While some implementations mess up portid and need portdescr instead, others are just the opposite. Tolerate match either by description or name. --- confluent_server/confluent/networking/lldp.py | 17 ++++++++++++----- confluent_server/confluent/networking/macmap.py | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/confluent_server/confluent/networking/lldp.py b/confluent_server/confluent/networking/lldp.py index 910bb7de..29b94ede 100644 --- a/confluent_server/confluent/networking/lldp.py +++ b/confluent_server/confluent/networking/lldp.py @@ -139,7 +139,10 @@ def get_fingerprint(switch, port, configmanager, portmatch): continue if info.get('switch', None) != switch: continue - if portmatch(info.get('port'), port): + if portmatch(info.get('portid', None), port): + return ('sha256$' + b64tohex(info['peersha256fingerprint']), + info.get('verified', False)) + elif portmatch(info.get('port', None), port): return ('sha256$' + b64tohex(info['peersha256fingerprint']), info.get('verified', False)) return None, False @@ -235,19 +238,23 @@ def _extract_neighbor_data_b(args): idx = oidindex[0][-1] idxtoifname[idx] = _lldpdesc_to_ifname(sid, idx, str(oidindex[1])) for remotedesc in conn.walk('1.0.8802.1.1.2.1.4.1.1.10'): - iname = idxtoifname[remotedesc[0][-2]] + iname = idxtoifname.get(remotedesc[0][-2], + idxtoportid[remotedesc[0][-2]]) _init_lldp(lldpdata, iname, remotedesc[0][-2], idxtoportid, switch) _extract_extended_desc(lldpdata[iname], remotedesc[1], user) for remotename in conn.walk('1.0.8802.1.1.2.1.4.1.1.9'): - iname = idxtoifname[remotename[0][-2]] + iname = idxtoifname.get(remotename[0][-2], + idxtoportid[remotename[0][-2]]) _init_lldp(lldpdata, iname, remotename[0][-2], idxtoportid, switch) lldpdata[iname]['peername'] = str(remotename[1]) for remotename in conn.walk('1.0.8802.1.1.2.1.4.1.1.7'): - iname = idxtoifname[remotename[0][-2]] + iname = idxtoifname.get(remotename[0][-2], + idxtoportid[remotename[0][-2]]) _init_lldp(lldpdata, iname, remotename[0][-2], idxtoportid, switch) lldpdata[iname]['peerportid'] = sanitize(remotename[1]) for remoteid in conn.walk('1.0.8802.1.1.2.1.4.1.1.5'): - iname = idxtoifname[remoteid[0][-2]] + iname = idxtoifname.get(remoteid[0][-2], + idxtoportid[remoteid[0][-2]]) _init_lldp(lldpdata, iname, remoteid[0][-2], idxtoportid, switch) lldpdata[iname]['peerchassisid'] = sanitize(remoteid[1]) for entry in lldpdata: diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index 34d9b4fd..894109be 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -82,6 +82,8 @@ _blacklistnames = ( def _namesmatch(switchdesc, userdesc): + if switchdesc is None: + return False if switchdesc == userdesc: return True try: