Commit Graph

54 Commits

Author SHA1 Message Date
Jay Zhuang 822fc99ecd Add support for UDP IPv6
Also ironed out all the bugs found on the IPv6 code path that affects socket
bind, send and receive.

PiperOrigin-RevId: 321202653
2020-07-14 11:49:51 -07:00
Jay Zhuang 76b392bc26 Create packetimpact test for UDP broadcast
PiperOrigin-RevId: 321000340
2020-07-13 11:49:06 -07:00
Tony Gong 76c7bc51b7 Set IPv4 ID on all non-atomic datagrams
RFC 6864 imposes various restrictions on the uniqueness of the IPv4
Identification field for non-atomic datagrams, defined as an IP datagram that
either can be fragmented (DF=0) or is already a fragment (MF=1 or positive
fragment offset). In order to be compliant, the ID field is assigned for all
non-atomic datagrams.

Add a TCP unit test that induces retransmissions and checks that the IPv4
ID field is unique every time. Add basic handling of the IP_MTU_DISCOVER
socket option so that the option can be used to disable PMTU discovery,
effectively setting DF=0. Attempting to set the sockopt to anything other
than disabled will fail because PMTU discovery is currently not implemented,
and the default behavior matches that of disabled.

PiperOrigin-RevId: 320081842
2020-07-07 16:14:49 -07:00
Tamir Duberstein 5ac34386a7 Improve failure message
Currently this test produces an error resembling

  tcp_zero_window_probe_retransmit_test.go:92: zero probe came sooner interval 3200179405 probe 4

which is approximately useless.

PiperOrigin-RevId: 319572263
2020-07-03 23:20:13 -07:00
Mithun Iyer 31b27adf9b TCP receive should block when in SYN-SENT state.
The application can choose to initiate a non-blocking connect and
later block on a read, when the endpoint is still in SYN-SENT state.

PiperOrigin-RevId: 319311016
2020-07-01 15:47:50 -07:00
Bhasker Hariharan c9446f0534 Fix two bugs in TCP sender.
a) When GSO is in use we should not cap the segment to maxPayloadSize in
   sender.maybeSendSegment as the GSO logic will cap the segment to the correct
   size. Without this the host GSO is not used as we end up breaking up large
   segments into small MSS sized segments before writing the packets to the
   host.

b) The check to not split a segment due to it not fitting in the receiver window
   when there are pending segments is incorrect as segments in writeList can be
   really large as we just take the write call's buffer size and create a single
   large segment. So a write of say 128KB will just be 1 segment in the
   writeList.

   The linux code checks if 1 MSS sized segments fits in the receiver's window
   and if not then does not split the current segment. gVisor's check was
   incorrect that it was checking if the whole segment which could be >>> 1 MSS
   would fit in the receiver's window. This was causing us to prematurely stop
   sending and falling back to retransmit timer/probe from the other end to send
   data.

This was seen when running HTTPD benchmarks where @ HEAD when sending large
files the benchmark was taking forever to run.

The tcp_splitseg_mss_test.go is being deleted as the test as written doesn't
test what is intended correctly. This is because GSO is enabled by default and
the reason the MSS+1 sized segment is sent is because GSO is in use. A proper
test will require disabling GSO on linux and netstack which is going to take a
bit of work in packetimpact to do it correctly.

Separately a new test probably should be written that verifies that a segment >
availableWindow is not split if the availableWindow is < 1 MSS.

Fixes #3107

PiperOrigin-RevId: 319172089
2020-06-30 23:56:34 -07:00
Zeling Feng aed7183976 Packetimpact test for IPv6 unknown options action
The Option Type identifiers are internally encoded such that their
highest-order two bits specify the action that must be taken if the
processing IPv6 node does not recognize the Option Type:

  00 - skip over this option and continue processing the header.
  01 - discard the packet.
  10 - discard the packet and, regardless of whether or not the
       packet's Destination Address was a multicast address, send an
       ICMP Parameter Problem, Code 2, message to the packet's
       Source Address, pointing to the unrecognized Option Type.
  11 - discard the packet and, only if the packet's Destination
       Address was not a multicast address, send an ICMP Parameter
       Problem, Code 2, message to the packet's Source Address,
       pointing to the unrecognized Option Type.

PiperOrigin-RevId: 318566613
2020-06-26 16:43:53 -07:00
Mithun Iyer 67f261a87d TCP to honor updated window size during handshake.
In passive open cases, we transition to Established state after
initializing endpoint's sender and receiver. With this we lose out
on any updates coming from the ACK that completes the handshake.
This change ensures that we uniformly transition to Established in all
cases and does minor cleanups.

