Commit Graph

1011 Commits

Author SHA1 Message Date
Alex Crawford 27232041e7 Silence a few warnings from clippy
These were flagged by `cargo clippy`:

    warning: the operation is ineffective. Consider reducing it to `number`
    warning: this function has too many arguments (8/7)
    warning: you should consider adding a `Default` implementation for
             `phy::loopback::Loopback`

I like the code better as it is.
2020-12-28 23:09:53 -08:00
Alex Crawford 8a961b7d7c Use iterators instead of manually looping
These were flagged by `cargo clippy`:

    warning: the loop variable is used to index

I've verified that this doesn't increase the size of consuming binaries.
Pretty impressive. I tested this with a project that uses the following
features: ethernet, proto-dhcpv4, socket-tcp.
2020-12-28 22:28:07 -08:00
Alex Crawford 20c82238df Remove some unneeded imports and a variable
These were flagged by `cargo clippy`:

    warning: returning the result of a `let` binding from a block
    warning: this import is redundant
2020-12-28 22:28:06 -08:00
Alex Crawford fff5926210 Clean up a couple of if-blocks
These were flagged by `cargo clippy`:

    warning: this `else { if .. }` block can be collapsed
2020-12-28 22:27:24 -08:00
Alex Crawford e27f6cb564 Remove redundant field names from structs
These were flagged by `cargo clippy`:

    warning: redundant field names in struct initialization

There are plenty more redundant field names, but I only changed the ones
where the initialization was a single line of code. I still prefer the
redundant style for multi-line initializations (and I'm under the
impression that others agree), so I've also disabled the warning.
2020-12-28 22:27:24 -08: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
Dario Nieuwenhuis f67097cf3f Merge pull request #399 from smoltcp-rs/medium-ip-part1
Add IP medium support, part 1
2020-12-28 14:31:33 +01:00
Dario Nieuwenhuis 004d054003 Merge pull request #402 from crawford/clippy
Some more cleanup suggested by cargo clippy
2020-12-28 02:05:08 +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 81ddfe734f Remove some redundant closures
These were flagged by `cargo clippy`:

    warning: redundant closure found
2020-12-27 17:00:03 -08:00
Alex Crawford 737fdf7bbf Use subsec_millis where possible
These were flagged by `cargo clippy`:

    warning: calling `subsec_millis()` is more concise than this
             calculation
2020-12-27 17:00:03 -08:00
Alex Crawford ec5c924d88 Prefer elided lifetimes
These were flagged by `cargo clippy`:

    warning: explicit lifetimes given in parameter types where they
             could be elided (or replaced with `'_` if needed by type
             declaration)
2020-12-27 17:00:03 -08:00
Alex Crawford d2b557e01c Prefer assignment operators
These were flagged by `cargo clippy`:

    warning: manual implementation of an assign operation
2020-12-27 17:00:03 -08:00
Alex Crawford a73c90ad08 Silence warning about matches macro
These were flagged by `cargo clippy`:

    warning: match expression looks like `matches!` macro

The matches! macro isn't stabilized until Rust 1.42.
2020-12-27 17:00:02 -08:00
Alex Crawford 79e81bf97f Silence warning about is_empty method
These were flagged by `cargo clippy`:

    warning: item has a public `len` method but no corresponding
             `is_empty` method
2020-12-27 16:59:39 -08:00
Alex Crawford 1a1861721b Silence warning about non-exhaustive pattern
These were flagged by `cargo clippy`:

    warning: this seems like a manual implementation of the
             non-exhaustive pattern

The non_exhaustive attribute isn't available until we increase the
minimum Rust version to 1.40, so we should just silence these warnings
in the meantime.
2020-12-27 16:59:30 -08:00
Alex Crawford 752e81489e Dereference match expressions to clean up patterns
These were flagged by `cargo clippy`:

    warning: you don't need to add `&` to all patterns

This should have happened in ac830e8b, but I guess I missed it.
2020-12-27 15:20:16 -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 708be1ccb5 Split Packet into EthernetPacket and IpPacket.
Functions that only deal with IP packets take/return IpPacket's. IpPacket's
are wrapped into EthernetPacket's as late as possible.

This will later allow generalizing Interface to handle both Ethernet
and pure-IP mediums.
2020-12-27 19:57:18 +01:00
Dario Nieuwenhuis 2d7b150984 Remove "None" variant from Packet, use Option<Packet> instead. 2020-12-27 19:25:25 +01:00
Dario Nieuwenhuis 2c8b780702 tcp: fix racey simultaneous close not sending FIN. 2020-12-27 19:11:52 +01:00
Dario Nieuwenhuis 71a5e41b9e Merge pull request #396 from smoltcp-rs/rust-2018
Update to Rust 2018
2020-12-27 18:49:52 +01:00
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
Dario Nieuwenhuis 1d5a329155 Merge pull request #394 from smoltcp-rs/async
Async/await waker support.
2020-12-27 17:33:22 +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 0c7cdbb4ef Remove unnecessary returns
These were flagged by `cargo clippy`:

    warning: unneeded `return` statement
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
Alex Crawford d217c81e5d Remove explicit calls to as_ref/as_mut
These were flagged by `cargo clippy`:

    warning: this call to `as_ref` does nothing
    warning: this call to `as_mut` does nothing
2020-12-26 10:27:32 -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 21deb47bbb Enable `proto-dhcpv4` feature by default. Fixes #327 2020-12-26 02:06:06 +01:00
Dario Nieuwenhuis 12f2e0f7e2 Merge pull request #372 from JOE1994/null_terminator
add null terminator to c-string passed to 'libc::open'
2020-12-26 00:24:27 +01:00
Dario Nieuwenhuis ebe9e9c450 Merge pull request #393 from smoltcp-rs/linux-mtu-fix
Fix MTU of RawSocket and TapInterface.
2020-12-26 00:07:48 +01:00
JOE1994 e12f4abaa0 add null terminator to c-string passed to libc API 2020-12-26 00:07:14 +01:00
Dario Nieuwenhuis 273f4d60b6 Fix MTU of RawSocket and TapInterface.
Linux's MTU is the IP MTU, while smoltcp's is the Ethernet MTU.
Therefore we have to add the ethernet header size to it.
2020-12-25 23:57:54 +01:00
Dario Nieuwenhuis a40a4ac5af Remove .test_like_travis.rb 2020-12-25 23:57:35 +01:00
Daniel Egger 675374d3ed Merge pull request #390 from smoltcp-rs/gha
Add Github Actions for CI
2020-12-23 09:56:04 +01:00
Adam Greig 49c0871b34 Remove Travis configuration 2020-12-22 15:31:16 +00:00
Adam Greig 8fb34901a7 Add Github Actions for CI 2020-12-22 13:11:35 +00: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
whitequark de5f91a28b Take MTU into account during TcpSocket dispatch. 2020-10-25 12:35:42 +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
Sam Jones d32c72aafd Changed Dhcpv4Client to use device checksum capabilities 2020-10-22 10:31:36 +00:00
whitequark 7375c67a43 dhcpv4: use offered ip in requested ip option
Instead of configuring the ifaces ip address when a dhcp server offers
and ip, we now use the requested_ip option, based on the offered ip
(yiaddr). The user now only has to configure the iface once the dhcp
transaction has completed (Ack'd).
2020-10-22 10:04:03 +00:00
whitequark 3e22502f61 Merge branch 'master' into dhcpv4-use-requested_ip 2020-10-22 09:53:38 +00:00