summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/tests/integration
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/tests/integration')
-rw-r--r--pkg/tcpip/tests/integration/BUILD115
-rw-r--r--pkg/tcpip/tests/integration/forward_test.go228
-rw-r--r--pkg/tcpip/tests/integration/iptables_test.go17
-rw-r--r--pkg/tcpip/tests/integration/link_resolution_test.go265
-rw-r--r--pkg/tcpip/tests/integration/loopback_test.go35
-rw-r--r--pkg/tcpip/tests/integration/multicast_broadcast_test.go153
-rw-r--r--pkg/tcpip/tests/integration/route_test.go15
7 files changed, 318 insertions, 510 deletions
diff --git a/pkg/tcpip/tests/integration/BUILD b/pkg/tcpip/tests/integration/BUILD
index 71695b630..58aabe547 100644
--- a/pkg/tcpip/tests/integration/BUILD
+++ b/pkg/tcpip/tests/integration/BUILD
@@ -3,31 +3,57 @@ load("//tools:defs.bzl", "go_test")
package(licenses = ["notice"])
go_test(
- name = "integration_test",
+ name = "forward_test",
size = "small",
- srcs = [
- "forward_test.go",
- "iptables_test.go",
- "link_resolution_test.go",
- "loopback_test.go",
- "multicast_broadcast_test.go",
- "route_test.go",
+ srcs = ["forward_test.go"],
+ deps = [
+ "//pkg/tcpip",
+ "//pkg/tcpip/checker",
+ "//pkg/tcpip/network/arp",
+ "//pkg/tcpip/network/ipv4",
+ "//pkg/tcpip/network/ipv6",
+ "//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
+ "//pkg/tcpip/transport/tcp",
+ "//pkg/tcpip/transport/udp",
+ "//pkg/waiter",
+ "@com_github_google_go_cmp//cmp:go_default_library",
+ ],
+)
+
+go_test(
+ name = "iptables_test",
+ size = "small",
+ srcs = ["iptables_test.go"],
+ deps = [
+ "//pkg/tcpip",
+ "//pkg/tcpip/buffer",
+ "//pkg/tcpip/header",
+ "//pkg/tcpip/link/channel",
+ "//pkg/tcpip/network/ipv4",
+ "//pkg/tcpip/network/ipv6",
+ "//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
+ "//pkg/tcpip/transport/udp",
],
+)
+
+go_test(
+ name = "link_resolution_test",
+ size = "small",
+ srcs = ["link_resolution_test.go"],
deps = [
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/checker",
"//pkg/tcpip/faketime",
"//pkg/tcpip/header",
- "//pkg/tcpip/link/channel",
- "//pkg/tcpip/link/ethernet",
- "//pkg/tcpip/link/loopback",
- "//pkg/tcpip/link/nested",
"//pkg/tcpip/link/pipe",
"//pkg/tcpip/network/arp",
"//pkg/tcpip/network/ipv4",
"//pkg/tcpip/network/ipv6",
"//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
"//pkg/tcpip/transport/icmp",
"//pkg/tcpip/transport/tcp",
"//pkg/tcpip/transport/udp",
@@ -36,3 +62,68 @@ go_test(
"@com_github_google_go_cmp//cmp/cmpopts:go_default_library",
],
)
+
+go_test(
+ name = "loopback_test",
+ size = "small",
+ srcs = ["loopback_test.go"],
+ deps = [
+ "//pkg/tcpip",
+ "//pkg/tcpip/buffer",
+ "//pkg/tcpip/checker",
+ "//pkg/tcpip/header",
+ "//pkg/tcpip/link/loopback",
+ "//pkg/tcpip/network/ipv4",
+ "//pkg/tcpip/network/ipv6",
+ "//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
+ "//pkg/tcpip/transport/tcp",
+ "//pkg/tcpip/transport/udp",
+ "//pkg/waiter",
+ "@com_github_google_go_cmp//cmp:go_default_library",
+ ],
+)
+
+go_test(
+ name = "multicast_broadcast_test",
+ size = "small",
+ srcs = ["multicast_broadcast_test.go"],
+ deps = [
+ "//pkg/tcpip",
+ "//pkg/tcpip/buffer",
+ "//pkg/tcpip/checker",
+ "//pkg/tcpip/header",
+ "//pkg/tcpip/link/channel",
+ "//pkg/tcpip/link/loopback",
+ "//pkg/tcpip/network/ipv4",
+ "//pkg/tcpip/network/ipv6",
+ "//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
+ "//pkg/tcpip/transport/icmp",
+ "//pkg/tcpip/transport/udp",
+ "//pkg/waiter",
+ "@com_github_google_go_cmp//cmp:go_default_library",
+ ],
+)
+
+go_test(
+ name = "route_test",
+ size = "small",
+ srcs = ["route_test.go"],
+ deps = [
+ "//pkg/tcpip",
+ "//pkg/tcpip/buffer",
+ "//pkg/tcpip/checker",
+ "//pkg/tcpip/header",
+ "//pkg/tcpip/link/channel",
+ "//pkg/tcpip/link/loopback",
+ "//pkg/tcpip/network/ipv4",
+ "//pkg/tcpip/network/ipv6",
+ "//pkg/tcpip/stack",
+ "//pkg/tcpip/tests/utils",
+ "//pkg/tcpip/transport/icmp",
+ "//pkg/tcpip/transport/udp",
+ "//pkg/waiter",
+ "@com_github_google_go_cmp//cmp:go_default_library",
+ ],
+)
diff --git a/pkg/tcpip/tests/integration/forward_test.go b/pkg/tcpip/tests/integration/forward_test.go
index 38e1881c7..0cb9d034e 100644
--- a/pkg/tcpip/tests/integration/forward_test.go
+++ b/pkg/tcpip/tests/integration/forward_test.go
@@ -12,231 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package forward_test
import (
"bytes"
- "net"
"testing"
"github.com/google/go-cmp/cmp"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/checker"
- "gvisor.dev/gvisor/pkg/tcpip/header"
- "gvisor.dev/gvisor/pkg/tcpip/link/ethernet"
- "gvisor.dev/gvisor/pkg/tcpip/link/nested"
- "gvisor.dev/gvisor/pkg/tcpip/link/pipe"
"gvisor.dev/gvisor/pkg/tcpip/network/arp"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
)
-var _ stack.NetworkDispatcher = (*endpointWithDestinationCheck)(nil)
-var _ stack.LinkEndpoint = (*endpointWithDestinationCheck)(nil)
-
-const (
- host1NICID = 1
- routerNICID1 = 2
- routerNICID2 = 3
- host2NICID = 4
-)
-
-var (
- host1IPv4Addr = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.0.2").To4()),
- PrefixLen: 24,
- },
- }
- routerNIC1IPv4Addr = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.0.1").To4()),
- PrefixLen: 24,
- },
- }
- routerNIC2IPv4Addr = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("10.0.0.1").To4()),
- PrefixLen: 8,
- },
- }
- host2IPv4Addr = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("10.0.0.2").To4()),
- PrefixLen: 8,
- },
- }
- host1IPv6Addr = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("a::2").To16()),
- PrefixLen: 64,
- },
- }
- routerNIC1IPv6Addr = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("a::1").To16()),
- PrefixLen: 64,
- },
- }
- routerNIC2IPv6Addr = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("b::1").To16()),
- PrefixLen: 64,
- },
- }
- host2IPv6Addr = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("b::2").To16()),
- PrefixLen: 64,
- },
- }
-)
-
-func setupRoutedStacks(t *testing.T, host1Stack, routerStack, host2Stack *stack.Stack) {
- host1NIC, routerNIC1 := pipe.New(linkAddr1, linkAddr2)
- routerNIC2, host2NIC := pipe.New(linkAddr3, linkAddr4)
-
- if err := host1Stack.CreateNIC(host1NICID, newEthernetEndpoint(host1NIC)); err != nil {
- t.Fatalf("host1Stack.CreateNIC(%d, _): %s", host1NICID, err)
- }
- if err := routerStack.CreateNIC(routerNICID1, newEthernetEndpoint(routerNIC1)); err != nil {
- t.Fatalf("routerStack.CreateNIC(%d, _): %s", routerNICID1, err)
- }
- if err := routerStack.CreateNIC(routerNICID2, newEthernetEndpoint(routerNIC2)); err != nil {
- t.Fatalf("routerStack.CreateNIC(%d, _): %s", routerNICID2, err)
- }
- if err := host2Stack.CreateNIC(host2NICID, newEthernetEndpoint(host2NIC)); err != nil {
- t.Fatalf("host2Stack.CreateNIC(%d, _): %s", host2NICID, err)
- }
-
- if err := routerStack.SetForwarding(ipv4.ProtocolNumber, true); err != nil {
- t.Fatalf("routerStack.SetForwarding(%d): %s", ipv4.ProtocolNumber, err)
- }
- if err := routerStack.SetForwarding(ipv6.ProtocolNumber, true); err != nil {
- t.Fatalf("routerStack.SetForwarding(%d): %s", ipv6.ProtocolNumber, err)
- }
-
- if err := host1Stack.AddProtocolAddress(host1NICID, host1IPv4Addr); err != nil {
- t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, host1IPv4Addr, err)
- }
- if err := routerStack.AddProtocolAddress(routerNICID1, routerNIC1IPv4Addr); err != nil {
- t.Fatalf("routerStack.AddProtocolAddress(%d, %#v): %s", routerNICID1, routerNIC1IPv4Addr, err)
- }
- if err := routerStack.AddProtocolAddress(routerNICID2, routerNIC2IPv4Addr); err != nil {
- t.Fatalf("routerStack.AddProtocolAddress(%d, %#v): %s", routerNICID2, routerNIC2IPv4Addr, err)
- }
- if err := host2Stack.AddProtocolAddress(host2NICID, host2IPv4Addr); err != nil {
- t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, host2IPv4Addr, err)
- }
- if err := host1Stack.AddProtocolAddress(host1NICID, host1IPv6Addr); err != nil {
- t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, host1IPv6Addr, err)
- }
- if err := routerStack.AddProtocolAddress(routerNICID1, routerNIC1IPv6Addr); err != nil {
- t.Fatalf("routerStack.AddProtocolAddress(%d, %#v): %s", routerNICID1, routerNIC1IPv6Addr, err)
- }
- if err := routerStack.AddProtocolAddress(routerNICID2, routerNIC2IPv6Addr); err != nil {
- t.Fatalf("routerStack.AddProtocolAddress(%d, %#v): %s", routerNICID2, routerNIC2IPv6Addr, err)
- }
- if err := host2Stack.AddProtocolAddress(host2NICID, host2IPv6Addr); err != nil {
- t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, host2IPv6Addr, err)
- }
-
- host1Stack.SetRouteTable([]tcpip.Route{
- {
- Destination: host1IPv4Addr.AddressWithPrefix.Subnet(),
- NIC: host1NICID,
- },
- {
- Destination: host1IPv6Addr.AddressWithPrefix.Subnet(),
- NIC: host1NICID,
- },
- {
- Destination: host2IPv4Addr.AddressWithPrefix.Subnet(),
- Gateway: routerNIC1IPv4Addr.AddressWithPrefix.Address,
- NIC: host1NICID,
- },
- {
- Destination: host2IPv6Addr.AddressWithPrefix.Subnet(),
- Gateway: routerNIC1IPv6Addr.AddressWithPrefix.Address,
- NIC: host1NICID,
- },
- })
- routerStack.SetRouteTable([]tcpip.Route{
- {
- Destination: routerNIC1IPv4Addr.AddressWithPrefix.Subnet(),
- NIC: routerNICID1,
- },
- {
- Destination: routerNIC1IPv6Addr.AddressWithPrefix.Subnet(),
- NIC: routerNICID1,
- },
- {
- Destination: routerNIC2IPv4Addr.AddressWithPrefix.Subnet(),
- NIC: routerNICID2,
- },
- {
- Destination: routerNIC2IPv6Addr.AddressWithPrefix.Subnet(),
- NIC: routerNICID2,
- },
- })
- host2Stack.SetRouteTable([]tcpip.Route{
- {
- Destination: host2IPv4Addr.AddressWithPrefix.Subnet(),
- NIC: host2NICID,
- },
- {
- Destination: host2IPv6Addr.AddressWithPrefix.Subnet(),
- NIC: host2NICID,
- },
- {
- Destination: host1IPv4Addr.AddressWithPrefix.Subnet(),
- Gateway: routerNIC2IPv4Addr.AddressWithPrefix.Address,
- NIC: host2NICID,
- },
- {
- Destination: host1IPv6Addr.AddressWithPrefix.Subnet(),
- Gateway: routerNIC2IPv6Addr.AddressWithPrefix.Address,
- NIC: host2NICID,
- },
- })
-}
-
-// newEthernetEndpoint returns an ethernet link endpoint that wraps an inner
-// link endpoint and checks the destination link address before delivering
-// network packets to the network dispatcher.
-//
-// See ethernet.Endpoint for more details.
-func newEthernetEndpoint(ep stack.LinkEndpoint) *endpointWithDestinationCheck {
- var e endpointWithDestinationCheck
- e.Endpoint.Init(ethernet.New(ep), &e)
- return &e
-}
-
-// endpointWithDestinationCheck is a link endpoint that checks the destination
-// link address before delivering network packets to the network dispatcher.
-type endpointWithDestinationCheck struct {
- nested.Endpoint
-}
-
-// DeliverNetworkPacket implements stack.NetworkDispatcher.
-func (e *endpointWithDestinationCheck) DeliverNetworkPacket(src, dst tcpip.LinkAddress, proto tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
- if dst == e.Endpoint.LinkAddress() || dst == header.EthernetBroadcastAddress || header.IsMulticastEthernetAddress(dst) {
- e.Endpoint.DeliverNetworkPacket(src, dst, proto, pkt)
- }
-}
-
func TestForwarding(t *testing.T) {
const listenPort = 8080
@@ -278,11 +72,11 @@ func TestForwarding(t *testing.T) {
ep2, ep2WECH := newEP(t, host2Stack, proto, ipv4.ProtocolNumber)
return endpointAndAddresses{
serverEP: ep1,
- serverAddr: host1IPv4Addr.AddressWithPrefix.Address,
+ serverAddr: utils.Host1IPv4Addr.AddressWithPrefix.Address,
serverReadableCH: ep1WECH,
clientEP: ep2,
- clientAddr: host2IPv4Addr.AddressWithPrefix.Address,
+ clientAddr: utils.Host2IPv4Addr.AddressWithPrefix.Address,
clientReadableCH: ep2WECH,
}
},
@@ -294,11 +88,11 @@ func TestForwarding(t *testing.T) {
ep2, ep2WECH := newEP(t, host1Stack, proto, ipv6.ProtocolNumber)
return endpointAndAddresses{
serverEP: ep1,
- serverAddr: host2IPv6Addr.AddressWithPrefix.Address,
+ serverAddr: utils.Host2IPv6Addr.AddressWithPrefix.Address,
serverReadableCH: ep1WECH,
clientEP: ep2,
- clientAddr: host1IPv6Addr.AddressWithPrefix.Address,
+ clientAddr: utils.Host1IPv6Addr.AddressWithPrefix.Address,
clientReadableCH: ep2WECH,
}
},
@@ -310,11 +104,11 @@ func TestForwarding(t *testing.T) {
ep2, ep2WECH := newEP(t, routerStack, proto, ipv4.ProtocolNumber)
return endpointAndAddresses{
serverEP: ep1,
- serverAddr: host2IPv4Addr.AddressWithPrefix.Address,
+ serverAddr: utils.Host2IPv4Addr.AddressWithPrefix.Address,
serverReadableCH: ep1WECH,
clientEP: ep2,
- clientAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
+ clientAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
clientReadableCH: ep2WECH,
}
},
@@ -326,11 +120,11 @@ func TestForwarding(t *testing.T) {
ep2, ep2WECH := newEP(t, host1Stack, proto, ipv6.ProtocolNumber)
return endpointAndAddresses{
serverEP: ep1,
- serverAddr: routerNIC2IPv6Addr.AddressWithPrefix.Address,
+ serverAddr: utils.RouterNIC2IPv6Addr.AddressWithPrefix.Address,
serverReadableCH: ep1WECH,
clientEP: ep2,
- clientAddr: host1IPv6Addr.AddressWithPrefix.Address,
+ clientAddr: utils.Host1IPv6Addr.AddressWithPrefix.Address,
clientReadableCH: ep2WECH,
}
},
@@ -405,7 +199,7 @@ func TestForwarding(t *testing.T) {
host1Stack := stack.New(stackOpts)
routerStack := stack.New(stackOpts)
host2Stack := stack.New(stackOpts)
- setupRoutedStacks(t, host1Stack, routerStack, host2Stack)
+ utils.SetupRoutedStacks(t, host1Stack, routerStack, host2Stack)
epsAndAddrs := test.epAndAddrs(t, host1Stack, routerStack, host2Stack, subTest.proto)
defer epsAndAddrs.serverEP.Close()
diff --git a/pkg/tcpip/tests/integration/iptables_test.go b/pkg/tcpip/tests/integration/iptables_test.go
index b56706357..480174070 100644
--- a/pkg/tcpip/tests/integration/iptables_test.go
+++ b/pkg/tcpip/tests/integration/iptables_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package iptables_test
import (
"testing"
@@ -24,6 +24,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
)
@@ -375,7 +376,7 @@ func TestIPTableWritePackets(t *testing.T) {
const (
nicID = 1
- dropLocalPort = localPort - 1
+ dropLocalPort = utils.LocalPort - 1
acceptPackets = 2
dropPackets = 3
)
@@ -411,7 +412,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, localPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, utils.LocalPort, utils.RemotePort)
pkts.PushFront(pkt)
return pkts
@@ -473,7 +474,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, localPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, utils.LocalPort, utils.RemotePort)
pkts.PushFront(pkt)
}
for i := 0; i < dropPackets; i++ {
@@ -481,7 +482,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, dropLocalPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, dropLocalPort, utils.RemotePort)
pkts.PushFront(pkt)
}
@@ -502,7 +503,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, localPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, utils.LocalPort, utils.RemotePort)
pkts.PushFront(pkt)
return pkts
@@ -564,7 +565,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, localPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, utils.LocalPort, utils.RemotePort)
pkts.PushFront(pkt)
}
for i := 0; i < dropPackets; i++ {
@@ -572,7 +573,7 @@ func TestIPTableWritePackets(t *testing.T) {
ReserveHeaderBytes: int(r.MaxHeaderLength() + header.UDPMinimumSize),
})
hdr := pkt.TransportHeader().Push(header.UDPMinimumSize)
- udpHdr(hdr, r.LocalAddress, r.RemoteAddress, dropLocalPort, remotePort)
+ udpHdr(hdr, r.LocalAddress, r.RemoteAddress, dropLocalPort, utils.RemotePort)
pkts.PushFront(pkt)
}
diff --git a/pkg/tcpip/tests/integration/link_resolution_test.go b/pkg/tcpip/tests/integration/link_resolution_test.go
index 824f81a42..18da67fb1 100644
--- a/pkg/tcpip/tests/integration/link_resolution_test.go
+++ b/pkg/tcpip/tests/integration/link_resolution_test.go
@@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package link_resolution_test
import (
"bytes"
"fmt"
- "net"
"testing"
"time"
@@ -33,107 +32,56 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
)
-const (
- linkAddr1 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x06")
- linkAddr2 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x07")
- linkAddr3 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x08")
- linkAddr4 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x09")
-)
-
-var (
- ipv4Addr1 = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.0.1").To4()),
- PrefixLen: 24,
- },
- }
- ipv4Addr2 = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.0.2").To4()),
- PrefixLen: 8,
- },
- }
- ipv4Addr3 = tcpip.ProtocolAddress{
- Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.0.3").To4()),
- PrefixLen: 8,
- },
- }
- ipv6Addr1 = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("a::1").To16()),
- PrefixLen: 64,
- },
- }
- ipv6Addr2 = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("a::2").To16()),
- PrefixLen: 64,
- },
- }
- ipv6Addr3 = tcpip.ProtocolAddress{
- Protocol: ipv6.ProtocolNumber,
- AddressWithPrefix: tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("a::3").To16()),
- PrefixLen: 64,
- },
- }
-)
-
func setupStack(t *testing.T, stackOpts stack.Options, host1NICID, host2NICID tcpip.NICID) (*stack.Stack, *stack.Stack) {
host1Stack := stack.New(stackOpts)
host2Stack := stack.New(stackOpts)
- host1NIC, host2NIC := pipe.New(linkAddr1, linkAddr2)
+ host1NIC, host2NIC := pipe.New(utils.LinkAddr1, utils.LinkAddr2)
- if err := host1Stack.CreateNIC(host1NICID, newEthernetEndpoint(host1NIC)); err != nil {
+ if err := host1Stack.CreateNIC(host1NICID, utils.NewEthernetEndpoint(host1NIC)); err != nil {
t.Fatalf("host1Stack.CreateNIC(%d, _): %s", host1NICID, err)
}
- if err := host2Stack.CreateNIC(host2NICID, newEthernetEndpoint(host2NIC)); err != nil {
+ if err := host2Stack.CreateNIC(host2NICID, utils.NewEthernetEndpoint(host2NIC)); err != nil {
t.Fatalf("host2Stack.CreateNIC(%d, _): %s", host2NICID, err)
}
- if err := host1Stack.AddProtocolAddress(host1NICID, ipv4Addr1); err != nil {
- t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, ipv4Addr1, err)
+ if err := host1Stack.AddProtocolAddress(host1NICID, utils.Ipv4Addr1); err != nil {
+ t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, utils.Ipv4Addr1, err)
}
- if err := host2Stack.AddProtocolAddress(host2NICID, ipv4Addr2); err != nil {
- t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, ipv4Addr2, err)
+ if err := host2Stack.AddProtocolAddress(host2NICID, utils.Ipv4Addr2); err != nil {
+ t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, utils.Ipv4Addr2, err)
}
- if err := host1Stack.AddProtocolAddress(host1NICID, ipv6Addr1); err != nil {
- t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, ipv6Addr1, err)
+ if err := host1Stack.AddProtocolAddress(host1NICID, utils.Ipv6Addr1); err != nil {
+ t.Fatalf("host1Stack.AddProtocolAddress(%d, %#v): %s", host1NICID, utils.Ipv6Addr1, err)
}
- if err := host2Stack.AddProtocolAddress(host2NICID, ipv6Addr2); err != nil {
- t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, ipv6Addr2, err)
+ if err := host2Stack.AddProtocolAddress(host2NICID, utils.Ipv6Addr2); err != nil {
+ t.Fatalf("host2Stack.AddProtocolAddress(%d, %#v): %s", host2NICID, utils.Ipv6Addr2, err)
}
host1Stack.SetRouteTable([]tcpip.Route{
{
- Destination: ipv4Addr1.AddressWithPrefix.Subnet(),
+ Destination: utils.Ipv4Addr1.AddressWithPrefix.Subnet(),
NIC: host1NICID,
},
{
- Destination: ipv6Addr1.AddressWithPrefix.Subnet(),
+ Destination: utils.Ipv6Addr1.AddressWithPrefix.Subnet(),
NIC: host1NICID,
},
})
host2Stack.SetRouteTable([]tcpip.Route{
{
- Destination: ipv4Addr2.AddressWithPrefix.Subnet(),
+ Destination: utils.Ipv4Addr2.AddressWithPrefix.Subnet(),
NIC: host2NICID,
},
{
- Destination: ipv6Addr2.AddressWithPrefix.Subnet(),
+ Destination: utils.Ipv6Addr2.AddressWithPrefix.Subnet(),
NIC: host2NICID,
},
})
@@ -164,7 +112,7 @@ func TestPing(t *testing.T) {
name: "IPv4 Ping",
transProto: icmp.ProtocolNumber4,
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
icmpBuf: func(t *testing.T) []byte {
data := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
hdr := header.ICMPv4(make([]byte, header.ICMPv4MinimumSize+len(data)))
@@ -179,7 +127,7 @@ func TestPing(t *testing.T) {
name: "IPv6 Ping",
transProto: icmp.ProtocolNumber6,
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
icmpBuf: func(t *testing.T) []byte {
data := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
hdr := header.ICMPv6(make([]byte, header.ICMPv6MinimumSize+len(data)))
@@ -272,30 +220,30 @@ func TestTCPLinkResolutionFailure(t *testing.T) {
{
name: "IPv4 with resolvable remote",
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
expectedWriteErr: nil,
},
{
name: "IPv6 with resolvable remote",
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
expectedWriteErr: nil,
},
{
name: "IPv4 without resolvable remote",
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr3.AddressWithPrefix.Address,
expectedWriteErr: &tcpip.ErrNoRoute{},
sockError: tcpip.SockError{
Err: &tcpip.ErrNoRoute{},
Dst: tcpip.FullAddress{
NIC: host1NICID,
- Addr: ipv4Addr3.AddressWithPrefix.Address,
+ Addr: utils.Ipv4Addr3.AddressWithPrefix.Address,
Port: 1234,
},
Offender: tcpip.FullAddress{
NIC: host1NICID,
- Addr: ipv4Addr1.AddressWithPrefix.Address,
+ Addr: utils.Ipv4Addr1.AddressWithPrefix.Address,
},
NetProto: ipv4.ProtocolNumber,
},
@@ -309,18 +257,18 @@ func TestTCPLinkResolutionFailure(t *testing.T) {
{
name: "IPv6 without resolvable remote",
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr3.AddressWithPrefix.Address,
expectedWriteErr: &tcpip.ErrNoRoute{},
sockError: tcpip.SockError{
Err: &tcpip.ErrNoRoute{},
Dst: tcpip.FullAddress{
NIC: host1NICID,
- Addr: ipv6Addr3.AddressWithPrefix.Address,
+ Addr: utils.Ipv6Addr3.AddressWithPrefix.Address,
Port: 1234,
},
Offender: tcpip.FullAddress{
NIC: host1NICID,
- Addr: ipv6Addr1.AddressWithPrefix.Address,
+ Addr: utils.Ipv6Addr1.AddressWithPrefix.Address,
},
NetProto: ipv6.ProtocolNumber,
},
@@ -462,25 +410,25 @@ func TestGetLinkAddress(t *testing.T) {
{
name: "IPv4 resolvable",
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
expectedOk: true,
},
{
name: "IPv6 resolvable",
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
expectedOk: true,
},
{
name: "IPv4 not resolvable",
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr3.AddressWithPrefix.Address,
expectedOk: false,
},
{
name: "IPv6 not resolvable",
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr3.AddressWithPrefix.Address,
expectedOk: false,
},
}
@@ -502,7 +450,7 @@ func TestGetLinkAddress(t *testing.T) {
}
wantRes := stack.LinkResolutionResult{Success: test.expectedOk}
if test.expectedOk {
- wantRes.LinkAddress = linkAddr2
+ wantRes.LinkAddress = utils.LinkAddr2
}
if diff := cmp.Diff(wantRes, <-ch); diff != "" {
t.Fatalf("link resolution result mismatch (-want +got):\n%s", diff)
@@ -529,7 +477,7 @@ func TestRouteResolvedFields(t *testing.T) {
{
name: "IPv4 immediately resolvable",
netProto: ipv4.ProtocolNumber,
- localAddr: ipv4Addr1.AddressWithPrefix.Address,
+ localAddr: utils.Ipv4Addr1.AddressWithPrefix.Address,
remoteAddr: header.IPv4AllSystems,
immediatelyResolvable: true,
expectedSuccess: true,
@@ -538,7 +486,7 @@ func TestRouteResolvedFields(t *testing.T) {
{
name: "IPv6 immediately resolvable",
netProto: ipv6.ProtocolNumber,
- localAddr: ipv6Addr1.AddressWithPrefix.Address,
+ localAddr: utils.Ipv6Addr1.AddressWithPrefix.Address,
remoteAddr: header.IPv6AllNodesMulticastAddress,
immediatelyResolvable: true,
expectedSuccess: true,
@@ -547,34 +495,34 @@ func TestRouteResolvedFields(t *testing.T) {
{
name: "IPv4 resolvable",
netProto: ipv4.ProtocolNumber,
- localAddr: ipv4Addr1.AddressWithPrefix.Address,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ localAddr: utils.Ipv4Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
immediatelyResolvable: false,
expectedSuccess: true,
- expectedLinkAddr: linkAddr2,
+ expectedLinkAddr: utils.LinkAddr2,
},
{
name: "IPv6 resolvable",
netProto: ipv6.ProtocolNumber,
- localAddr: ipv6Addr1.AddressWithPrefix.Address,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ localAddr: utils.Ipv6Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
immediatelyResolvable: false,
expectedSuccess: true,
- expectedLinkAddr: linkAddr2,
+ expectedLinkAddr: utils.LinkAddr2,
},
{
name: "IPv4 not resolvable",
netProto: ipv4.ProtocolNumber,
- localAddr: ipv4Addr1.AddressWithPrefix.Address,
- remoteAddr: ipv4Addr3.AddressWithPrefix.Address,
+ localAddr: utils.Ipv4Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr3.AddressWithPrefix.Address,
immediatelyResolvable: false,
expectedSuccess: false,
},
{
name: "IPv6 not resolvable",
netProto: ipv6.ProtocolNumber,
- localAddr: ipv6Addr1.AddressWithPrefix.Address,
- remoteAddr: ipv6Addr3.AddressWithPrefix.Address,
+ localAddr: utils.Ipv6Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr3.AddressWithPrefix.Address,
immediatelyResolvable: false,
expectedSuccess: false,
},
@@ -594,7 +542,7 @@ func TestRouteResolvedFields(t *testing.T) {
defer r.Release()
var wantRouteInfo stack.RouteInfo
- wantRouteInfo.LocalLinkAddress = linkAddr1
+ wantRouteInfo.LocalLinkAddress = utils.LinkAddr1
wantRouteInfo.LocalAddress = test.localAddr
wantRouteInfo.RemoteAddress = test.remoteAddr
wantRouteInfo.NetProto = test.netProto
@@ -657,13 +605,13 @@ func TestWritePacketsLinkResolution(t *testing.T) {
{
name: "IPv4",
netProto: ipv4.ProtocolNumber,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
expectedWriteErr: nil,
},
{
name: "IPv6",
netProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
expectedWriteErr: nil,
},
}
@@ -850,8 +798,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv4 active connection through neighbor",
netProto: ipv4.ProtocolNumber,
- remoteAddr: host2IPv4Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host2IPv4Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, _, host2Stack *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host2Stack.NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, &listenerWQ)
@@ -874,8 +822,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv6 active connection through neighbor",
netProto: ipv6.ProtocolNumber,
- remoteAddr: host2IPv6Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv6Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host2IPv6Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv6Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, _, host2Stack *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host2Stack.NewEndpoint(tcp.ProtocolNumber, ipv6.ProtocolNumber, &listenerWQ)
@@ -898,8 +846,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv4 active connection to neighbor",
netProto: ipv4.ProtocolNumber,
- remoteAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, routerStack, _ *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := routerStack.NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, &listenerWQ)
@@ -922,8 +870,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv6 active connection to neighbor",
netProto: ipv6.ProtocolNumber,
- remoteAddr: routerNIC1IPv6Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv6Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.RouterNIC1IPv6Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv6Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, routerStack, _ *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := routerStack.NewEndpoint(tcp.ProtocolNumber, ipv6.ProtocolNumber, &listenerWQ)
@@ -946,8 +894,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv4 passive connection to neighbor",
netProto: ipv4.ProtocolNumber,
- remoteAddr: host1IPv4Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host1IPv4Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, routerStack, _ *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host1Stack.NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, &listenerWQ)
@@ -971,8 +919,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv6 passive connection to neighbor",
netProto: ipv6.ProtocolNumber,
- remoteAddr: host1IPv6Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv6Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host1IPv6Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv6Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, routerStack, _ *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host1Stack.NewEndpoint(tcp.ProtocolNumber, ipv6.ProtocolNumber, &listenerWQ)
@@ -996,8 +944,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv4 passive connection through neighbor",
netProto: ipv4.ProtocolNumber,
- remoteAddr: host1IPv4Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv4Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host1IPv4Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv4Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, _, host2Stack *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host1Stack.NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, &listenerWQ)
@@ -1021,8 +969,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
{
name: "IPv6 passive connection through neighbor",
netProto: ipv6.ProtocolNumber,
- remoteAddr: host1IPv6Addr.AddressWithPrefix.Address,
- neighborAddr: routerNIC1IPv6Addr.AddressWithPrefix.Address,
+ remoteAddr: utils.Host1IPv6Addr.AddressWithPrefix.Address,
+ neighborAddr: utils.RouterNIC1IPv6Addr.AddressWithPrefix.Address,
getEndpoints: func(t *testing.T, host1Stack, _, host2Stack *stack.Stack) (tcpip.Endpoint, tcpip.Endpoint, <-chan struct{}) {
var listenerWQ waiter.Queue
listenerEP, err := host1Stack.NewEndpoint(tcp.ProtocolNumber, ipv6.ProtocolNumber, &listenerWQ)
@@ -1062,41 +1010,41 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
host1Stack := stack.New(host1StackOpts)
routerStack := stack.New(stackOpts)
host2Stack := stack.New(stackOpts)
- setupRoutedStacks(t, host1Stack, routerStack, host2Stack)
+ utils.SetupRoutedStacks(t, host1Stack, routerStack, host2Stack)
// Add a reachable dynamic entry to our neighbor table for the remote.
{
ch := make(chan stack.LinkResolutionResult, 1)
- err := host1Stack.GetLinkAddress(host1NICID, test.neighborAddr, "", test.netProto, func(r stack.LinkResolutionResult) {
+ err := host1Stack.GetLinkAddress(utils.Host1NICID, test.neighborAddr, "", test.netProto, func(r stack.LinkResolutionResult) {
ch <- r
})
if _, ok := err.(*tcpip.ErrWouldBlock); !ok {
- t.Fatalf("got host1Stack.GetLinkAddress(%d, %s, '', %d, _) = %s, want = %s", host1NICID, test.neighborAddr, test.netProto, err, &tcpip.ErrWouldBlock{})
+ t.Fatalf("got host1Stack.GetLinkAddress(%d, %s, '', %d, _) = %s, want = %s", utils.Host1NICID, test.neighborAddr, test.netProto, err, &tcpip.ErrWouldBlock{})
}
- if diff := cmp.Diff(stack.LinkResolutionResult{LinkAddress: linkAddr2, Success: true}, <-ch); diff != "" {
+ if diff := cmp.Diff(stack.LinkResolutionResult{LinkAddress: utils.LinkAddr2, Success: true}, <-ch); diff != "" {
t.Fatalf("link resolution mismatch (-want +got):\n%s", diff)
}
}
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryAdded,
- nicID: host1NICID,
+ nicID: utils.Host1NICID,
entry: stack.NeighborEntry{State: stack.Incomplete, Addr: test.neighborAddr},
}); err != nil {
t.Fatalf("error waiting for initial NUD event: %s", err)
}
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for reachable NUD event: %s", err)
}
// Wait for the remote's neighbor entry to be stale before creating a
// TCP connection from host1 to some remote.
- nudConfigs, err := host1Stack.NUDConfigurations(host1NICID, test.netProto)
+ nudConfigs, err := host1Stack.NUDConfigurations(utils.Host1NICID, test.netProto)
if err != nil {
- t.Fatalf("host1Stack.NUDConfigurations(%d, %d): %s", host1NICID, test.netProto, err)
+ t.Fatalf("host1Stack.NUDConfigurations(%d, %d): %s", utils.Host1NICID, test.netProto, err)
}
// The maximum reachable time for a neighbor is some maximum random factor
// applied to the base reachable time.
@@ -1106,8 +1054,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
clock.Advance(maxReachableTime)
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Stale, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Stale, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for stale NUD event: %s", err)
}
@@ -1136,15 +1084,15 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
<-clientCH
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Delay, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Delay, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for delay NUD event: %s", err)
}
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for reachable NUD event: %s", err)
}
@@ -1157,8 +1105,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
clock.Advance(maxReachableTime)
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Stale, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Stale, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for stale NUD event: %s", err)
}
@@ -1170,8 +1118,8 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
}
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Delay, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Delay, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for delay NUD event: %s", err)
}
@@ -1183,16 +1131,16 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
clock.Advance(nudConfigs.DelayFirstProbeTime)
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Probe, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Probe, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for probe NUD event: %s", err)
}
}
if err := nudDisp.waitForEvent(eventInfo{
eventType: entryChanged,
- nicID: host1NICID,
- entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: linkAddr2},
+ nicID: utils.Host1NICID,
+ entry: stack.NeighborEntry{State: stack.Reachable, Addr: test.neighborAddr, LinkAddr: utils.LinkAddr2},
}); err != nil {
t.Fatalf("error waiting for reachable NUD event: %s", err)
}
@@ -1201,11 +1149,6 @@ func TestTCPConfirmNeighborReachability(t *testing.T) {
}
func TestDAD(t *testing.T) {
- const (
- host1NICID = 1
- host2NICID = 4
- )
-
dadConfigs := stack.DADConfigurations{
DupAddrDetectTransmits: 1,
RetransmitTimer: time.Second,
@@ -1222,42 +1165,42 @@ func TestDAD(t *testing.T) {
name: "IPv4 own address",
netProto: ipv4.ProtocolNumber,
dadNetProto: arp.ProtocolNumber,
- remoteAddr: ipv4Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr1.AddressWithPrefix.Address,
expectedResolved: true,
},
{
name: "IPv6 own address",
netProto: ipv6.ProtocolNumber,
dadNetProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr1.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr1.AddressWithPrefix.Address,
expectedResolved: true,
},
{
name: "IPv4 duplicate address",
netProto: ipv4.ProtocolNumber,
dadNetProto: arp.ProtocolNumber,
- remoteAddr: ipv4Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr2.AddressWithPrefix.Address,
expectedResolved: false,
},
{
name: "IPv6 duplicate address",
netProto: ipv6.ProtocolNumber,
dadNetProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr2.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr2.AddressWithPrefix.Address,
expectedResolved: false,
},
{
name: "IPv4 no duplicate address",
netProto: ipv4.ProtocolNumber,
dadNetProto: arp.ProtocolNumber,
- remoteAddr: ipv4Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv4Addr3.AddressWithPrefix.Address,
expectedResolved: true,
},
{
name: "IPv6 no duplicate address",
netProto: ipv6.ProtocolNumber,
dadNetProto: ipv6.ProtocolNumber,
- remoteAddr: ipv6Addr3.AddressWithPrefix.Address,
+ remoteAddr: utils.Ipv6Addr3.AddressWithPrefix.Address,
expectedResolved: true,
},
}
@@ -1274,21 +1217,21 @@ func TestDAD(t *testing.T) {
},
}
- host1Stack, _ := setupStack(t, stackOpts, host1NICID, host2NICID)
+ host1Stack, _ := setupStack(t, stackOpts, utils.Host1NICID, utils.Host2NICID)
// DAD should be disabled by default.
- if res, err := host1Stack.CheckDuplicateAddress(host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
+ if res, err := host1Stack.CheckDuplicateAddress(utils.Host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
t.Errorf("unexpectedly called DAD completion handler when DAD was supposed to be disabled")
}); err != nil {
- t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", host1NICID, test.netProto, test.remoteAddr, err)
+ t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", utils.Host1NICID, test.netProto, test.remoteAddr, err)
} else if res != stack.DADDisabled {
- t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", host1NICID, test.netProto, test.remoteAddr, res, stack.DADDisabled)
+ t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", utils.Host1NICID, test.netProto, test.remoteAddr, res, stack.DADDisabled)
}
// Enable DAD then attempt to check if an address is duplicated.
- netEP, err := host1Stack.GetNetworkEndpoint(host1NICID, test.dadNetProto)
+ netEP, err := host1Stack.GetNetworkEndpoint(utils.Host1NICID, test.dadNetProto)
if err != nil {
- t.Fatalf("host1Stack.GetNetworkEndpoint(%d, %d): %s", host1NICID, test.dadNetProto, err)
+ t.Fatalf("host1Stack.GetNetworkEndpoint(%d, %d): %s", utils.Host1NICID, test.dadNetProto, err)
}
dad, ok := netEP.(stack.DuplicateAddressDetector)
if !ok {
@@ -1296,12 +1239,12 @@ func TestDAD(t *testing.T) {
}
dad.SetDADConfigurations(dadConfigs)
ch := make(chan stack.DADResult, 3)
- if res, err := host1Stack.CheckDuplicateAddress(host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
+ if res, err := host1Stack.CheckDuplicateAddress(utils.Host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
ch <- r
}); err != nil {
- t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", host1NICID, test.netProto, test.remoteAddr, err)
+ t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", utils.Host1NICID, test.netProto, test.remoteAddr, err)
} else if res != stack.DADStarting {
- t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", host1NICID, test.netProto, test.remoteAddr, res, stack.DADStarting)
+ t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", utils.Host1NICID, test.netProto, test.remoteAddr, res, stack.DADStarting)
}
expectResults := 1
@@ -1318,12 +1261,12 @@ func TestDAD(t *testing.T) {
// same address. The handler for the new request should be called once
// the original DAD request completes.
expectResults = 2
- if res, err := host1Stack.CheckDuplicateAddress(host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
+ if res, err := host1Stack.CheckDuplicateAddress(utils.Host1NICID, test.netProto, test.remoteAddr, func(r stack.DADResult) {
ch <- r
}); err != nil {
- t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", host1NICID, test.netProto, test.remoteAddr, err)
+ t.Fatalf("host1Stack.CheckDuplicateAddress(%d, %d, %s, _): %s", utils.Host1NICID, test.netProto, test.remoteAddr, err)
} else if res != stack.DADAlreadyRunning {
- t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", host1NICID, test.netProto, test.remoteAddr, res, stack.DADAlreadyRunning)
+ t.Errorf("got host1Stack.CheckDuplicateAddress(%d, %d, %s, _) = %d, want = %d", utils.Host1NICID, test.netProto, test.remoteAddr, res, stack.DADAlreadyRunning)
}
clock.Advance(delta)
diff --git a/pkg/tcpip/tests/integration/loopback_test.go b/pkg/tcpip/tests/integration/loopback_test.go
index ab67762ef..c56155ea2 100644
--- a/pkg/tcpip/tests/integration/loopback_test.go
+++ b/pkg/tcpip/tests/integration/loopback_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package loopback_test
import (
"bytes"
@@ -28,6 +28,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
@@ -109,7 +110,7 @@ func TestLoopbackAcceptAllInSubnetUDP(t *testing.T) {
ipv4ProtocolAddress := tcpip.ProtocolAddress{
Protocol: header.IPv4ProtocolNumber,
- AddressWithPrefix: ipv4Addr,
+ AddressWithPrefix: utils.Ipv4Addr,
}
ipv4Bytes := []byte(ipv4ProtocolAddress.AddressWithPrefix.Address)
ipv4Bytes[len(ipv4Bytes)-1]++
@@ -117,9 +118,9 @@ func TestLoopbackAcceptAllInSubnetUDP(t *testing.T) {
ipv6ProtocolAddress := tcpip.ProtocolAddress{
Protocol: header.IPv6ProtocolNumber,
- AddressWithPrefix: ipv6Addr,
+ AddressWithPrefix: utils.Ipv6Addr,
}
- ipv6Bytes := []byte(ipv6Addr.Address)
+ ipv6Bytes := []byte(utils.Ipv6Addr.Address)
ipv6Bytes[len(ipv6Bytes)-1]++
otherIPv6Address := tcpip.Address(ipv6Bytes)
@@ -145,7 +146,7 @@ func TestLoopbackAcceptAllInSubnetUDP(t *testing.T) {
{
name: "IPv4 bind to wildcard send to other address",
addAddress: ipv4ProtocolAddress,
- dstAddr: remoteIPv4Addr,
+ dstAddr: utils.RemoteIPv4Addr,
expectRx: false,
},
{
@@ -173,8 +174,8 @@ func TestLoopbackAcceptAllInSubnetUDP(t *testing.T) {
{
name: "IPv6 bind and send to assigned address",
addAddress: ipv6ProtocolAddress,
- bindAddr: ipv6Addr.Address,
- dstAddr: ipv6Addr.Address,
+ bindAddr: utils.Ipv6Addr.Address,
+ dstAddr: utils.Ipv6Addr.Address,
expectRx: true,
},
{
@@ -277,9 +278,9 @@ func TestLoopbackSubnetLifetimeBoundToAddr(t *testing.T) {
protoAddr := tcpip.ProtocolAddress{
Protocol: ipv4.ProtocolNumber,
- AddressWithPrefix: ipv4Addr,
+ AddressWithPrefix: utils.Ipv4Addr,
}
- addrBytes := []byte(ipv4Addr.Address)
+ addrBytes := []byte(utils.Ipv4Addr.Address)
addrBytes[len(addrBytes)-1]++
otherAddr := tcpip.Address(addrBytes)
@@ -299,9 +300,9 @@ func TestLoopbackSubnetLifetimeBoundToAddr(t *testing.T) {
},
})
- r, err := s.FindRoute(nicID, otherAddr, remoteIPv4Addr, ipv4.ProtocolNumber, false /* multicastLoop */)
+ r, err := s.FindRoute(nicID, otherAddr, utils.RemoteIPv4Addr, ipv4.ProtocolNumber, false /* multicastLoop */)
if err != nil {
- t.Fatalf("s.FindRoute(%d, %s, %s, %d, false): %s", nicID, otherAddr, remoteIPv4Addr, ipv4.ProtocolNumber, err)
+ t.Fatalf("s.FindRoute(%d, %s, %s, %d, false): %s", nicID, otherAddr, utils.RemoteIPv4Addr, ipv4.ProtocolNumber, err)
}
defer r.Release()
@@ -344,7 +345,7 @@ func TestLoopbackAcceptAllInSubnetTCP(t *testing.T) {
ipv4ProtocolAddress := tcpip.ProtocolAddress{
Protocol: header.IPv4ProtocolNumber,
- AddressWithPrefix: ipv4Addr,
+ AddressWithPrefix: utils.Ipv4Addr,
}
ipv4ProtocolAddress.AddressWithPrefix.PrefixLen = 8
ipv4Bytes := []byte(ipv4ProtocolAddress.AddressWithPrefix.Address)
@@ -353,9 +354,9 @@ func TestLoopbackAcceptAllInSubnetTCP(t *testing.T) {
ipv6ProtocolAddress := tcpip.ProtocolAddress{
Protocol: header.IPv6ProtocolNumber,
- AddressWithPrefix: ipv6Addr,
+ AddressWithPrefix: utils.Ipv6Addr,
}
- ipv6Bytes := []byte(ipv6Addr.Address)
+ ipv6Bytes := []byte(utils.Ipv6Addr.Address)
ipv6Bytes[len(ipv6Bytes)-1]++
otherIPv6Address := tcpip.Address(ipv6Bytes)
@@ -381,7 +382,7 @@ func TestLoopbackAcceptAllInSubnetTCP(t *testing.T) {
{
name: "IPv4 bind to wildcard send to other address",
addAddress: ipv4ProtocolAddress,
- dstAddr: remoteIPv4Addr,
+ dstAddr: utils.RemoteIPv4Addr,
expectAccept: false,
},
{
@@ -409,8 +410,8 @@ func TestLoopbackAcceptAllInSubnetTCP(t *testing.T) {
{
name: "IPv6 bind and send to assigned address",
addAddress: ipv6ProtocolAddress,
- bindAddr: ipv6Addr.Address,
- dstAddr: ipv6Addr.Address,
+ bindAddr: utils.Ipv6Addr.Address,
+ dstAddr: utils.Ipv6Addr.Address,
expectAccept: true,
},
{
diff --git a/pkg/tcpip/tests/integration/multicast_broadcast_test.go b/pkg/tcpip/tests/integration/multicast_broadcast_test.go
index d685fdd36..e4439ba79 100644
--- a/pkg/tcpip/tests/integration/multicast_broadcast_test.go
+++ b/pkg/tcpip/tests/integration/multicast_broadcast_test.go
@@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package multicast_broadcast_test
import (
"bytes"
- "net"
"testing"
"github.com/google/go-cmp/cmp"
@@ -29,6 +28,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
@@ -37,29 +37,6 @@ import (
const (
defaultMTU = 1280
ttl = 255
-
- remotePort = 5555
- localPort = 80
-)
-
-var (
- ipv4Addr = tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("192.168.1.58").To4()),
- PrefixLen: 24,
- }
- ipv4Subnet = ipv4Addr.Subnet()
- ipv4SubnetBcast = ipv4Subnet.Broadcast()
-
- ipv6Addr = tcpip.AddressWithPrefix{
- Address: tcpip.Address(net.ParseIP("200a::1").To16()),
- PrefixLen: 64,
- }
- ipv6Subnet = ipv6Addr.Subnet()
- ipv6SubnetBcast = ipv6Subnet.Broadcast()
-
- // Remote addrs.
- remoteIPv4Addr = tcpip.Address(net.ParseIP("10.0.0.1").To4())
- remoteIPv6Addr = tcpip.Address(net.ParseIP("200b::1").To16())
)
// TestPingMulticastBroadcast tests that responding to an Echo Request destined
@@ -81,7 +58,7 @@ func TestPingMulticastBroadcast(t *testing.T) {
TotalLength: uint16(totalLen),
Protocol: uint8(icmp.ProtocolNumber4),
TTL: ttl,
- SrcAddr: remoteIPv4Addr,
+ SrcAddr: utils.RemoteIPv4Addr,
DstAddr: dst,
})
ip.SetChecksum(^ip.CalculateChecksum())
@@ -98,13 +75,13 @@ func TestPingMulticastBroadcast(t *testing.T) {
pkt.SetType(header.ICMPv6EchoRequest)
pkt.SetCode(0)
pkt.SetChecksum(0)
- pkt.SetChecksum(header.ICMPv6Checksum(pkt, remoteIPv6Addr, dst, buffer.VectorisedView{}))
+ pkt.SetChecksum(header.ICMPv6Checksum(pkt, utils.RemoteIPv6Addr, dst, buffer.VectorisedView{}))
ip := header.IPv6(hdr.Prepend(header.IPv6MinimumSize))
ip.Encode(&header.IPv6Fields{
PayloadLength: header.ICMPv6MinimumSize,
TransportProtocol: icmp.ProtocolNumber6,
HopLimit: ttl,
- SrcAddr: remoteIPv6Addr,
+ SrcAddr: utils.RemoteIPv6Addr,
DstAddr: dst,
})
@@ -119,11 +96,11 @@ func TestPingMulticastBroadcast(t *testing.T) {
}{
{
name: "IPv4 unicast",
- dstAddr: ipv4Addr.Address,
+ dstAddr: utils.Ipv4Addr.Address,
},
{
name: "IPv4 directed broadcast",
- dstAddr: ipv4SubnetBcast,
+ dstAddr: utils.Ipv4SubnetBcast,
},
{
name: "IPv4 broadcast",
@@ -135,7 +112,7 @@ func TestPingMulticastBroadcast(t *testing.T) {
},
{
name: "IPv6 unicast",
- dstAddr: ipv6Addr.Address,
+ dstAddr: utils.Ipv6Addr.Address,
},
{
name: "IPv6 all-nodes multicast",
@@ -154,11 +131,11 @@ func TestPingMulticastBroadcast(t *testing.T) {
if err := s.CreateNIC(nicID, e); err != nil {
t.Fatalf("CreateNIC(%d, _): %s", nicID, err)
}
- ipv4ProtoAddr := tcpip.ProtocolAddress{Protocol: header.IPv4ProtocolNumber, AddressWithPrefix: ipv4Addr}
+ ipv4ProtoAddr := tcpip.ProtocolAddress{Protocol: header.IPv4ProtocolNumber, AddressWithPrefix: utils.Ipv4Addr}
if err := s.AddProtocolAddress(nicID, ipv4ProtoAddr); err != nil {
t.Fatalf("AddProtocolAddress(%d, %#v): %s", nicID, ipv4ProtoAddr, err)
}
- ipv6ProtoAddr := tcpip.ProtocolAddress{Protocol: header.IPv6ProtocolNumber, AddressWithPrefix: ipv6Addr}
+ ipv6ProtoAddr := tcpip.ProtocolAddress{Protocol: header.IPv6ProtocolNumber, AddressWithPrefix: utils.Ipv6Addr}
if err := s.AddProtocolAddress(nicID, ipv6ProtoAddr); err != nil {
t.Fatalf("AddProtocolAddress(%d, %#v): %s", nicID, ipv6ProtoAddr, err)
}
@@ -183,13 +160,13 @@ func TestPingMulticastBroadcast(t *testing.T) {
switch l := len(test.dstAddr); l {
case header.IPv4AddressSize:
rxICMP = rxIPv4ICMP
- expectedSrc = ipv4Addr.Address
- expectedDst = remoteIPv4Addr
+ expectedSrc = utils.Ipv4Addr.Address
+ expectedDst = utils.RemoteIPv4Addr
protoNum = header.IPv4ProtocolNumber
case header.IPv6AddressSize:
rxICMP = rxIPv6ICMP
- expectedSrc = ipv6Addr.Address
- expectedDst = remoteIPv6Addr
+ expectedSrc = utils.Ipv6Addr.Address
+ expectedDst = utils.RemoteIPv6Addr
protoNum = header.IPv6ProtocolNumber
default:
t.Fatalf("got unexpected address length = %d bytes", l)
@@ -226,8 +203,8 @@ func rxIPv4UDP(e *channel.Endpoint, src, dst tcpip.Address, data []byte) {
hdr := buffer.NewPrependable(totalLen)
u := header.UDP(hdr.Prepend(payloadLen))
u.Encode(&header.UDPFields{
- SrcPort: remotePort,
- DstPort: localPort,
+ SrcPort: utils.RemotePort,
+ DstPort: utils.LocalPort,
Length: uint16(payloadLen),
})
copy(u.Payload(), data)
@@ -255,8 +232,8 @@ func rxIPv6UDP(e *channel.Endpoint, src, dst tcpip.Address, data []byte) {
hdr := buffer.NewPrependable(header.IPv6MinimumSize + payloadLen)
u := header.UDP(hdr.Prepend(payloadLen))
u.Encode(&header.UDPFields{
- SrcPort: remotePort,
- DstPort: localPort,
+ SrcPort: utils.RemotePort,
+ DstPort: utils.LocalPort,
Length: uint16(payloadLen),
})
copy(u.Payload(), data)
@@ -298,68 +275,68 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
{
name: "IPv4 unicast binding to unicast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- bindAddr: ipv4Addr.Address,
- dstAddr: ipv4Addr.Address,
+ bindAddr: utils.Ipv4Addr.Address,
+ dstAddr: utils.Ipv4Addr.Address,
expectRx: true,
},
{
name: "IPv4 unicast binding to broadcast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
bindAddr: header.IPv4Broadcast,
- dstAddr: ipv4Addr.Address,
+ dstAddr: utils.Ipv4Addr.Address,
expectRx: false,
},
{
name: "IPv4 unicast binding to wildcard",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- dstAddr: ipv4Addr.Address,
+ dstAddr: utils.Ipv4Addr.Address,
expectRx: true,
},
{
name: "IPv4 directed broadcast binding to subnet broadcast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- bindAddr: ipv4SubnetBcast,
- dstAddr: ipv4SubnetBcast,
+ bindAddr: utils.Ipv4SubnetBcast,
+ dstAddr: utils.Ipv4SubnetBcast,
expectRx: true,
},
{
name: "IPv4 directed broadcast binding to broadcast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
bindAddr: header.IPv4Broadcast,
- dstAddr: ipv4SubnetBcast,
+ dstAddr: utils.Ipv4SubnetBcast,
expectRx: false,
},
{
name: "IPv4 directed broadcast binding to wildcard",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- dstAddr: ipv4SubnetBcast,
+ dstAddr: utils.Ipv4SubnetBcast,
expectRx: true,
},
{
name: "IPv4 broadcast binding to broadcast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
bindAddr: header.IPv4Broadcast,
dstAddr: header.IPv4Broadcast,
@@ -368,28 +345,28 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
{
name: "IPv4 broadcast binding to subnet broadcast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- bindAddr: ipv4SubnetBcast,
+ bindAddr: utils.Ipv4SubnetBcast,
dstAddr: header.IPv4Broadcast,
expectRx: false,
},
{
name: "IPv4 broadcast binding to wildcard",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- dstAddr: ipv4SubnetBcast,
+ dstAddr: utils.Ipv4SubnetBcast,
expectRx: true,
},
{
name: "IPv4 all-systems multicast binding to all-systems multicast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
bindAddr: header.IPv4AllSystems,
dstAddr: header.IPv4AllSystems,
@@ -398,8 +375,8 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
{
name: "IPv4 all-systems multicast binding to wildcard",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
dstAddr: header.IPv4AllSystems,
expectRx: true,
@@ -407,10 +384,10 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
{
name: "IPv4 all-systems multicast binding to unicast",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
- bindAddr: ipv4Addr.Address,
+ bindAddr: utils.Ipv4Addr.Address,
dstAddr: header.IPv4AllSystems,
expectRx: false,
},
@@ -418,19 +395,19 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
// IPv6 has no notion of a broadcast.
{
name: "IPv6 unicast binding to wildcard",
- dstAddr: ipv6Addr.Address,
+ dstAddr: utils.Ipv6Addr.Address,
proto: header.IPv6ProtocolNumber,
- remoteAddr: remoteIPv6Addr,
- localAddr: ipv6Addr,
+ remoteAddr: utils.RemoteIPv6Addr,
+ localAddr: utils.Ipv6Addr,
rxUDP: rxIPv6UDP,
expectRx: true,
},
{
name: "IPv6 broadcast-like address binding to wildcard",
- dstAddr: ipv6SubnetBcast,
+ dstAddr: utils.Ipv6SubnetBcast,
proto: header.IPv6ProtocolNumber,
- remoteAddr: remoteIPv6Addr,
- localAddr: ipv6Addr,
+ remoteAddr: utils.RemoteIPv6Addr,
+ localAddr: utils.Ipv6Addr,
rxUDP: rxIPv6UDP,
expectRx: false,
},
@@ -458,7 +435,7 @@ func TestIncomingMulticastAndBroadcast(t *testing.T) {
}
defer ep.Close()
- bindAddr := tcpip.FullAddress{Addr: test.bindAddr, Port: localPort}
+ bindAddr := tcpip.FullAddress{Addr: test.bindAddr, Port: utils.LocalPort}
if err := ep.Bind(bindAddr); err != nil {
t.Fatalf("ep.Bind(%#v): %s", bindAddr, err)
}
@@ -639,16 +616,16 @@ func TestUDPAddRemoveMembershipSocketOption(t *testing.T) {
name: "IPv4 unicast binding to unicast",
multicastAddr: "\xe0\x01\x02\x03",
proto: header.IPv4ProtocolNumber,
- remoteAddr: remoteIPv4Addr,
- localAddr: ipv4Addr,
+ remoteAddr: utils.RemoteIPv4Addr,
+ localAddr: utils.Ipv4Addr,
rxUDP: rxIPv4UDP,
},
{
name: "IPv6 broadcast-like address binding to wildcard",
multicastAddr: "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04",
proto: header.IPv6ProtocolNumber,
- remoteAddr: remoteIPv6Addr,
- localAddr: ipv6Addr,
+ remoteAddr: utils.RemoteIPv6Addr,
+ localAddr: utils.Ipv6Addr,
rxUDP: rxIPv6UDP,
},
}
@@ -719,7 +696,7 @@ func TestUDPAddRemoveMembershipSocketOption(t *testing.T) {
}
defer ep.Close()
- bindAddr := tcpip.FullAddress{Port: localPort}
+ bindAddr := tcpip.FullAddress{Port: utils.LocalPort}
if err := ep.Bind(bindAddr); err != nil {
t.Fatalf("ep.Bind(%#v): %s", bindAddr, err)
}
diff --git a/pkg/tcpip/tests/integration/route_test.go b/pkg/tcpip/tests/integration/route_test.go
index 9654c9527..4455f6dd7 100644
--- a/pkg/tcpip/tests/integration/route_test.go
+++ b/pkg/tcpip/tests/integration/route_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package integration_test
+package route_test
import (
"bytes"
@@ -28,6 +28,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
+ "gvisor.dev/gvisor/pkg/tcpip/tests/utils"
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
@@ -107,7 +108,7 @@ func TestLocalPing(t *testing.T) {
transProto: icmp.ProtocolNumber4,
netProto: ipv4.ProtocolNumber,
linkEndpoint: channelEP,
- localAddr: ipv4Addr.Address,
+ localAddr: utils.Ipv4Addr.Address,
icmpBuf: ipv4ICMPBuf,
checkLinkEndpoint: channelEPCheck,
},
@@ -116,7 +117,7 @@ func TestLocalPing(t *testing.T) {
transProto: icmp.ProtocolNumber6,
netProto: ipv6.ProtocolNumber,
linkEndpoint: channelEP,
- localAddr: ipv6Addr.Address,
+ localAddr: utils.Ipv6Addr.Address,
icmpBuf: ipv6ICMPBuf,
checkLinkEndpoint: channelEPCheck,
},
@@ -253,13 +254,13 @@ func TestLocalUDP(t *testing.T) {
}{
{
name: "IPv4",
- canBePrimaryAddr: ipv4Addr1,
- firstPrimaryAddr: ipv4Addr2,
+ canBePrimaryAddr: utils.Ipv4Addr1,
+ firstPrimaryAddr: utils.Ipv4Addr2,
},
{
name: "IPv6",
- canBePrimaryAddr: ipv6Addr1,
- firstPrimaryAddr: ipv6Addr2,
+ canBePrimaryAddr: utils.Ipv6Addr1,
+ firstPrimaryAddr: utils.Ipv6Addr2,
},
}