Commit Graph

56 Commits

Author SHA1 Message Date
Julian Elischer 3b353ff0ef Additions to ICMP and IPv4 parsers
Teach ICMP.Parser/ToBytes to handle some non echo ICMP packets.
Teach IPv4.Parser that fragments only have a payload, not an upper layer.
Fix IPv4 and IPv6 reassembly tests to handle the change.

Fixes #4758

PiperOrigin-RevId: 341549665
2020-11-09 21:59:53 -08:00
Arthur Sfez 337c4b9a19 Add support for bare IPv4 in packetimpact tests
PiperOrigin-RevId: 339699771
2020-10-29 10:44:59 -07:00
Arthur Sfez 906f912b7c Add the payload directly to the ICMPv4 type
This makes handling inbound fragmented packets easier, because a fragmented
packet might not have an actual ICMP header but only a payload. After this
change, the ICMPv4 is the last layer you can get because the payload is
embedded in it.

Note that this makes it consistent with the ICMPv6 implementation.

While I'm here, I've also added the Ident and Sequence fields on the ICMPv4
type. Defaults are still zero.

PiperOrigin-RevId: 339577094
2020-10-28 18:18:18 -07:00
Ting-Yu Wang 8fa18e8ecb Bump honnef.co/go/tools to v0.0.1-2020.1.6
PiperOrigin-RevId: 339476515
2020-10-28 09:41:11 -07:00
Adin Scannell a55bd73d48 Add staticcheck and staticstyle analyzers.
This change also adds support to go_stateify for detecting an appropriate
receiver name, avoiding a large number of false positives.

PiperOrigin-RevId: 335994587
2020-10-07 18:29:05 -07:00
Zeling Feng 64aae6bbd6 Cleanup device name confusion in packetimpact testbench
There are two device names on the test net.
- The sniffer/injector device which is always a linux device. Only the
testbench library is interested in this device.
- The device which is on the DUT. It happens to be the same device as
the former if DUT is linux. An individual test might be interested in
this device if the test cares about the device name.

PiperOrigin-RevId: 332112968
2020-09-16 16:26:10 -07:00
Nayana Bidari b6d165fe98 Automated rollback of changelist 329526153
PiperOrigin-RevId: 332097286
2020-09-16 15:06:55 -07:00
Mithun Iyer 40faeaa180 Fix handling of unacceptable ACKs during close.
On receiving an ACK with unacceptable ACK number, in a closing state,
TCP, needs to reply back with an ACK with correct seq and ack numbers and
remain in same state. This change is as per RFC793 page 37, but with a
difference that it does not apply to ESTABLISHED state, just as in Linux.
Also add more tests to check for OTW sequence number and unacceptable
ack numbers in these states.

Fixes #3785

PiperOrigin-RevId: 329616283
2020-09-01 17:45:04 -07:00
Nayana Bidari 0eae08bc9e Automated rollback of changelist 328350576
PiperOrigin-RevId: 329526153
2020-09-01 09:54:55 -07:00
Nayana Bidari b26f7503b5 Support SO_LINGER socket option.
When SO_LINGER option is enabled, the close will not return until all the
queued messages are sent and acknowledged for the socket or linger timeout is
reached. If the option is not set, close will return immediately. This option
is mainly supported for connection oriented protocols such as TCP.

PiperOrigin-RevId: 328350576
2020-08-25 10:04:07 -07:00
Julian Elischer 190634e0fc Give the ICMP Code its own type
This is  a preparatory commit for a larger commit working on
ICMP generation in error cases.
This is removal of technical debt and cleanup in the gvisor code
as part of gvisor issue 2211.

Updates #2211.

PiperOrigin-RevId: 326615389
2020-08-14 02:07:36 -07:00
Adin Scannell c5f5806fe6 Enable "make packetimpact-tests" to work.
This required minor fixes to the bazel wrapper. The "dut_platform" is
also changed to "native" to line-up with the system call tests and
remove the hard-coded "linux" and "netstack" strings.
2020-08-04 20:49:00 -07:00
Jay Zhuang cf7141fb43 Ask for *testing.T instead of storing it
Storing *testing.T on test helper structs is problematic when
subtests are used, because it is possible for nested tests to call
Fatal on parent test, which incorrect terminates the parent test.

