summaryrefslogtreecommitdiff
path: root/vendor/github.com/vishvananda/netlink/neigh_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vishvananda/netlink/neigh_linux.go')
-rw-r--r--vendor/github.com/vishvananda/netlink/neigh_linux.go61
1 files changed, 50 insertions, 11 deletions
diff --git a/vendor/github.com/vishvananda/netlink/neigh_linux.go b/vendor/github.com/vishvananda/netlink/neigh_linux.go
index f069db257..f75c22649 100644
--- a/vendor/github.com/vishvananda/netlink/neigh_linux.go
+++ b/vendor/github.com/vishvananda/netlink/neigh_linux.go
@@ -2,10 +2,10 @@ package netlink
import (
"net"
- "syscall"
"unsafe"
"github.com/vishvananda/netlink/nl"
+ "golang.org/x/sys/unix"
)
const (
@@ -73,7 +73,7 @@ func NeighAdd(neigh *Neigh) error {
// NeighAdd will add an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh add ....`
func (h *Handle) NeighAdd(neigh *Neigh) error {
- return h.neighAdd(neigh, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL)
+ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_EXCL)
}
// NeighSet will add or replace an IP to MAC mapping to the ARP table
@@ -85,7 +85,7 @@ func NeighSet(neigh *Neigh) error {
// NeighSet will add or replace an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh replace....`
func (h *Handle) NeighSet(neigh *Neigh) error {
- return h.neighAdd(neigh, syscall.NLM_F_CREATE|syscall.NLM_F_REPLACE)
+ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_REPLACE)
}
// NeighAppend will append an entry to FDB
@@ -97,7 +97,7 @@ func NeighAppend(neigh *Neigh) error {
// NeighAppend will append an entry to FDB
// Equivalent to: `bridge fdb append...`
func (h *Handle) NeighAppend(neigh *Neigh) error {
- return h.neighAdd(neigh, syscall.NLM_F_CREATE|syscall.NLM_F_APPEND)
+ return h.neighAdd(neigh, unix.NLM_F_CREATE|unix.NLM_F_APPEND)
}
// NeighAppend will append an entry to FDB
@@ -109,7 +109,7 @@ func neighAdd(neigh *Neigh, mode int) error {
// NeighAppend will append an entry to FDB
// Equivalent to: `bridge fdb append...`
func (h *Handle) neighAdd(neigh *Neigh, mode int) error {
- req := h.newNetlinkRequest(syscall.RTM_NEWNEIGH, mode|syscall.NLM_F_ACK)
+ req := h.newNetlinkRequest(unix.RTM_NEWNEIGH, mode|unix.NLM_F_ACK)
return neighHandle(neigh, req)
}
@@ -122,12 +122,13 @@ func NeighDel(neigh *Neigh) error {
// NeighDel will delete an IP address from a link device.
// Equivalent to: `ip addr del $addr dev $link`
func (h *Handle) NeighDel(neigh *Neigh) error {
- req := h.newNetlinkRequest(syscall.RTM_DELNEIGH, syscall.NLM_F_ACK)
+ req := h.newNetlinkRequest(unix.RTM_DELNEIGH, unix.NLM_F_ACK)
return neighHandle(neigh, req)
}
func neighHandle(neigh *Neigh, req *nl.NetlinkRequest) error {
var family int
+
if neigh.Family > 0 {
family = neigh.Family
} else {
@@ -151,12 +152,25 @@ func neighHandle(neigh *Neigh, req *nl.NetlinkRequest) error {
dstData := nl.NewRtAttr(NDA_DST, ipData)
req.AddData(dstData)
- if neigh.Flags != NTF_PROXY || neigh.HardwareAddr != nil {
+ if neigh.LLIPAddr != nil {
+ llIPData := nl.NewRtAttr(NDA_LLADDR, neigh.LLIPAddr.To4())
+ req.AddData(llIPData)
+ } else if neigh.Flags != NTF_PROXY || neigh.HardwareAddr != nil {
hwData := nl.NewRtAttr(NDA_LLADDR, []byte(neigh.HardwareAddr))
req.AddData(hwData)
}
- _, err := req.Execute(syscall.NETLINK_ROUTE, 0)
+ if neigh.Vlan != 0 {
+ vlanData := nl.NewRtAttr(NDA_VLAN, nl.Uint16Attr(uint16(neigh.Vlan)))
+ req.AddData(vlanData)
+ }
+
+ if neigh.VNI != 0 {
+ vniData := nl.NewRtAttr(NDA_VNI, nl.Uint32Attr(uint32(neigh.VNI)))
+ req.AddData(vniData)
+ }
+
+ _, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}
@@ -189,7 +203,7 @@ func (h *Handle) NeighProxyList(linkIndex, family int) ([]Neigh, error) {
}
func (h *Handle) neighList(linkIndex, family, flags int) ([]Neigh, error) {
- req := h.newNetlinkRequest(syscall.RTM_GETNEIGH, syscall.NLM_F_DUMP)
+ req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP)
msg := Ndmsg{
Family: uint8(family),
Index: uint32(linkIndex),
@@ -197,7 +211,7 @@ func (h *Handle) neighList(linkIndex, family, flags int) ([]Neigh, error) {
}
req.AddData(&msg)
- msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWNEIGH)
+ msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH)
if err != nil {
return nil, err
}
@@ -237,12 +251,37 @@ func NeighDeserialize(m []byte) (*Neigh, error) {
return nil, err
}
+ // This should be cached for perfomance
+ // once per table dump
+ link, err := LinkByIndex(neigh.LinkIndex)
+ if err != nil {
+ return nil, err
+ }
+ encapType := link.Attrs().EncapType
+
for _, attr := range attrs {
switch attr.Attr.Type {
case NDA_DST:
neigh.IP = net.IP(attr.Value)
case NDA_LLADDR:
- neigh.HardwareAddr = net.HardwareAddr(attr.Value)
+ // BUG: Is this a bug in the netlink library?
+ // #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
+ // #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
+ attrLen := attr.Attr.Len - unix.SizeofRtAttr
+ if attrLen == 4 && (encapType == "ipip" ||
+ encapType == "sit" ||
+ encapType == "gre") {
+ neigh.LLIPAddr = net.IP(attr.Value)
+ } else if attrLen == 16 &&
+ encapType == "tunnel6" {
+ neigh.IP = net.IP(attr.Value)
+ } else {
+ neigh.HardwareAddr = net.HardwareAddr(attr.Value)
+ }
+ case NDA_VLAN:
+ neigh.Vlan = int(native.Uint16(attr.Value[0:2]))
+ case NDA_VNI:
+ neigh.VNI = int(native.Uint32(attr.Value[0:4]))
}
}