Skip to content

Commit

Permalink
Add support for ARP/ND Timestamps when retriving neighbors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jlamanna committed Dec 15, 2024
1 parent 976bd8d commit 4aa9175
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions neigh_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down

0 comments on commit 4aa9175

Please sign in to comment.