From dd2231ee54bfc414291f4e1d362e453eea29013c Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sat, 20 Feb 2021 00:43:04 +0100 Subject: [PATCH] Interfaces / Diagnostics / arp,ndp table: slow manufacturer lookups, likely after upgrading netaddr to 0.8.0. for https://github.com/opnsense/core/issues/4666 --- src/opnsense/scripts/interfaces/list_arp.py | 15 ++++++++++----- src/opnsense/scripts/interfaces/list_ndp.py | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/opnsense/scripts/interfaces/list_arp.py b/src/opnsense/scripts/interfaces/list_arp.py index e1eda740f..1692eda7d 100755 --- a/src/opnsense/scripts/interfaces/list_arp.py +++ b/src/opnsense/scripts/interfaces/list_arp.py @@ -37,6 +37,14 @@ sys.path.insert(0, "/usr/local/opnsense/site-python") import watchers.dhcpd if __name__ == '__main__': + # index mac database (shipped with netaddr) + macdb = dict() + with open("%s/eui/oui.txt" % os.path.dirname(netaddr.__file__)) as fh_macdb: + for line in fh_macdb: + if line[11:].startswith('(hex)'): + macprefix = line[0:8].replace('-', ':').lower() + macdb[macprefix] = line[18:].strip() + result = [] # import dhcp_leases (index by ip address) @@ -64,11 +72,8 @@ if __name__ == '__main__': 'manufacturer': '', 'hostname': '' } - manufacturer_mac = netaddr.EUI(record['mac']) - try: - record['manufacturer'] = manufacturer_mac.oui.registration().org - except netaddr.NotRegisteredError: - pass + if record['mac'][0:8] in macdb: + record['manufacturer'] = macdb[record['mac'][0:8]] if record['ip'] in dhcp_leases: record['hostname'] = dhcp_leases[record['ip']]['hostname'] result.append(record) diff --git a/src/opnsense/scripts/interfaces/list_ndp.py b/src/opnsense/scripts/interfaces/list_ndp.py index f815898ec..7513f1bb8 100755 --- a/src/opnsense/scripts/interfaces/list_ndp.py +++ b/src/opnsense/scripts/interfaces/list_ndp.py @@ -35,6 +35,14 @@ import ujson import netaddr if __name__ == '__main__': + # index mac database (shipped with netaddr) + macdb = dict() + with open("%s/eui/oui.txt" % os.path.dirname(netaddr.__file__)) as fh_macdb: + for line in fh_macdb: + if line[11:].startswith('(hex)'): + macprefix = line[0:8].replace('-', ':').lower() + macdb[macprefix] = line[18:].strip() + result = [] # parse ndp output sp = subprocess.run(['/usr/sbin/ndp', '-an'], capture_output=True, text=True) @@ -46,11 +54,8 @@ if __name__ == '__main__': 'intf': line_parts[2], 'manufacturer': '' } - manufacturer_mac = netaddr.EUI(record['mac']) - try: - record['manufacturer'] = manufacturer_mac.oui.registration().org - except netaddr.NotRegisteredError: - pass + if record['mac'][0:8] in macdb: + record['manufacturer'] = macdb[record['mac'][0:8]] result.append(record) # handle command line argument (type selection)