Commit Graph

221 Commits (88256dbdcfc3b284f5533e5aa2969bf5061db22a)

Author SHA1 Message Date
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
Dario Nieuwenhuis 4e11070ff4 Async/await waker support. 2020-12-27 17:31:49 +01:00
Dario Nieuwenhuis 29cc59c89d Merge pull request #395 from crawford/clippy
Various cleanup suggested by cargo clippy
2020-12-26 23:53:25 +01:00
Alex Crawford c9f57150a8 Dereference match expressions to clean up patterns
These were flagged by `cargo clippy`:

    warning: you don't need to add `&` to all patterns
2020-12-26 10:32:51 -08:00
Alex Crawford c58711e11b Use newline variants of write macro
These were flagged by `cargo clippy`:

    warning: using `println!("")`
    warning: using `write!()` with a format string that ends in a single
             newline
2020-12-26 10:32:42 -08:00
Dario Nieuwenhuis a7d3f604a3 Don't use matches! macro, for Rust 1.36 support 2020-12-26 03:12:48 +01:00
Dario Nieuwenhuis 67e03b34b6 Fix seq_to_transmit incorrectly returning true when a FIN was enqueued.
If there's data queued that doesn't fit into the remote window, we can't
send the FIN either, so seq_to_transmit should return false.
2020-12-26 03:04:17 +01:00
Dario Nieuwenhuis f89d240c29 tcp: don't send data outside the remote window 2020-12-19 03:23:44 +00:00
Dario Nieuwenhuis 42dc04852b tcp: allow sending ACKs in FinWait2 state. 2020-12-19 01:13:59 +00:00
mustermeiszer 7b4997d5c7 Taking into account TCP and IP header
The MTU consists of TCP header, IP header and the payload.
In the former fix, this was not taken into account.
2020-10-23 15:13:18 +02:00
mustermeiszer d2aa3edbb7 Fixes unused MTU settings at TcpSocket dispatch
This commit fixes a small bug, where the TcpSocket computed the maximum
size per payload in a tx_buffer without taking into account the MTU
defined by the underlying network device.
2020-10-23 14:12:20 +02:00
Ryan Summers 1ae400acaa Return RST to unexpected ACK in SYN-SENT state.
Before this commit, the socket got stuck in an unusable state.
2020-08-17 05:44:58 +00:00
Dario Nieuwenhuis 4cfe8dafdb Do not send window updates in states that shouldn't do so.
Previously, the window update was sent anytime it changed. This is
not desirable for 2 reasons:

- It would send window updates in TimeWait or Closed states, which is incorrect.
- It would send window updates in states where we've already received the
  remote side's FIN, such as CloseWait. This is not necessarily incorrect, but
  is useless, since the remote side is not going to send us more data, therefore
  it's not interested in our window size anymore.
2020-06-25 04:06:29 +00:00
Lucas Zanela d5c44a37d5 Fix overly strict lifetime in TcpSocket. 2020-06-15 12:39:06 +00:00
Dario Nieuwenhuis d1e614516a Remove now-redundant `remote_last_ack` update. 2020-06-12 18:49:33 +00:00
Dario Nieuwenhuis 544b3789d0 Document `Error::Finished` in `recv()`. 2020-06-12 09:43:44 +00:00
Dario Nieuwenhuis a176641192 Return `Error::Finished` in `recv()` on graceful close.
This allows applications to distinguish whether the remote end has
gracefully closed the connection with a FIN (in which case it has
received all the data intact), or the connection has failed due to e.g. a
RST or a timeout (in which case the received data may be truncated).
2020-06-12 09:43:44 +00:00
Dario Nieuwenhuis 0d31e0a134 Always send updated ack number in `ack_reply()`.
Previously, `ack_reply()` was sending the ack number present in `remote_last_ack`,
which is only updated by `dispatch`. This means the ack replies could contain
a wrong, old ack number.

Most of the time this simply caused wasting an extra roundtrip until the socket state
settles down, but in extreme cases it could lead to an infinite loop of packets, such
as in https://github.com/smoltcp-rs/smoltcp/issues/338

