|
| 1 | +// Copyright 2024 The gVisor Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package tcp |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "gvisor.dev/gvisor/pkg/tcpip" |
| 21 | + "gvisor.dev/gvisor/pkg/tcpip/faketime" |
| 22 | + "gvisor.dev/gvisor/pkg/tcpip/stack" |
| 23 | +) |
| 24 | + |
| 25 | +// TestResetConnectionLockedNilSndRcv verifies that resetConnectionLocked does |
| 26 | +// not panic when e.snd and e.rcv are nil, which occurs for endpoints in |
| 27 | +// handshake states (e.g. SynSent) that have not yet initialized their sender |
| 28 | +// and receiver. In this case, per Linux behavior, the RST is sent with a |
| 29 | +// sequence number of zero and a receive window of zero. |
| 30 | +func TestResetConnectionLockedNilSndRcv(t *testing.T) { |
| 31 | + fClock := faketime.NewManualClock() |
| 32 | + s := stack.New(stack.Options{ |
| 33 | + TransportProtocols: []stack.TransportProtocolFactory{NewProtocol}, |
| 34 | + Clock: fClock, |
| 35 | + }) |
| 36 | + |
| 37 | + ep := &Endpoint{ |
| 38 | + stack: s, |
| 39 | + snd: nil, |
| 40 | + rcv: nil, |
| 41 | + } |
| 42 | + ep.setEndpointState(StateSynSent) |
| 43 | + |
| 44 | + ep.mu.Lock() |
| 45 | + ep.resetConnectionLocked(&tcpip.ErrConnectionAborted{}) |
| 46 | + ep.mu.Unlock() |
| 47 | + |
| 48 | + if got, want := ep.EndpointState(), StateError; got != want { |
| 49 | + t.Errorf("endpoint state after resetConnectionLocked = %v, want %v", got, want) |
| 50 | + } |
| 51 | +} |
0 commit comments