File: neigh_live_test.go

package info (click to toggle)
golang-github-jsimonetti-rtnetlink 2.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,284 kB
  • sloc: makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//go:build integration
// +build integration

package rtnl

import (
	"net"
	"testing"

	"golang.org/x/sys/unix"
)

func TestLiveNeighbours(t *testing.T) {
	c, err := Dial(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	// Trigger a DNS lookup, only for a side effect of pushing our gateway or NS onto the neighbour table
	net.LookupHost("github.com")

	neigtab, err := c.Neighbours(nil, 0)
	if err != nil {
		t.Fatal(err)
	}
	if len(neigtab) == 0 {
		t.Skip("no neighbours")
	}
	for i, e := range neigtab {
		t.Logf("* neighbour table entry [%d]: %v", i, e)

		// Ignore neighbor entries in internal/pseudo state.
		if e.State == unix.NUD_NONE {
			continue
		}
		// Loopback and p2p interfaces can have neigh entries with a zero IP address.
		if e.IP.IsUnspecified() {
			continue
		}

		if e.Interface == nil {
			t.Error("nil e.Interface, expected non-nil")
		}
		if len(e.Interface.Name) == 0 {
			t.Error("zero-length e.Interface.Name")
		}

		// Don't (always) expect hardware address info on entries marked noarp,
		// as they include link-local multicast and loopback addresses that are
		// valid for all interfaces on the host.
		if e.State == unix.NUD_NOARP {
			continue
		}

		if hardwareAddrIsUnspecified(e.HwAddr) {
			t.Error("zero e.HwAddr, expected non-zero")
		}
		if hardwareAddrIsUnspecified(e.Interface.HardwareAddr) {
			t.Error("zero e.Interface.HardwareAddr, expected non-zero")
		}
	}
}