Fixes #2938

PiperOrigin-RevId: 316567014
2020-06-15 16:19:53 -07:00
Tony Gong 82313667ea Make GenerateRandomPayload available to all tests
Moved the function for generating a payload of random byets of a specified
length into the testbench package so that it's availbale for all tests to use.

Added a test case to the IPv4 ID uniqueness test which uses a payload length
of 512 bytes. This test case passes for gVisor currently, whereas the test case
with a small payload of 11 bytes fails because gVisor only assigns the ID field
if the IP payload is sufficiently large.

PiperOrigin-RevId: 316185097
2020-06-12 15:07:17 -07:00
Mithun Iyer 61d6c059ac Replace use of %v in packetimpact tests
PiperOrigin-RevId: 316027588
2020-06-11 19:46:49 -07:00
Ian Gudger dc4e0157ef Add test for reordering.
Tests the effect of reordering on retransmission and window size.

Test covers the expected behavior of both Linux and netstack, however, netstack
does not behave as expected. Further, the current expected behavior of netstack
is not ideal and should be adjusted in the future.

PiperOrigin-RevId: 316015184
2020-06-11 18:04:43 -07:00
gVisor bot 44575bf726 Refactor packetimpact Connection types
Reorganize the Connection types such that the defined types no longer expose
the lower-level functions SendFrame and CreateFrame. These methods are still
exported on the underlying Connection type, and thus can be accessed via a
type-cast. In future, defined types should have one or more type-safe versions
of the send() method on Connection, e.g. UDPIPv4 has Send() which allows the UDP
header to be overridden and SendIP() which allows both the IPv4 and UDP headers
to be modified.

testbench.Connection gets a SendFrameStateless method which sends frames
without updating the state of any of the layers. This should be used when
sending out-of-band control messages such as ICMP messages, as using the
normal Send method can result in errors when attempting to update the TCP
state using an ICMP packet.

Also remove the localAddr field of testbench.Connection and instead compute
it on the fly as needed for UDPIPv4 and TCPIPv4.

PiperOrigin-RevId: 315969714
2020-06-11 13:48:30 -07:00
Mithun Iyer f766366091 Handle TCP segment split cases as per MSS.
- Always split segments larger than MSS.
  Currently, we base the segment split decision as a function of the
  send congestion window and MSS, which could be greater than the MSS
  advertised by remote.
- While splitting segments, ensure the PSH flag is reset when there
  are segments that are queued to be sent.
- With TCP_CORK, hold up segments up until MSS. Fix a bug in computing
  available send space before attempting to coalesce segments.

Fixes #2832

PiperOrigin-RevId: 314802928
2020-06-05 11:28:24 -07:00
Mithun Iyer 162848e129 Avoid TCP segment split when out of sender window.
If the entire segment cannot be accommodated in the receiver advertised
window and if there are still unacknowledged pending segments, skip
splitting the segment. The segment transmit would get retried by the
retransmit handler.

PiperOrigin-RevId: 314538523
2020-06-03 08:49:49 -07:00
Zeling Feng a9b47390c8 Test TCP should queue RECEIVE request in SYN-SENT
PiperOrigin-RevId: 313878910
2020-05-29 17:24:20 -07:00
Mithun Iyer 089c88f2e8 Move TCP to CLOSED from SYN-RCVD on RST.
RST handling is broken when the TCP state transitions
from SYN-SENT to SYN-RCVD in case of simultaneous open.
An incoming RST should trigger cleanup of the endpoint.
RFC793, section 3.9, page 70.

Fixes #2814

PiperOrigin-RevId: 313828777
2020-05-29 12:33:28 -07:00
gVisor bot 0baba92ad9 Internal change.
PiperOrigin-RevId: 313821986
2020-05-29 11:52:22 -07:00
gVisor bot 92bafd7929 Automated rollback of changelist 311424257
PiperOrigin-RevId: 313300554
2020-05-26 17:40:57 -07:00
Zeling Feng 5f3eeb4728 Test that we have PAWS mechanism
If there is a Timestamps option in the arriving segment and SEG.TSval
< TS.Recent and if TS.Recent is valid, then treat the arriving segment
as not acceptable: Send an acknowledgement in reply as specified in
RFC-793 page 69 and drop the segment.

https://tools.ietf.org/html/rfc1323#page-19

