Skip to content

Commit

Permalink
Remove netlink dependency for ndp on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Apr 28, 2024
1 parent 3c5744c commit df7d2e6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ require (
github.com/cespare/xxhash v1.1.0
github.com/denisbrodbeck/machineid v1.0.1
github.com/hashicorp/golang-lru v1.0.2
github.com/vishvananda/netlink v1.1.0
golang.org/x/net v0.24.0
golang.org/x/sys v0.19.0
)

require github.com/vishvananda/netns v0.0.4 // indirect
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iP
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
39 changes: 28 additions & 11 deletions ndp/ndp_linux.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
//go:build linux
// +build linux

package ndp

import (
"github.com/vishvananda/netlink"
"bufio"
"net"
"os/exec"
"strings"
)

func Get() (Table, error) {
neights, err := netlink.NeighList(0, netlink.FAMILY_V6)
func Get() (t Table, err error) {
cmd := exec.Command("ip", "-6", "neigh")
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
return t, err
}

var t Table
for _, n := range neights {
t = append(t, Entry{
IP: n.IP,
MAC: n.HardwareAddr,
})
if err := cmd.Start(); err != nil {
return t, err
}

return t, nil
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Fields(line)
if len(parts) >= 5 {
ip := net.ParseIP(parts[0])
mac, _ := net.ParseMAC(parts[4])
if ip != nil && mac != nil {
t = append(t, Entry{
IP: ip,
MAC: mac,
})
}
}
}

return t, cmd.Wait()
}
2 changes: 1 addition & 1 deletion ndp/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux
//go:build !linux

package ndp

Expand Down

0 comments on commit df7d2e6

Please sign in to comment.