Commit Graph

250 Commits

Author SHA1 Message Date
qiujiangkun 2a574fbca6 various clippy fix 2021-06-27 10:45:57 +02:00
Dario Nieuwenhuis 98fe17890a rustfmt 2021-06-27 09:31:59 +02:00
Dario Nieuwenhuis 9101e039d5 tcp: do not scale window in SYN packets. 2021-06-17 06:22:30 +02:00
Dario Nieuwenhuis 4045dee3f9 tcp: don't do window scaling when connecting if remote doesn't support it. 2021-06-17 06:02:36 +02:00
Dario Nieuwenhuis 736a17cae3 tcp: fix window scaling of synack being ignored. 2021-06-17 05:56:01 +02:00
Dario Nieuwenhuis 60a299bcc2 tcp: add Nagle's Algorithm. 2021-06-17 04:44:13 +02:00
Dario Nieuwenhuis 32311b23dc Add Context struct. 2021-06-17 03:20:58 +02:00
Dario Nieuwenhuis 0754a7703c tcp: use nonzero initial sequence number. 2021-06-11 22:36:26 +02:00
Dario Nieuwenhuis caad8929d5 tcp: fix substract with overflow when receiving a SYNACK with unincremented ACK number. 2021-06-11 22:17:59 +02:00
Dario Nieuwenhuis f1b0a04599 tcp: extract ack_min, ack_max vars 2021-06-11 22:17:24 +02:00
Dario Nieuwenhuis de950ef823 Fix "subtract sequence numbers with underflow" on remote window shrink.
Fixes #489
2021-06-11 11:25:30 +02:00
Dario Nieuwenhuis a5b9461275 tcp: LastAck should only change to Closed on ack of fin.
Fixes #470
2021-05-28 21:09:36 +02:00
Dario Nieuwenhuis 383d2426cb tcp rtte: fix "attempt to multiply with overflow". Fixes #468 2021-05-28 21:02:31 +02:00
Dario Nieuwenhuis d64c8593f0 Add defmt logging support 2021-04-01 01:30:47 +02:00
Dario Nieuwenhuis b6220a04c8 Do not use DeviceCapabilities in sockets.
DeviceCapabilities contains the `medium` field, so tests had to give it a value
even if it was unused. This is impossible to do with no `medium-*` enabled, because
it makes `Medium` uninhabited (empty enum).
2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis 4933a0a19f Merge pull request #431 from dnadlinger/patch-2
socket/tcp: Fix missing ` in doc comment
2021-03-07 07:58:04 +01:00
David Nadlinger b5eca87885 socket/tcp: Fix missing ` in doc comment 2021-03-07 04:14:10 +00:00
David Nadlinger 3fb05f0857 socket/tcp: Fix is_active comment typo 2021-03-07 04:09:44 +00:00
Alex Crawford 0cf0a7e386 Clean up clippy warnings about if-else blocks
This de-duplicates and (hopefully) simplifies a few if-else blocks. The
others were given an exception because I thought they were more readable
as is. I've verified that these changes don't result in larger binaries.
2021-01-10 14:30:31 -08:00
Dario Nieuwenhuis c09ca370b2 Simplify Socket lifetimes 2021-01-09 01:59:02 +01:00
Dario Nieuwenhuis 2ea2b7ff6b tcp: add Delayed ACK 2021-01-07 00:21:55 +01:00
Alex Crawford cb66f9f036 Allow DeviceCapabilities to be initialized
This was flagged by `cargo clippy`:

    warning: field assignment outside of initializer for an instance
             created with Default::default()

This changes the visibility of the dummy field to be public, but only to
the crate.
2021-01-04 10:39:33 -08:00
Dario Nieuwenhuis bb891ce7c1 tcp: Add RTT estimation. 2021-01-04 03:26:55 +01:00
Dario Nieuwenhuis 45df367d7e More clippy fixes. 2021-01-04 01:19:20 +01:00
Dario Nieuwenhuis adce62a795 Merge pull request #398 from smoltcp-rs/simultaneous-close
tcp: fix racey simultaneous close not sending FIN.
2020-12-28 14:49:13 +01:00
Alex Crawford e78c9576b2 Clean up iterator chains
These were flagged by `cargo clippy`:

    warning: called `is_some()` after searching an `Iterator` with find.
             This is more succinctly expressed by calling `any()`.
    warning: this `.into_iter()` call is equivalent to `.iter_mut()` and
             will not consume the `BTreeMap`
    warning: called `skip_while(p).next()` on an `Iterator`

The skip_while conversion is a little tricky. Clippy notes that:

    warning: called `skip_while(p).next()` on an `Iterator`
    help: this is more succinctly expressed by calling `.find(!p)` instead

So the condition of the skip_while is inverted and then simplified using
De Morgan's laws.
2020-12-27 17:00:03 -08:00
Alex Crawford 321998eb66 Prefer if-let syntax over single-pattern match
These were flagged by `cargo clippy`:

    warning: you seem to be trying to use match for destructuring a
             single pattern. Consider using `if let`

This also silences a few cases where the match couldn't be replaced with
an if because of the following error:

    error: attributes are not yet allowed on `if` expressions

Once we increase the minimum Rust version to 1.43, these can be updated
as well.
2020-12-27 15:20:14 -08:00
Alex Crawford b2c04416c2 Use is_empty instead of length comparison
These were flagged by `cargo clippy`:

    warning: length comparison to zero
2020-12-27 15:18:51 -08:00
Dario Nieuwenhuis 2c8b780702 tcp: fix racey simultaneous close not sending FIN. 2020-12-27 19:11:52 +01:00
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