PiperOrigin-RevId: 312590678
2020-05-20 17:53:35 -07:00
gVisor bot a338eed1d8 Internal change.
PiperOrigin-RevId: 312559963
2020-05-20 14:57:59 -07:00
gVisor bot 326abf5e36 Internal change.
PiperOrigin-RevId: 311645222
2020-05-14 18:17:33 -07:00
Mithun Iyer f1ad2d54ab Fix TCP segment retransmit timeout handling.
As per RFC 1122 and Linux retransmit timeout handling:
- The segment retransmit timeout needs to exponentially increase and
  cap at a predefined value.
- TCP connection needs to timeout after a predefined number of
  segment retransmissions.
- TCP connection should not timeout when the retranmission timeout
  exceeds MaxRTO, predefined upper bound.

Fixes #2673

PiperOrigin-RevId: 311463961
2020-05-13 21:26:54 -07:00
Bhasker Hariharan 8605c97136 Automated rollback of changelist 311285868
PiperOrigin-RevId: 311424257
2020-05-13 16:13:37 -07:00
Ian Gudger e4058c0355 Replace test_runner.sh bash script with Go.
PiperOrigin-RevId: 311285868
2020-05-13 01:22:42 -07:00
gVisor bot 633e1b89bb Internal change.
PiperOrigin-RevId: 311011004
2020-05-11 15:54:08 -07:00
gVisor bot c5ab21b048 Internal change.
PiperOrigin-RevId: 310949277
2020-05-11 11:04:31 -07:00
Bhasker Hariharan e4d2d21f6b Add UDP send/recv packetimpact tests.
Fixes #2654

PiperOrigin-RevId: 310642216
2020-05-08 15:40:27 -07:00
Zeling Feng 5d7d5ed7d6 Send ACK to OTW SEQs/unacc ACKs in CLOSE_WAIT
This fixed the corresponding packetimpact test.

PiperOrigin-RevId: 310593470
2020-05-08 11:23:24 -07:00
gVisor bot 92cab8e2c3 Internal change.
PiperOrigin-RevId: 310409922
2020-05-07 12:10:02 -07:00
Mithun Iyer e590314fec Support TCP zero window probes.
As per RFC 1122 4.2.2.17, when the remote advertizes zero receive window,
the sender needs to probe for the window-size to become non-zero starting
from the next retransmission interval. The TCP connection needs to be kept
open as long as the remote is acknowledging the zero window probes.
We reuse the retransmission timers to support this.

Fixes #1644

PiperOrigin-RevId: 310021575
2020-05-05 14:30:52 -07:00
gVisor bot e7ed68d225 Internal change.
PiperOrigin-RevId: 309832671
2020-05-04 15:48:45 -07:00
gVisor bot e7b8a71156 Internal change.
PiperOrigin-RevId: 309467878
2020-05-01 13:52:21 -07:00
Zeling Feng 4875cda8d1 Make tcp_close_wait_ack_test more accurate
Previously the test used an out-dated window size which is advertised
during the handshake to generate testing packets, but the window size
has changed since the handshake; currently it is using the most recent
one which is advertised in DUT's ACK to our FIN packet to generate the
testing outside-the-window packets.

PiperOrigin-RevId: 309222921
2020-04-30 07:40:34 -07:00
gVisor bot 24abccbc1c Internal change.
PiperOrigin-RevId: 308940886
2020-04-28 18:50:44 -07:00
Eyal Soha dfff265fe4 Add ICMP6 param problem test
Tested:
  When run on Linux, a correct ICMPv6 response is received.  On netstack, no
  ICMPv6 response is received.
PiperOrigin-RevId: 308343113
2020-04-24 15:56:27 -07:00
Eyal Soha 3d860530a9 Better error message from ExpectFrame
Display the errors as diffs between the expected and wanted frame.

PiperOrigin-RevId: 308333271
2020-04-24 15:04:03 -07:00
Adin Scannell c60613475c Standardize all Docker images.
This change moves all Docker images to a standard location, and abstracts the
build process so that they can be maintained in an automated fashion. This also
allows the images to be architecture-independent.

All images will now be referred to by the test framework via the canonical
`gvisor.dev/images/<name>`, where `<name>` is a function of the path within the
source tree.

In a subsequent change, continuous integration will be added so that the images
will always be correct and available locally.

In the end, using `bazel` for Docker containers is simply not possible. Given
that we already have the need to use `make` with the base container (for
Docker), we extend this approach to get more flexibility.

This change also adds a self-documenting and powerful Makefile that is intended
to replace the collection of scripts in scripts. Canonical (self-documenting)
targets can be added here for targets that understand which images need to be
loaded and/or built.

