fix timewait not counting as closed state in listen open; add second part to test

This commit is contained in:
soypat
2025-10-24 18:26:59 -03:00
parent 92a245957b
commit 3fa2f32737
2 changed files with 25 additions and 9 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ type recvSpace struct {
// To open an active connection use [ControlBlock.Send] with a segment generated with [ClientSynSegment].
func (tcb *ControlBlock) Open(iss Value, wnd Size) (err error) {
switch {
case tcb._state != StateClosed && tcb._state != StateListen:
case tcb._state != StateClosed && tcb._state != StateTimeWait:
err = errNeedClosedTCBToOpen
case wnd > math.MaxUint16:
err = errWindowTooLarge
+24 -8
View File
@@ -17,7 +17,7 @@ const (
finack = tcp.FlagFIN | tcp.FlagACK
)
func TestABC(t *testing.T) {
func TestStackAsyncTCP(t *testing.T) {
const seed = 1234
const MTU = 1500
var mac = [6]byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}
@@ -47,6 +47,8 @@ func TestABC(t *testing.T) {
if err != nil {
t.Fatal(err)
}
client.SetGateway6(sv.HardwareAddress())
sv.SetGateway6(client.HardwareAddress())
const svPort = 80
var svconn tcp.Conn
@@ -58,11 +60,6 @@ func TestABC(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = sv.ListenTCP(&svconn, svPort)
if err != nil {
t.Fatal(err)
}
var clconn tcp.Conn
err = clconn.Configure(tcp.ConnConfig{
RxBuf: make([]byte, MTU),
@@ -72,9 +69,12 @@ func TestABC(t *testing.T) {
if err != nil {
t.Fatal(err)
}
client.SetGateway6(sv.HardwareAddress())
sv.SetGateway6(client.HardwareAddress())
// Attach server and client connections to stacks.
err = sv.ListenTCP(&svconn, svPort)
if err != nil {
t.Fatal(err)
}
err = client.DialTCP(&clconn, 1337, netip.AddrPortFrom(sv.Addr(), svPort))
if err != nil {
t.Fatal(err)
@@ -87,6 +87,22 @@ func TestABC(t *testing.T) {
tst.TestTCPHandshake(&client, &sv)
tst.TestTCPEstablishedSingleData(&client, &sv, &clconn, &svconn, sendData)
tst.TestTCPClose(&client, &sv, &clconn, &svconn)
// Switch handles around, now server will be client and they will be registered to
// a different stack.
svconn, clconn = clconn, svconn
err = sv.ListenTCP(&svconn, svPort)
if err != nil {
t.Fatal(err)
}
err = client.DialTCP(&clconn, 1234, netip.AddrPortFrom(sv.Addr(), svPort))
if err != nil {
t.Fatal(err)
}
sendData = []byte("olleh")
tst.TestTCPHandshake(&client, &sv)
tst.TestTCPEstablishedSingleData(&client, &sv, &clconn, &svconn, sendData)
tst.TestTCPClose(&client, &sv, &clconn, &svconn)
}
type tester struct {