Fixes #338
2020-06-11 23:24:24 +00:00
Dario Nieuwenhuis ffcaa83502 Accept data packets in FIN_WAIT_2 state.
Previously, data packets were never accepted in FIN_WAIT_2. The missing
match case was dropping them as "unexpected packet"s.
2020-06-11 20:19:44 +00:00
fdb-hiroshima 09f4a8f551 use provided ip for TcpSocket::connect instead of 0.0.0.0 2020-04-16 07:55:17 +00:00
Scott Mabin d7916c9a92 Add capacity methods to all sockets. 2019-11-05 23:07:12 +00:00
Richard Meadows 186bc05d77 Allow TCPSockets in a SocketSet without 'static storage lifetime
`TCPSocket` buffers are type `RingBuffer<'a, _>` whilst other
socket types have buffers with type `PacketBuffer<'a, 'b,
_>`.

There is an enum over socket types `pub enum Socket<'a, 'b: 'a>`,
 which is in turn used by `set::Item` and `SocketSet`. The lifetime
 `'b` is not required for `TcpSocket`, but the `Into<Socket>`
 implementation for `TCPSocket` specifies the `'static` lifetime for
 `'b`.

Therefore using `TCPSocket` in a `SocketSet` currently requires the
lifetime `'b` for other sockets to be `'static` which is unnecessarily
restrictive. This patch fixes this.

The lifetime signature of socket specifies `'b: 'a`, that is `'b`
outlives `'a`. Instead of `'static`, this is also satisfied by
`impl<'a> Into<Socket<'a, 'a>> for TcpSocket<'a>` as `'a` "outlives"
`'a` by definition.