PiperOrigin-RevId: 308322438
2020-04-24 14:11:42 -07:00
Eyal Soha cc5de905e6 Fix test output so that filenames have the correct path.
Tested:
  Intentionally introduce an error and then run:
  blaze test --test_output=streamed //third_party/gvisor/test/packetimpact/tests:tcp_outside_the_window_linux_test
PiperOrigin-RevId: 308114194
2020-04-23 13:18:59 -07:00
Adin Scannell 1481499fe2 Simplify Docker test infrastructure.
This change adds a layer of abstraction around the internal Docker APIs,
and eliminates all direct dependencies on Dockerfiles in the infrastructure.

A subsequent change will automated the generation of local images (with
efficient caching). Note that this change drops the use of bazel container
rules, as that experiment does not seem to be viable.

PiperOrigin-RevId: 308095430
2020-04-23 11:33:30 -07:00
Eyal Soha a2925a079f Run failing packetimpact test and expect failure.
This will make it easier to notice if a code change causes an existing test to
pass.

PiperOrigin-RevId: 308057978
2020-04-23 08:36:19 -07:00
Eyal Soha db2a60be67 Don't accept segments outside the receive window
Fixed to match RFC 793 page 69.

Fixes #1607

PiperOrigin-RevId: 307334892
2020-04-19 22:16:14 -07:00
Eyal Soha 08b2fd9bc2 Convert tcp_user_timeout test from packetdrill to packetimpact.
PiperOrigin-RevId: 307328289
2020-04-19 20:49:06 -07:00
gVisor bot eb7b1903e0 Test TCP behavior when receiving unacceptable segment in CLOSE_WAIT
TCP, in CLOSE-WAIT state, MUST return ACK with proper SEQ and ACK numbers after
recv a seg with OTW SEQ or unacc ACK number, and remain in same state. If the
connection is in a synchronized state, any unacceptable segment (out of window
sequence number or unacceptable acknowledgment number) must elicit only an empty
acknowledgment segment containing the current send-sequence number and an
acknowledgment indicating the next sequence number expected to be received, and
the connection remains in the same state.

PiperOrigin-RevId: 306897984
2020-04-16 12:22:17 -07:00
Eyal Soha 09c7e3f6e4 Add tests for segments outside the receive window.
The tests are based on RFC 793 page 69.

Updates #1607

PiperOrigin-RevId: 306768847
2020-04-15 19:37:00 -07:00
Eyal Soha 1bcc2bf17f Refactor connections.go to make it easier to add new connection types.
Rather than have a struct for the state of each type of connection, such as
TCP/IPv4, UDP/IPv4, TCP/IPv6, etc, have a state for each layer, such as UDP,
TCP, IPv4, IPv6.  Those states can be composed into connections.

Tested:
  Existing unit tests still pass/fail as expected.
PiperOrigin-RevId: 306703180
2020-04-15 13:01:11 -07:00
Mithun Iyer 9c918340e4 Reset pending connections on listener close
Attempt to redeliver TCP segments that are enqueued into a closing
TCP endpoint. This was being done for Established endpoints but not
for those that are listening or performing connection handshake.

Fixes #2417

PiperOrigin-RevId: 306598155
2020-04-15 01:11:44 -07:00
gVisor bot 81c44c4cd7 Test TCP should piggyback ACK in ESTAB state
TCP, in ESTABLISHED state, SHOULD piggyback acknowledgement with a segment being
transmitted (whenever possible) without incurring undue delay

PiperOrigin-RevId: 306474550
2020-04-14 11:05:38 -07:00
gVisor bot c230d12b5c Add Sniffer.Drain() draining socket receive buffer
Add Sniffer.Drain() which drains the socket's receive buffer by temporarily
setting the socket to non-blocking, and receiving in a loop until EINTR,
EWOULDBLOCK or EAGAIN. This method should be used when long periods of time
elapses without receiving on the socket, because uninteresting packets may have
piled up in the receive buffer, filling it up and causing packets critical to
test operation to be dropped.

PiperOrigin-RevId: 306380480
2020-04-13 23:05:08 -07:00
Eyal Soha 12b00c8156 Test that RST is sent after ABORT in ESTABLISHED TCP state.
PiperOrigin-RevId: 305879441
2020-04-10 08:22:09 -07:00
Eyal Soha 71c7e24e5c Return all packets when Expect fails.
PiperOrigin-RevId: 305466309
2020-04-08 06:42:58 -07:00