2020-04-10 15:20:56 +00:00
|
|
|
// Copyright 2020 The gVisor Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package tcp_noaccept_close_rst_test
|
|
|
|
|
|
|
|
import (
|
2020-05-11 22:52:42 +00:00
|
|
|
"flag"
|
2020-04-10 15:20:56 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/header"
|
2020-06-04 21:22:46 +00:00
|
|
|
"gvisor.dev/gvisor/test/packetimpact/testbench"
|
2020-04-10 15:20:56 +00:00
|
|
|
)
|
|
|
|
|
2020-05-11 22:52:42 +00:00
|
|
|
func init() {
|
2020-06-04 21:22:46 +00:00
|
|
|
testbench.RegisterFlags(flag.CommandLine)
|
2020-05-11 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 15:20:56 +00:00
|
|
|
func TestTcpNoAcceptCloseReset(t *testing.T) {
|
2020-06-04 21:22:46 +00:00
|
|
|
dut := testbench.NewDUT(t)
|
2020-04-10 15:20:56 +00:00
|
|
|
defer dut.TearDown()
|
|
|
|
listenFd, remotePort := dut.CreateListener(unix.SOCK_STREAM, unix.IPPROTO_TCP, 1)
|
2020-06-04 21:22:46 +00:00
|
|
|
conn := testbench.NewTCPIPv4(t, testbench.TCP{DstPort: &remotePort}, testbench.TCP{SrcPort: &remotePort})
|
|
|
|
conn.Connect()
|
2020-04-10 15:20:56 +00:00
|
|
|
defer conn.Close()
|
|
|
|
dut.Close(listenFd)
|
2020-06-04 21:22:46 +00:00
|
|
|
if _, err := conn.Expect(testbench.TCP{Flags: testbench.Uint8(header.TCPFlagRst | header.TCPFlagAck)}, 1*time.Second); err != nil {
|
2020-04-10 15:20:56 +00:00
|
|
|
t.Fatalf("expected a RST-ACK packet but got none: %s", err)
|
|
|
|
}
|
|
|
|
}
|