From b08d99c0d0cb9bdf29fd2546a1921027fed5e3dc Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 26 Oct 2021 10:04:16 +0000 Subject: [PATCH] Add support for NDA_FLAGS_EXT neighboring attribute This allows to set NTF_EXT_MANAGED neighbor flag for managed neighbor entries as per kernel commit 7482e3841d52 ("net, neigh: Add NTF_MANAGED flag for managed neighbor entries"). The flag then indicates to the kernel that the neighbor entry should be periodically probed for keeping the entry in NUD_REACHABLE state iff possible. Signed-off-by: Daniel Borkmann --- neigh.go | 1 + neigh_linux.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/neigh.go b/neigh.go index 379e565..32d722e 100644 --- a/neigh.go +++ b/neigh.go @@ -12,6 +12,7 @@ type Neigh struct { State int Type int Flags int + FlagsExt int IP net.IP HardwareAddr net.HardwareAddr LLIPAddr net.IP //Used in the case of NHRP diff --git a/neigh_linux.go b/neigh_linux.go index 2158e4c..65e2d21 100644 --- a/neigh_linux.go +++ b/neigh_linux.go @@ -24,7 +24,11 @@ const ( NDA_MASTER NDA_LINK_NETNSID NDA_SRC_VNI - NDA_MAX = NDA_SRC_VNI + NDA_PROTOCOL + NDA_NH_ID + NDA_FDB_EXT_ATTRS + NDA_FLAGS_EXT + NDA_MAX = NDA_FLAGS_EXT ) // Neighbor Cache Entry States. @@ -47,9 +51,16 @@ const ( NTF_MASTER = 0x04 NTF_PROXY = 0x08 NTF_EXT_LEARNED = 0x10 + NTF_OFFLOADED = 0x20 + NTF_STICKY = 0x40 NTF_ROUTER = 0x80 ) +// Extended Neighbor Flags +const ( + NTF_EXT_MANAGED = 0x00000001 +) + // Ndmsg is for adding, removing or receiving information about a neighbor table entry type Ndmsg struct { Family uint8 @@ -168,6 +179,11 @@ func neighHandle(neigh *Neigh, req *nl.NetlinkRequest) error { req.AddData(hwData) } + if neigh.FlagsExt != 0 { + flagsExtData := nl.NewRtAttr(NDA_FLAGS_EXT, nl.Uint32Attr(uint32(neigh.FlagsExt))) + req.AddData(flagsExtData) + } + if neigh.Vlan != 0 { vlanData := nl.NewRtAttr(NDA_VLAN, nl.Uint16Attr(uint16(neigh.Vlan))) req.AddData(vlanData) @@ -306,6 +322,8 @@ func NeighDeserialize(m []byte) (*Neigh, error) { } else { neigh.HardwareAddr = net.HardwareAddr(attr.Value) } + case NDA_FLAGS_EXT: + neigh.FlagsExt = int(native.Uint32(attr.Value[0:4])) case NDA_VLAN: neigh.Vlan = int(native.Uint16(attr.Value[0:2])) case NDA_VNI: