Commit Graph

1011 Commits (55c22b9865039dabf89c13fa09378157448add00)

Author SHA1 Message Date
Dario Nieuwenhuis 55c22b9865 readme: add instructions on how to setup a bridged tap. 2021-10-19 03:06:37 +02:00
bors[bot] 03492be337 Merge #549
549: wire: add From<Address> for ::std::net::IpAddr r=Dirbaio a=Dirbaio

Originally from #296 

Co-authored-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-10-19 00:49:10 +00:00
Marc-André Lureau aa10b5250a wire: add From<Address> for ::std::net::IpAddr
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-10-19 02:27:49 +02:00
bors[bot] d0928cf068 Merge #548
548: DHCP fixes r=Dirbaio a=Dirbaio

Several fixes, including one that fixes DHCP not working with some routers.

See individual commit messages for details.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-18 23:25:22 +00: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 6d37633353 wire/dhcp: use bitflags for the FLAGS field. 2021-10-14 14:02:27 +02:00
Dario Nieuwenhuis fc5559069c wire/dhcp: BROADCAST flag is MSB (0x8000), not LSB (0x0001).
This fixes DHCP on Linksys WRT1900AC. With 0x0001, it would not reply to
DISCOVERs at all, probably because seeing an unknown reserved flag being set.
With 0x8000, it works fine.
2021-10-14 13:59:16 +02:00
bors[bot] c0a46e2d14 Merge #547
547: Basic rand infrastructure. r=Dirbaio a=Dirbaio

See [previous discussion](https://github.com/smoltcp-rs/smoltcp/pull/465#pullrequestreview-774487285). Opening a separate PR so it can be discussed separately.

- Add `smoltcp::rand`.
  - On `std` targets, `OsRng` is used by default.
  - The user can supply a custom impl by enabling the `rand-custom-impl` Cargo feature and using the `rand_custom_impl!()` macro.
  - Specifying a custom impl is mandatory when `std` is not enabled.
- Make TCP initial sequence numbers actually random.


Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-14 11:53:41 +00:00
Dario Nieuwenhuis 61293b2cb2 tcp: Make initial sequence number random. 2021-10-11 20:53:04 +02:00
Dario Nieuwenhuis 17e0ddcee3 Add rand module.
On `std` targets, `OsRng` is used by default. The user can supply a custom impl
by enabling the `rand-custom-impl` Cargo feature and using the `rand_custom_impl!()` macro.
Specifying a custom impl is mandatory when `std` is not enabled.
2021-10-11 20:53:04 +02:00
bors[bot] 1ba5283cf7 Merge #545
545: time: fix incorrect conversion from std r=Dirbaio a=Dirbaio

from #514 

cc `@qiujiangkun` 

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-07 02:59:32 +00:00
Dario Nieuwenhuis d98f56f8bd time: fix incorrect conversion from std 2021-10-07 04:57:59 +02:00
bors[bot] bf5f0abc31 Merge #542 #544
542: More TCP fixes r=Dirbaio a=Dirbaio

See individual commit messages for details.

544: ARP fixes r=Dirbaio a=Dirbaio



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-06 19:13:12 +00:00
Dario Nieuwenhuis b4d7819769 arp: ignore ARP packets that are not REQUEST or RESPONSE. 2021-10-06 04:12:33 +02:00
Dario Nieuwenhuis 975ae59eab arp; reject packets with source address not in our network.
Fixes #536
2021-10-06 04:12:20 +02:00
Dario Nieuwenhuis 271ec5d26b arp: fill cache only for ARP packets directed at us.
- Mirrors what Linux does, so will hopefully reduce problems in broken networks.
- it can actually increase performance: for small ARP caches, it'll reduce the
  amount of entries that we're not going to use, increasing the chances of the
  ones that we actually use to stay in the cache.

Fixes #537
2021-10-06 04:12:17 +02:00
Dario Nieuwenhuis f98a89ba61 arp: Do not fill cache from random packets.
On paper this looks great, and in a sane network it should work.
However the world out there is full of horribly broken, screwed up
networks, which *of course* ruin this.

I've seen a customer's network where the router is IP 192.168.1.1,
MAC addr xx:03. However, every 1 minute the router broadcasts some
"mikrotik discovery" UDP garbage with source IP 192.168.1.1, source MAC
addr xx:02 (one less!). This accidentally poisons smoltcp's ARP cache,
which then sends all traffic for the default gateway to xx:02, which
unsurprisingly blackholes it.

And, of course, the broadcast is every 1min and the ARP cache lifetime
is 1min. This means the cache is almsot all the time poisoned, and the
smoltcp device barely works. Fantastic.

Screw you mikrotik.
2021-10-06 03:12:53 +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
bors[bot] 6fee12dcee Merge #514
514: use micros in Instant and Duration r=Dirbaio a=qiujiangkun

This improves precision everywhere, especially pcap
https://github.com/smoltcp-rs/smoltcp/pull/513

Co-authored-by: qiujiangkun <qiujiangkun@foxmail.com>
2021-10-05 20:35:20 +00:00
qiujiangkun acfa7f0b19 use micros in Instant and Duration 2021-10-05 22:33:58 +02:00
bors[bot] 120a8452cd Merge #538
538: TCP fuzz fixes r=Dirbaio a=Dirbaio

Fixes panics and hangs found by whole-stack fuzzing. See individual commit messages.

Will post the whole-stack fuzz target when it's fully clean.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-05 20:17:50 +00:00
bors[bot] 9539e7987a Merge #540
540: make bors checks much simpler r=Dirbaio a=Emilgardis



Co-authored-by: Emil Gardström <emil.gardstrom@gmail.com>
2021-10-05 20:09:54 +00:00
Emil Gardström 28c6dc6faf make bors checks much simpler 2021-10-05 21:50:50 +02:00
bors[bot] 4acde9ff15 Merge #539
539: Update README.md r=Dirbaio a=Dirbaio



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-05 19:46:50 +00:00
Dario Nieuwenhuis 3458bffc0c Update README.md 2021-10-05 21:35:02 +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
bors[bot] 4692119e05 Merge #535
535: Fuzz fixes r=Dirbaio a=Dirbaio



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2021-10-04 23:34:22 +00:00
Dario Nieuwenhuis 6d61f5ab6c phy: fix wrong order in FuzzInjector TX. Fixes #525. 2021-10-03 21:39:55 +02:00
Dario Nieuwenhuis 8058a6289f fuzz: Modernize fuzz crate, fix tcp_headers not compiling. 2021-10-03 21:29:40 +02:00
Dario Nieuwenhuis b674f0d0ba phy: simplify PcapSink trait 2021-10-03 21:29:40 +02:00
Dario Nieuwenhuis 28e350f300 tcp: Fix clippy 2021-10-03 21:20:24 +02:00