The example
[here](https://gist.github.com/richardeoin/b562e79d0d499e00a8bf4944f00594d9)
fails to compile without this patch.

Closes: #304
Approved by: whitequark
2019-08-15 08:31:48 +08:00
whitequark 563434997c Fix spurious crash in commit bd3912e5. 2019-06-22 09:04:30 +00:00
whitequark be7750486f Bump log dependency to version 0.4. NFC.
This doesn't affect downstream code because log 0.3.9 is a facade
crate implemented in terms of log 0.4, and so log 0.3 and log 0.4
APIs can be used together.
2019-06-22 08:31:11 +00:00
whitequark f32522bef7 Fix docstrings for TcpSocket::{send,recv}_slice(). NFC. 2019-06-22 07:49:24 +00:00
whitequark 4e77a29c91 Clarify TcpSocket::recv_queue() semantics. NFC. 2019-06-22 07:03:15 +00:00
whitequark efdf3a2fb3 Fix typo in docstring. NFC. 2019-06-22 06:50:58 +00:00
jhwgh1968 e867832214 Minimal Implementation of TCP Selective Acknowledgement
Closes: #266
Approved by: whitequark
2019-01-01 13:51:02 +08:00
jhwgh1968 88016e675f Fully implement TCP Window Scaling
Closes: #253
Approved by: whitequark
2018-08-20 06:57:44 +08:00
jhwgh1968 1745df2110 Implement TCP Window Scaling, Phase 1 (Issue #106)
Closes: #232
Approved by: whitequark
2018-06-25 03:08:44 +08:00
Kai Lüke b23df24a2a Only trigger fast retransmit for data to send
This fixes entering a loop when both endpoints
are stuck in retransmission.

https://github.com/m-labs/smoltcp/issues/224

Closes: #233
Approved by: whitequark
2018-06-18 22:19:42 +08:00
Kai Lüke 272baab3ef Reset retrasmission delay after fast retrasmit
Closes: #233
Approved by: whitequark
2018-06-18 22:19:42 +08:00
Ole Martin Ruud 022cad8b11 Fix implementation of fast retransmit (TcpSocket)
Improve detection of duplicate ACKs by checking that the segment does
not contain data.

Move implementation from the 'reject unacceptable acknowledgements'
to later in the process function, because a duplicate ACK is not an
'unacceptable' acknowledgement but rather a condition to update state.

Implement more tests to verify the operation of the fast retransmit
implementation.

Related issue: #224

Closes: #225
Approved by: whitequark
2018-06-10 02:53:35 +08:00
Astro e5a3de210c Optimize RingBuffer::enqueue_many_with to an empty buffer.
This optimization makes sure that enqueueing to an empty ring buffer
would never wrap around, in turn ensuring that enqueueing to an empty
packet buffer would never use more than one metadata entry.
Right now, pushing buffer-sized packets into a packet buffer requires
at least two metadata entries, which is surprising and wasteful.
2018-05-24 22:00:00 +00:00
Ole Martin Ruud f501198a68 Implement fast retransmit for TcpSocket
Implement a simple way to discover and respond to three duplicate ACKs
from the reciver of the data. This leads to a fast retransmit of the
last unacknowledged seqment. This is feature is described in [RFC 5681].

Closes: #104

Closes: #214
Approved by: whitequark
2018-05-18 00:40:47 +08:00
Ole Martin Ruud 0c59e3f5f9 Implement new type for `poll_at`
Change return-type for `poll_at` for sockets to be a `PollAt` instead of
the former `Option<Instant>`.

Closes: #216
Approved by: whitequark
2018-05-17 06:17:47 +08:00
whitequark ca743cba24 Fix format strings using time to not include extraneous ms suffix. 2018-05-15 14:49:53 +00:00
Kai Lüke fada9d4e27 Update remote_last_win for all ACKs
Only ACKs generated by `dispatch` were updating
`remote_last_win` but not the ACKs generated by
`process`, failing to keep track of the last
announced receive window. This left
`window_to_update` to return false in `dispatch`
after the RX buffer was emptied, thus not announcing
that the receive window is not zero anymore.

The change updates `remote_last_win` for immediate
ACKs generated by `process`.

Closes: #200
Approved by: whitequark
2018-05-08 01:27:28 +08:00
Dan Robertson 9747733dd7 Use time types in socket
Use the time types (Instant and Duration) in the socket modules instead
of a simple u64.

Closes: #141
Approved by: whitequark
2018-02-16 10:44:03 +08:00
Philipp Oppermann 6b3f103c05 Return specific sockets from `new` functions instead of `Socket`.
* Add Into<Socket> implementations for sockets
* Make SocketSet::add generic over Into<Socket>
2018-01-28 14:36:23 +00:00
whitequark f494200c8c Disregard TCP FIN flag if it arrives in a segment not at window start.
Fixes #111.
2018-01-05 21:06:20 +00:00
Dan Robertson b653a6e421 Fix documentation warnings.
- There are several warnings that are thrown when running `cargo doc`. Fix
  these warnings.
- Convert all module documentation to use /*! for consistency.
2018-01-05 19:38:23 +00:00
Dan Robertson 439e0a2cc1 Add the proto-ipv4 feature. 2017-12-24 13:28:59 +00:00
whitequark 436f4ef624 Correctly handle retransmission of lost-received-lost TCP segments.
Thanks @pothos for initial analysis of the issue.
2017-12-22 19:31:04 +00:00
whitequark ae17151f2a Fix a few documentation issues. NFC. 2017-12-22 13:13:43 +00:00
whitequark a45b3d9eab TcpSocket::recv_impl should have never been public, oops. 2017-12-22 13:11:11 +00:00
whitequark fec3bb32eb Make the log crate properly optional. 2017-12-22 09:57:38 +00:00
whitequark bd40265d3a Use a more specific log message for keep-alive or probe TCP packets. 2017-12-21 10:39:54 +00:00
Dan Robertson c5c2264cdc Use hop limit instead of ttl
Use hop limit instead of ttl for method and member names.
2017-12-18 13:47:34 +00:00
whitequark 278bb4b2c9 Trace the TCP socket acknowledging incoming segment. 2017-12-18 12:47:42 +00:00