diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2021-01-15 18:12:50 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-15 18:15:26 -0800 |
commit | 2814a032be7b34e4cc0c0607dba8030e74e11208 (patch) | |
tree | fc6a023766f5ad1ae5818abd710c997ba657e8bd /pkg/tcpip/tests | |
parent | fd5b52c87ff8fbabf2b293fc95ec9f9f04e5621c (diff) |
Support GetLinkAddress with neighborCache
Test: integration_test.TestGetLinkAddress
PiperOrigin-RevId: 352119404
Diffstat (limited to 'pkg/tcpip/tests')
-rw-r--r-- | pkg/tcpip/tests/integration/link_resolution_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/pkg/tcpip/tests/integration/link_resolution_test.go b/pkg/tcpip/tests/integration/link_resolution_test.go index 3f06c2145..af32d3009 100644 --- a/pkg/tcpip/tests/integration/link_resolution_test.go +++ b/pkg/tcpip/tests/integration/link_resolution_test.go @@ -16,6 +16,7 @@ package integration_test import ( "bytes" + "fmt" "net" "testing" @@ -395,3 +396,63 @@ func TestTCPLinkResolutionFailure(t *testing.T) { }) } } + +func TestGetLinkAddress(t *testing.T) { + const ( + host1NICID = 1 + host2NICID = 4 + ) + + tests := []struct { + name string + netProto tcpip.NetworkProtocolNumber + remoteAddr tcpip.Address + expectedLinkAddr bool + }{ + { + name: "IPv4", + netProto: ipv4.ProtocolNumber, + remoteAddr: ipv4Addr2.AddressWithPrefix.Address, + }, + { + name: "IPv6", + netProto: ipv6.ProtocolNumber, + remoteAddr: ipv6Addr2.AddressWithPrefix.Address, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + for _, useNeighborCache := range []bool{true, false} { + t.Run(fmt.Sprintf("UseNeighborCache=%t", useNeighborCache), func(t *testing.T) { + stackOpts := stack.Options{ + NetworkProtocols: []stack.NetworkProtocolFactory{arp.NewProtocol, ipv4.NewProtocol, ipv6.NewProtocol}, + UseNeighborCache: useNeighborCache, + } + + host1Stack, _ := setupStack(t, stackOpts, host1NICID, host2NICID) + + for i := 0; i < 2; i++ { + addr, ch, err := host1Stack.GetLinkAddress(host1NICID, test.remoteAddr, "", test.netProto, func(tcpip.LinkAddress, bool) {}) + var want *tcpip.Error + if i == 0 { + want = tcpip.ErrWouldBlock + } + if err != want { + t.Fatalf("got host1Stack.GetLinkAddress(%d, %s, '', %d, _) = (%s, _, %s), want = (_, _, %s)", host1NICID, test.remoteAddr, test.netProto, addr, err, want) + } + + if i == 0 { + <-ch + continue + } + + if addr != linkAddr2 { + t.Fatalf("got addr = %s, want = %s", addr, linkAddr2) + } + } + }) + } + }) + } +} |