For example

  func TestOuter(t *testing.T) {
    dut := NewDUT(t)

    t.Run("first test", func(t *testing.T) {
      dut.FallibleCall()
    })

    t.Run("second test", func(t *testing.T) {
      dut.FallibleCall()
    }
  }

In the example above, assuming `FallibleCall` calls `t.Fatal` on the
`t` it holds, if `dut.FallibleCall` fails in "first test", it will
call `Fatal` on the parent `t`, quitting `TestOuter`. This is not a
behavior we want.

PiperOrigin-RevId: 323350241
2020-07-27 06:39:06 -07:00
Kevin Krakauer fb8be7e627 make connect(2) fail when dest is unreachable
Previously, ICMP destination unreachable datagrams were ignored by TCP
endpoints. This caused connect to hang when an intermediate router
couldn't find a route to the host.

This manifested as a Kokoro error when Docker IPv6 was enabled. The Ruby
image test would try to install the sinatra gem and hang indefinitely
attempting to use an IPv6 address.

Fixes #3079.
2020-07-22 16:51:42 -07:00
Zeling Feng 221e1da947 Test IPv6 fragment reassembly
A packetimpact test for: "A node must be able to accept a fragmented packet
that, after reassembly, is as large as 1500 octets."

PiperOrigin-RevId: 321210729
2020-07-14 12:29:34 -07:00
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
gVisor bot c81ac8ec3b Merge pull request #2672 from amscanne:shim-integrated
PiperOrigin-RevId: 321053634
2020-07-13 16:10:58 -07:00
Jay Zhuang 76b392bc26 Create packetimpact test for UDP broadcast
PiperOrigin-RevId: 321000340
2020-07-13 11:49:06 -07:00
Zeling Feng e6a90baef1 Support IPv6 extension headers in packetimpact tests.
- IPv6 HopByHop Options Extension Header
- IPv6 Destination Options Extension Header

PiperOrigin-RevId: 318551425
2020-06-26 15:08:51 -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
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
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 92bafd7929 Automated rollback of changelist 311424257
PiperOrigin-RevId: 313300554
2020-05-26 17:40:57 -07:00
Zeling Feng 99a18ec8b4 Support TCP options for packetimpact
PiperOrigin-RevId: 312119730
2020-05-18 11:31:38 -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
Bhasker Hariharan e4d2d21f6b Add UDP send/recv packetimpact tests.
Fixes #2654

PiperOrigin-RevId: 310642216
2020-05-08 15:40:27 -07:00
gVisor bot 4631de620a Internal change.
PiperOrigin-RevId: 310213705
2020-05-06 13:13:48 -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
Eyal Soha 79542417fe Fix Layer merge and add unit tests
mergo was improperly merging nil and empty strings

PiperOrigin-RevId: 308170862
2020-04-23 18:24:31 -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 6d23673e10 Add comments about deepcopy in Layer.incoming()
PiperOrigin-RevId: 307812340
2020-04-22 07:28:39 -07:00
gVisor bot 0e013d8b00 Don't ignore override if it is longer than layerStates
PiperOrigin-RevId: 307708653
2020-04-21 16:55:28 -07:00
Eyal Soha 75e864fc75 Use multierr in packetimpact Connection.Close()
PiperOrigin-RevId: 306930652
2020-04-16 15:15:50 -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 3d3bf9603d Use hex.Dump for Layer.String() of byte slices.
PiperOrigin-RevId: 306726587
2020-04-15 14:59:15 -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
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 ef0b5584e5 Refactor parser to use a for loop instead of recursion.
This makes the code shorter and less repetitive.

TESTED:
  All unit tests still pass.
PiperOrigin-RevId: 306161475
2020-04-12 18:33:23 -07:00
Eyal Soha 2020349468 Improve error messages when parsing headers.
Tested:
  Looked at output of failing tests.
PiperOrigin-RevId: 306031407
2020-04-11 06:46:27 -07:00
gVisor bot 21e438d257 Dereference pointers in Layer's Stringer impl
Dereference any fields which are pointers before string formatting so that the
value pointed to ends up in the string representation.

Tested:
  Added TestLayerStringFormat to
  //third_party/gvisor/test/packetimpact/testbench:testbench_test
PiperOrigin-RevId: 305627821
2020-04-08 23:30:09 -07:00
Eyal Soha 71c7e24e5c Return all packets when Expect fails.
PiperOrigin-RevId: 305466309
2020-04-08 06:42:58 -07:00
gVisor bot dbcc59af0b Test TCP sender behavior against window shrinking
RFC 1122 Section 3.7: A sending TCP MUST be robust against window shrinking,
which may cause the "useable window" to become negative.

PiperOrigin-RevId: 305377072
2020-04-07 17:49:21 -07:00