From 4aa9175450d2f8ed406a634ae52550dcd9cfcd40 Mon Sep 17 00:00:00 2001 From: James Lamanna Date: Sat, 14 Dec 2024 17:39:36 -0800 Subject: [PATCH] Add support for ARP/ND Timestamps when retriving neighbors On Linux, Netlink provides NDA_CACHEINFO which carries timestamps about when ARP/ND was updated, used, and confirmed. Expose these fields in the Neigh type --- neigh.go | 8 ++++++++ neigh_linux.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/neigh.go b/neigh.go index 32d722e8..a96e5846 100644 --- a/neigh.go +++ b/neigh.go @@ -19,6 +19,14 @@ type Neigh struct { Vlan int VNI int MasterIndex int + + // These values are expressed as "clock ticks ago". To + // convert these clock ticks to seconds divide by sysconf(_SC_CLK_TCK). + // When _SC_CLK_TCK is 100, for example, the ndm_* times are expressed + // in centiseconds. + Confirmed uint32 // The last time ARP/ND succeeded OR higher layer confirmation was received + Used uint32 // The last time ARP/ND took place for this neighbor + Updated uint32 // The time when the current NUD state was entered } // String returns $ip/$hwaddr $label diff --git a/neigh_linux.go b/neigh_linux.go index 1c6f2958..f4dd8353 100644 --- a/neigh_linux.go +++ b/neigh_linux.go @@ -349,6 +349,10 @@ func NeighDeserialize(m []byte) (*Neigh, error) { neigh.VNI = int(native.Uint32(attr.Value[0:4])) case NDA_MASTER: neigh.MasterIndex = int(native.Uint32(attr.Value[0:4])) + case NDA_CACHEINFO: + neigh.Confirmed = native.Uint32(attr.Value[0:4]) + neigh.Used = native.Uint32(attr.Value[4:8]) + neigh.Updated = native.Uint32(attr.Value[8:12]) } }