Commit Graph

390 Commits (master)

Author SHA1 Message Date
Dario Nieuwenhuis eda4af4e68 Fix clippys 2021-11-03 23:38:23 +01:00
Dario Nieuwenhuis a6b3b64c78 socket/set: remove reference counting.
It is never used in practice, so it's not worth the complexity
and the extra RAM usage.
2021-11-03 23:32:32 +01:00
Dario Nieuwenhuis f8cc1eacbe socket: remove SocketRef.
The intent was to run custom code after the user is done modifying the socket,
for example to update a (not yet existing) port->socket map in SocketSet. However
this wouldn't work, since the SocketRef would have to borrow the SocketSet at
the same time as the Socket to be able to notify the SocketSet.

I believe such indexing can be achieved by setting a "dirty" bit *before* giving
the socket to the user, then on poll() reindexing all dirty sockets. This could
even be faster: if user gets a socket multiple times between polls, it'd be reindexed
only once.
2021-11-03 23:32:32 +01:00
Dario Nieuwenhuis b1d6104a74 socket/dhcpv4: return owned Config in Event. 2021-11-03 23:25:53 +01:00
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
Thibaut Vandervelden 1154390307 Use one PAN ID for source and destination
Also check for the correct destination PAN id when receiving a frame (as
discussed). Linux does this as well.
However, hardware implementations also can drop those packets.
2021-10-21 01:25:13 +02:00
Dario Nieuwenhuis b4764e4973 Add RawHardwareAddress, use it in wire ndisc.
This avoids wire needing to know what medium we're on.
2021-10-21 01:25:13 +02:00
Thibaut Vandervelden fb2d0029d8 Add support for 802.15.4 and 6LoWPAN 2021-10-21 01:25:12 +02: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 48debf7db8 dhcp: add "ignore NAKs" option.
This workarounds a known broken Vodafone Fiber router which replies
with both NAK and ACK:

![screenshot-2021-10-19_01-18-41](https://user-images.githubusercontent.com/1247578/137819133-a8f9ab28-8bc5-4cca-9c91-2eac15d88070.png)
2021-10-19 01:17:28 +02:00
Dario Nieuwenhuis bcf6211fbe socket/dhcp: add nak tests 2021-10-15 01:02:31 +02:00
Dario Nieuwenhuis a43a6772c9 socket/dhcp: add retransmission/timeout tests 2021-10-15 00:43:21 +02:00
Dario Nieuwenhuis 6768d89165 socket/dhcp: add renew test 2021-10-14 23:33:25 +02:00
Dario Nieuwenhuis 94541ae827 socket/dhcp: add basic test 2021-10-14 23:19:30 +02:00
Dario Nieuwenhuis 3b7100c501 socket/dhcp: log incoming reprs as well as outgoing. 2021-10-14 19:41:10 +02:00
Dario Nieuwenhuis af4db615f5 socket/dhcp: Use random transaction_id instead of sequential.
This is a minor security improvement against blind packet spoofing, since
it adds more entropy to the packets.
2021-10-14 14:10:08 +02:00
Dario Nieuwenhuis d34f4f783b socket/dhcp: do not set BROADCAST flag.
Reasons:
1. We were already accidentally not setting the BROADCAST flag due to it being the wrong bit (see previous commit).
2. Major OSes don't set it.
3. rfc1542 section 3.1.1 states it's discouraged, and the issue it's supposed to workaround doesn't apply to smoltcp.

    Unfortunately, some client implementations are
    unable to receive such unicast IP datagrams until they know their own
    IP address
    (..)
    This addition to the protocol is a workaround for old host
    implementations.  Such implementations SHOULD be modified so
    that they may receive unicast BOOTREPLY messages, thus making
    use of this workaround unnecessary.  In general, the use of
    this mechanism is discouraged.
2021-10-14 14:03:50 +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 8ce629257a Remove trailing commas in macros
This is going to become a hard error in future releases of the compiler.
2021-08-19 12:07:56 +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