fix: an ARP entry's expiry is no age #22
No files matched your search
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- The floor on napalm is 5.1: older releases import `pkg_resources`, which a Python
|
- The floor on napalm is 5.1: older releases import `pkg_resources`, which a Python
|
||||||
3.12 venv no longer has.
|
3.12 venv no longer has.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `get_arp_table()` reports an unknown age as `-1.0` (napalm-device-types'
|
||||||
|
`ARP_AGE_UNKNOWN`). It reported the time until the entry *expires* (FreeBSD's
|
||||||
|
`expires in N seconds`, OpenBSD's `Expire` column), which is no age: an entry
|
||||||
|
refreshed a second ago looked 20 minutes old (NetOrk/netork#1327).
|
||||||
|
|
||||||
## [0.5.0] - 2026-10-23
|
## [0.5.0] - 2026-10-23
|
||||||
|
|
||||||
The first release on PyPI.
|
The first release on PyPI.
|
||||||
|
|||||||
+7
-18
@@ -128,22 +128,12 @@ def routes(text: str) -> list[dict[str, str]]:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
_DURATION = re.compile(r"(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$")
|
_FREEBSD_ARP = re.compile(r"^\S+ \((?P<ip>[\d.]+)\) at (?P<mac>[0-9a-f:]{17}) on (?P<iface>\S+)")
|
||||||
|
|
||||||
|
#: ``arp -an`` shows when an entry *expires* (FreeBSD ``expires in 1176
|
||||||
def duration(text: str) -> float:
|
#: seconds``, OpenBSD's ``Expire`` column), not when the neighbour was last
|
||||||
"""OpenBSD's ``1h2m3s`` in seconds; -1.0 for anything else (``permanent``)."""
|
#: confirmed, so the age is unknown: napalm-device-types' ``ARP_AGE_UNKNOWN``.
|
||||||
match = _DURATION.match(text)
|
_AGE_UNKNOWN = -1.0
|
||||||
if not text or not match or not any(match.groups()):
|
|
||||||
return -1.0
|
|
||||||
hours, minutes, seconds = (int(g or 0) for g in match.groups())
|
|
||||||
return float(hours * 3600 + minutes * 60 + seconds)
|
|
||||||
|
|
||||||
|
|
||||||
_FREEBSD_ARP = re.compile(
|
|
||||||
r"^\S+ \((?P<ip>[\d.]+)\) at (?P<mac>[0-9a-f:]{17}) on (?P<iface>\S+)"
|
|
||||||
r"(?: expires in (?P<expires>\d+) seconds)?"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def arp(text: str) -> list[dict[str, Any]]:
|
def arp(text: str) -> list[dict[str, Any]]:
|
||||||
@@ -152,20 +142,19 @@ def arp(text: str) -> list[dict[str, Any]]:
|
|||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
sentence = _FREEBSD_ARP.match(line)
|
sentence = _FREEBSD_ARP.match(line)
|
||||||
if sentence:
|
if sentence:
|
||||||
expires = sentence["expires"]
|
|
||||||
entries.append(
|
entries.append(
|
||||||
{
|
{
|
||||||
"interface": sentence["iface"],
|
"interface": sentence["iface"],
|
||||||
"mac": sentence["mac"],
|
"mac": sentence["mac"],
|
||||||
"ip": sentence["ip"],
|
"ip": sentence["ip"],
|
||||||
"age": float(expires) if expires else -1.0,
|
"age": _AGE_UNKNOWN,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
words = line.split()
|
words = line.split()
|
||||||
if len(words) >= 4 and re.fullmatch(r"[0-9a-f:]{17}", words[1]):
|
if len(words) >= 4 and re.fullmatch(r"[0-9a-f:]{17}", words[1]):
|
||||||
entries.append(
|
entries.append(
|
||||||
{"interface": words[2], "mac": words[1], "ip": words[0], "age": duration(words[3])}
|
{"interface": words[2], "mac": words[1], "ip": words[0], "age": _AGE_UNKNOWN}
|
||||||
)
|
)
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -98,15 +98,19 @@ class TestRoutes:
|
|||||||
|
|
||||||
|
|
||||||
class TestArp:
|
class TestArp:
|
||||||
|
"""``arp -an`` shows when an entry expires, not when the neighbour was last
|
||||||
|
confirmed. Reported as the age, an entry refreshed a second ago looked 20
|
||||||
|
minutes old; the age is unknown, -1.0 (NetOrk/netork#1327)."""
|
||||||
|
|
||||||
def test_freebsd(self):
|
def test_freebsd(self):
|
||||||
entries = parse.arp(fixture("freebsd-host", "arp_an.txt"))
|
entries = parse.arp(fixture("freebsd-host", "arp_an.txt"))
|
||||||
assert entries[0] == {
|
assert entries[0] == {
|
||||||
"interface": "em0",
|
"interface": "em0",
|
||||||
"mac": "bc:24:11:3c:e2:d0",
|
"mac": "bc:24:11:3c:e2:d0",
|
||||||
"ip": "192.0.2.254",
|
"ip": "192.0.2.254",
|
||||||
"age": 1176.0,
|
"age": -1.0,
|
||||||
}
|
}
|
||||||
assert entries[2]["age"] == -1.0 # permanent: its own address
|
assert {e["age"] for e in entries} == {-1.0}
|
||||||
|
|
||||||
def test_openbsd_table(self):
|
def test_openbsd_table(self):
|
||||||
entries = parse.arp(fixture("openbsd-vm", "arp_an.txt"))
|
entries = parse.arp(fixture("openbsd-vm", "arp_an.txt"))
|
||||||
@@ -114,15 +118,9 @@ class TestArp:
|
|||||||
"interface": "vio0",
|
"interface": "vio0",
|
||||||
"mac": "52:55:0a:00:02:02",
|
"mac": "52:55:0a:00:02:02",
|
||||||
"ip": "10.0.2.2",
|
"ip": "10.0.2.2",
|
||||||
"age": 18 * 60 + 58.0,
|
"age": -1.0,
|
||||||
}
|
}
|
||||||
assert entries[2]["age"] == -1.0
|
assert {e["age"] for e in entries} == {-1.0}
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("text", "seconds"), [("18m58s", 1138.0), ("1h2m3s", 3723.0), ("45s", 45.0)]
|
|
||||||
)
|
|
||||||
def test_openbsd_durations(self, text, seconds):
|
|
||||||
assert parse.duration(text) == seconds
|
|
||||||
|
|
||||||
|
|
||||||
class TestUsers:
|
class TestUsers:
|
||||||
|
|||||||
Reference in new issue
Block a user