summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-01-31 12:25:21 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-31 12:27:21 -0800
commitb4f8a925283eaca32820e7977706768343bf04b8 (patch)
treea8280519f89737911f4185fff45dddc19402ce2c /pkg/tcpip
parent4ee8cf8734d24c7ba78700c21dff561207d4ed1a (diff)
Remove NICs before closing their link endpoints
...in IPv6 ICMP tests. A channel link endpoint's channel is closed when the link endpoint is closed. When the stack tries to send packets through a NIC with a closed channel endpoint, a panic will occur when attempting to write to a closed channel (https://golang.org/ref/spec#Close). To make sure the stack does not try to send packets through a NIC, we remove it. PiperOrigin-RevId: 354822085
Diffstat (limited to 'pkg/tcpip')
-rw-r--r--pkg/tcpip/network/ipv6/icmp_test.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go
index 4374d0198..60404c78b 100644
--- a/pkg/tcpip/network/ipv6/icmp_test.go
+++ b/pkg/tcpip/network/ipv6/icmp_test.go
@@ -492,6 +492,8 @@ func visitStats(v reflect.Value, f func(string, *tcpip.StatCounter)) {
}
type testContext struct {
+ t *testing.T
+
s0 *stack.Stack
s1 *stack.Stack
@@ -509,6 +511,8 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab
func newTestContext(t *testing.T) *testContext {
c := &testContext{
+ t: t,
+
s0: stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
@@ -562,10 +566,19 @@ func newTestContext(t *testing.T) *testContext {
}},
)
+ t.Cleanup(c.cleanup)
+
return c
}
func (c *testContext) cleanup() {
+ if err := c.s0.RemoveNIC(nicID); err != nil {
+ c.t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err)
+ }
+ if err := c.s1.RemoveNIC(nicID); err != nil {
+ c.t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err)
+ }
+
c.linkEP0.Close()
c.linkEP1.Close()
}
@@ -617,7 +630,6 @@ func routeICMPv6Packet(t *testing.T, args routeArgs, fn func(*testing.T, header.
func TestLinkResolution(t *testing.T) {
c := newTestContext(t)
- defer c.cleanup()
r, err := c.s0.FindRoute(nicID, lladdr0, lladdr1, ProtocolNumber, false /* multicastLoop */)
if err != nil {