How to update MAC vendor db?

Started by Werner Fischer, November 23, 2018, 03:50:45 PM

Previous topic - Next topic
The status site "status_interfaces.php" shows the vendor of a MAC address.

We have now acquired the MAC vendor range DC58BC, which is now listed at IEEE, see
https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries and http://standards-oui.ieee.org/oui/oui.txt

My question is: where does OPNsense store this oui.txt? (I'd like to contribute a patch, so that future OPNsense version show the vendor "Thomas-Krenn.AG" for MAC addresses starting with DC:58:BC  ;)

Thx and best regards,
Werner

Hi Werner,

The database is pulled in via https://pypi.org/project/netaddr/

The library itself wasn't renewed since January 2017 though...


Cheers,
Franco

This is the most easy to find posting on this issue via Google.
As this is still an issue and the file is still as old as before, I've opened an issue on this:
https://github.com/opnsense/core/issues/3883

September 17, 2020, 11:25:28 PM #3 Last Edit: September 17, 2020, 11:27:24 PM by XeroX
Finally the Package including Databases have been updated (last more than 3 years ago)

Can we get an update of this package to have finally granular vendor mac addr lookup?

https://netaddr.readthedocs.io/en/latest/changes.html
Release: 0.7.20
Date: 19 Jun 2020

(This is at least the used library for ARP Table?!)
https://github.com/opnsense/core/blob/master/src/opnsense/scripts/interfaces/list_macdb.py

September 18, 2020, 12:31:12 AM #4 Last Edit: September 18, 2020, 01:33:52 AM by XeroX
Works like a charm on ARP Table. However breaks Vendor Lookup in DHCP completely.

distinfo

TIMESTAMP = 1600381665
SHA256 (netaddr-0.7.20.tar.gz) = d09252e5aec3913815d77eb8e8ea8fa6eb33521253e52f977f6abaa964776f3e
SIZE (netaddr-0.7.20.tar.gz) = 1889698


rm files/patch-setup.py

Makefile
--- Makefile.old        2020-09-18 00:29:47.359512000 +0200
+++ Makefile    2020-09-18 00:29:53.599067000 +0200
@@ -2,7 +2,7 @@
# $FreeBSD$

PORTNAME=      netaddr
-PORTVERSION=   0.7.19
+PORTVERSION=   0.7.20
PORTREVISION=  1
CATEGORIES=    net python
MASTER_SITES=  CHEESESHOP


EDIT:
DHCP Leases uses the following command:
configctl interface list macdb json
Execute error

Its broken as a method does not exist anymore:

Traceback (most recent call last):
  File "/usr/local/opnsense/scripts/interfaces/list_macdb.py", line 39, in <module>
    if os.path.isfile(netaddr.eui.ieee.OUI_REGISTRY_PATH):
AttributeError: module 'netaddr.eui.ieee' has no attribute 'OUI_REGISTRY_PATH'

https://github.com/netaddr/netaddr/commit/5b2807ff91640c959dc358334f626cea0e28778c

EDIT2:
0.8.0 released 6 days ago.

September 18, 2020, 01:31:18 AM #5 Last Edit: September 18, 2020, 09:34:51 AM by XeroX
Bad code and ARP Vendor Lookup works different than DHCP Leases. DHCP leases always parses the complete list, instead of looking up each single item with netaddr method. I'm not a programmer, I may check how to build this better.

Fix for DHCP:
/usr/local/opnsense/scripts/interfaces/list_macdb.py
--- list_macdb.py.old   2020-09-18 01:28:10.300640000 +0200
+++ list_macdb.py       2020-09-18 01:27:01.729241000 +0200
@@ -27,12 +27,11 @@
import os.path
import sys
import ujson
-import netaddr.eui.ieee

if __name__ == '__main__':
     result=dict()
-    if os.path.isfile(netaddr.eui.ieee.OUI_REGISTRY_PATH):
-        for line in open(netaddr.eui.ieee.OUI_REGISTRY_PATH, 'rb'):
+    if os.path.isfile('/usr/local/lib/python3.7/site-packages/netaddr/eui/oui.txt'):
+        for line in open('/usr/local/lib/python3.7/site-packages/netaddr/eui/oui.txt', 'rb'):
             line = line.decode()
             if line.find('(base 16)') > -1:
                 parts=line.split('(base 16)')

Is that not exactly the same? Besides, hardcoding 3.7 will break on the next Python update.


Cheers,
Franco

Morning franco,
what do you mean exactly the same? referred to?

I know it breaks, will try to improve that, I'm quiet new to python.

Hi there :)

This looks for a file:

if os.path.isfile(netaddr.eui.ieee.OUI_REGISTRY_PATH):

This looks for a file:

if os.path.isfile('/usr/local/lib/python3.7/site-packages/netaddr/eui/oui.txt'):

It is probable that netaddr.eui.ieee.OUI_REGISTRY_PATH actually is /usr/local/lib/python3.7/site-packages/netaddr/eui/oui.txt ;)


Cheers,
Franco

September 18, 2020, 10:23:08 AM #9 Last Edit: September 18, 2020, 10:43:49 AM by XeroX
Oh yes, franco. You're correct.

Check the commit I posted on netaddr. The method has been removed. That's why changed it.

https://github.com/netaddr/netaddr/commit/5b2807ff91640c959dc358334f626cea0e28778c

EDIT:
Here we go:

--- list_macdb.py.old   2020-09-18 10:42:50.178232000 +0200
+++ list_macdb.py       2020-09-18 10:39:20.059022000 +0200
@@ -27,12 +27,12 @@
import os.path
import sys
import ujson
-import netaddr.eui.ieee
+import imp

if __name__ == '__main__':
     result=dict()
-    if os.path.isfile(netaddr.eui.ieee.OUI_REGISTRY_PATH):
-        for line in open(netaddr.eui.ieee.OUI_REGISTRY_PATH, 'rb'):
+    if os.path.isfile((imp.find_module('netaddr')[1])+'/eui/oui.txt'):
+        for line in open((imp.find_module('netaddr')[1])+'/eui/oui.txt', 'rb'):
             line = line.decode()
             if line.find('(base 16)') > -1:
                 parts=line.split('(base 16)')

Thanks, this was added to the development branch. We will work on a netaddr update right after 20.7.3 is out.


Cheers,
Franco

September 22, 2020, 06:19:35 PM #11 Last Edit: September 22, 2020, 06:21:10 PM by XeroX
Great franco, thank you!

Hope you can implement 0.8.0 directly and skip 0.7.20.

If you need any help or pull request let me know.

Which branch is it?

More discussion here. I'm not sure where this stands in FreeBSD as there is some kerfuffle about Python version support.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=249382


Cheers,
Franco