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
This commit is contained in:
Ghanan Gowripalan
2021-01-31 12:27:21 -08:00
committed by gVisor bot
parent 4ee8cf8734
commit b4f8a92528
+13 -1
View File
@@ -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 {