Commit Graph

277 Commits

Author SHA1 Message Date
bors[bot] 2c304b4e8b Merge #563
563: Print log to stdout in test r=Dirbaio a=deantvv

Use simple [trick](https://github.com/rust-lang/log/issues/106) to allow print log to stdout in test

Co-authored-by: Dean Li <deantvv@gmail.com>
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-11-03 22:02:06 +00:00
Dario Nieuwenhuis 565da5ab33 Remove manual `log::set_logger` from tests.
No longer needed since `net_debug!` and `net_trace!` now call `println!` directly
when testing!
2021-11-03 23:00:26 +01:00
luojia65 c111bee3b6 Code format using `cargo fmt` 2021-10-27 16:35:05 +08:00
luojia65 a714def8d0 Add lint `#[must_use]` for ring buffer functions.
This lint is in stable Rust now: https://github.com/rust-lang/rust/issues/43302.
These changes are noted according to code comment from @whitequark.
Some test cases and functions are altered due to changes of #[must_use].
2021-10-27 16:26:57 +08:00
Dario Nieuwenhuis 3baa13372c tcp: Reply with RST to ACKs with invalid ackno in SYN_SENT.
Should fix aramperes/onetun#17
2021-10-19 03:38:44 +02:00
Dario Nieuwenhuis 61293b2cb2 tcp: Make initial sequence number random. 2021-10-11 20:53:04 +02:00
Dario Nieuwenhuis 0d467df5f3 tcp: reply with RST to invalid SYNACKs in SynReceived state.
This matches the Linux behavior.
2021-10-06 02:44:39 +02:00
Dario Nieuwenhuis 3af5386bc5 tcp: do not abort socket when receiving invalid packets.
This matches the Linux behavior.
2021-10-06 02:36:23 +02:00
Dario Nieuwenhuis 1f25a986c7 tcp: reply with RST to invalid ACKs in SynReceived state.
This mirrors the Linux behavior, and helps cleanup desynced state.
2021-10-06 02:25:11 +02:00
Dario Nieuwenhuis 3a2cdc8680 tcp: rate-limit challenge ACKs.
This fixes infinite-packet-loop issues where two peers have
desynced and both think the other's sequence numbers are wrong.

Found with cargo-fuzz.
2021-10-06 01:52:57 +02:00
Dario Nieuwenhuis c7ae2e4f9b tcp: clarify comment 2021-10-06 01:24:01 +02:00
Dario Nieuwenhuis aea021cfa9 tcp: make match on (state, control, ack) more readable. 2021-10-06 01:03:13 +02:00
qiujiangkun acfa7f0b19 use micros in Instant and Duration 2021-10-05 22:33:58 +02:00
Dario Nieuwenhuis 49b1a61495 tcp: fix "attempt to negate with overflow" when initial seq is 0xFFFF_FFFF.
Found with cargo-fuzz.
2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis f044edf805 tcp: add test for ack one-too-high in SYN_RECEIVED. 2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis b50532cabd tcp: do not switch to ESTABLISHED when ack in syn-received is one too low. 2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis 07c6fb835d tcp: fix "subtract with overflow" when ack in syn-received is one too low.
Found with cargo-fuzz.
2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis 16abd60e9b tcp: in SYN_SENT only accept SYNACK, discard everything else.
THis would let FIN packets through, breaking the logic below.

Found with cargo-fuzz.
2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis 947a69b8b2 tcp: don't force-send data on retransmit.
Previous code had an `if` to force sending a packet when retransmitting.
When the remote window is zero this would cause an infinite loop of
sending empty packets, because the "retransmit" flag would never get cleared.

Remove the force-retransmit, and add an explicit check on `seq_to_transmit` for
pending SYNs because SYN retransmission relied on it.

Found with cargo-fuzz.
2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis e19151b9d0 tcp: disallow zero MSS.
This causes an infinite loop of zero-length packets: when we have data
to send, it sends MSS-length packets until filling the window, which
is an infinte amount of packets because mss is zero.

Found with cargo-fuzz.
2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis 7f30c7268b tcp: fix use of fractional .millis() that should be .total_millis() in rtte. 2021-10-05 01:38:31 +02:00
Dario Nieuwenhuis 28e350f300 tcp: Fix clippy 2021-10-03 21:20:24 +02:00
bors[bot] f058a94b85 Merge #529 #530
529: Fix typos in tcp docs r=Dirbaio a=david-sawatzke

Too few round brackets

530: tcp: fix delayed ack causing ack not to be sent after 3 packets. r=Dirbaio a=Dirbaio



Co-authored-by: david-sawatzke <david-sawatzke@users.noreply.github.com>
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-09-16 23:18:14 +00:00
Thibaut Vandervelden 82a62327ba Fix clippy because of MSV change 2021-09-16 19:44:26 +02:00
Dario Nieuwenhuis ddfabb42f0 tcp: fix delayed ack causing ack not to be sent after 3 packets. 2021-09-15 04:01:43 +02:00
david-sawatzke 1f8110687d Fix typos in tcp docs 2021-09-14 18:08:04 +02:00
Thibaut Vandervelden 6a27136047 Fix clippy lints 2021-08-18 16:05:50 +02:00
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