better mac matching
This commit is contained in:
parent
5f53ca2f1e
commit
ac5c4b5693
45
nodedb.py
45
nodedb.py
|
@ -284,9 +284,19 @@ class NodeDB:
|
||||||
if data[2]:
|
if data[2]:
|
||||||
node.name = data[2]
|
node.name = data[2]
|
||||||
|
|
||||||
|
# 1043nd, vpn, wlan, br-wan
|
||||||
|
|
||||||
# compares two MACs and decides whether they are
|
# compares two MACs and decides whether they are
|
||||||
# similar and could be from the same node
|
# similar and could be from the same node
|
||||||
def is_similar(a, b):
|
def is_similar(a, b):
|
||||||
|
# a is the base address
|
||||||
|
# b is some mac of the host
|
||||||
|
# b = 00:00:00:00:00:+1 x
|
||||||
|
# |2:00:00:+1:00:+1 x
|
||||||
|
# |2:00:00:00:00:+1 x
|
||||||
|
# |2:00:00:00:00:+2
|
||||||
|
# |2:00:00:+1:00:00
|
||||||
|
|
||||||
if a == b:
|
if a == b:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -296,20 +306,29 @@ def is_similar(a, b):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# first byte must only differ in bit 2
|
x = mac_a
|
||||||
if mac_a[0] | 2 == mac_b[0] | 2:
|
x[5] += 1
|
||||||
# count different bytes
|
if mac_b == x:
|
||||||
c = [x for x in zip(mac_a[1:], mac_b[1:]) if x[0] != x[1]]
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# no more than two additional bytes must differ
|
x[0] |= 2
|
||||||
if len(c) <= 2:
|
if mac_b == x:
|
||||||
delta = 0
|
return True
|
||||||
|
|
||||||
if len(c) > 0:
|
x[3] += 1
|
||||||
delta = sum(abs(i[0] -i[1]) for i in c)
|
if mac_b == x:
|
||||||
|
return True
|
||||||
|
|
||||||
# These addresses look pretty similar!
|
x = mac_a
|
||||||
return delta < 8
|
x[0] |= 2
|
||||||
|
x[5] += 2
|
||||||
|
if mac_b == x:
|
||||||
|
return True
|
||||||
|
|
||||||
|
x = mac_a
|
||||||
|
x[0] |= 2
|
||||||
|
x[3] += 1
|
||||||
|
if mac_b == x:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in a new issue