160 Commits

Author SHA1 Message Date
Dario Nieuwenhuis
ed0cf16750 socket_set: add get_mut, make get immutable. 2022-05-25 03:28:23 +02:00
Dario Nieuwenhuis
8ecd4360a1 iface: borrow the device instead of owning it. 2022-05-25 03:28:23 +02:00
Dario Nieuwenhuis
4d6c22a3ff iface: borrow the SocketSet instead of owning. 2022-05-25 03:28:23 +02:00
Dario Nieuwenhuis
43329e696e socket/dns: add own error enums for public API. 2022-05-20 23:36:36 +02:00
Dario Nieuwenhuis
72a9ee46ce socket: reorganize module structure, with one module per protocol. 2022-05-20 02:18:00 +02:00
Dario Nieuwenhuis
78f92bcea6 wire: use own Error type. 2022-05-20 01:37:34 +02:00
Dario Nieuwenhuis
ea0d4d7f46 dns: allow specifying name in human-friendly format. 2022-05-19 21:36:13 +02:00
Dario Nieuwenhuis
ce1f0169f8 dns: use Vec for server address list. 2022-05-19 19:54:38 +02:00
Dario Nieuwenhuis
da1a2b2df0 socket: add DNS 2022-05-19 19:13:57 +02:00
Dario Nieuwenhuis
eb41d077e0 Remove IpAddress::Unspecified, assign src addr in sockets.
This continues work started in #579, with the goal of "remove unspecified variants from wire".

"unspecified" variants are bad, they've been a source of bugs in the past. The issue with them is that
depending on the context it may or may not make sense for the value to be unspecified.
It's better to not have them, and then use Option only where the value can really be unspecified.

This removes lots of `Address::Unspecified => unreachable!()` and similar match arms, which shows the
unreachable variant was actively unwanted in many places.

This fixes the "unspecified src addr" panic:

- Picking src addr is now the resposibility of the sockets, not the interface. All sockets now emit IpReprs with properly assigned src addr.
- Removed the `assert!(!ip_repr.src_addr().is_unspecified());`. This assert is WRONG even if
  now sockets pick the source address, because there ARE cases where we indeed want to send a
  packet with zero src addr, for example in DHCP.
2022-05-19 04:38:55 +02:00
Alexandra Sandulescu
9b5abf0e88 Update dependencies: ignore those updated through caret spec
* allow logging environment overwrite by RUST_LOG
2022-01-28 18:49:18 +01:00
Alexandra Sandulescu
842c875f92 Update dependencies 2022-01-28 12:58:24 +01:00
Dario Nieuwenhuis
3644b94b82 rand: use simple PRNG owned by Interface, sockets access it through Context. 2021-11-30 18:36:17 +01:00
Dario Nieuwenhuis
9a2093e39e Remove braces that were previously needed to workaround SocketRef borrow issues. 2021-11-03 23:32:32 +01:00
Dario Nieuwenhuis
ef213fa772 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
bde881d2f9 iface: own the SocketSet instead of borrowing it 2021-11-03 23:32:32 +01:00
Thibaut Vandervelden
f67f024882 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
b74cd58036 example/6lowpan: expand readme, do not use monitor interface.
Using a raw socket on `monitor0` causes weird results: packets we receive
include FCS, packets we send are parsed as if they didn't have FCS, except
by wireshark which always expects a FCS??

Turns out the sane way is to use raw sockets on normal `wpanX` interfaces,
in which case all packets we send/receive are without FCS.
2021-10-21 01:25:13 +02:00
Dario Nieuwenhuis
68e25a29c3 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
3d782f19cd Add support for 802.15.4 and 6LoWPAN 2021-10-21 01:25:12 +02:00
Dario Nieuwenhuis
67c3b3b7b1 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
qiujiangkun
a4275a5966 use micros in Instant and Duration 2021-10-05 22:33:58 +02:00
Dario Nieuwenhuis
dfe8265772 phy: simplify PcapSink trait 2021-10-03 21:29:40 +02:00
Dario Nieuwenhuis
750fcb1887 Fix redundant closure clippy 2021-06-27 10:43:05 +02:00
Dario Nieuwenhuis
2cb407d62a rustfmt 2021-06-27 09:31:59 +02:00
Dario Nieuwenhuis
adb3b30cd7 dhcp: address review comments. 2021-05-28 18:23:50 +02:00
Dario Nieuwenhuis
e82ef25e91 dhcp: add max_lease_duration option 2021-04-13 20:23:28 +02:00
Dario Nieuwenhuis
b791ef535e dhcp: convert to socket 2021-04-07 19:00:36 +02:00
Dario Nieuwenhuis
49fa987cdc Add defmt logging support 2021-04-01 01:30:47 +02:00
Dario Nieuwenhuis
56bff5dcca Add IP medium support to PcapWriter and Tracer. 2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis
b869449b31 Add support for TUN interfaces. 2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis
d352e151f6 Add support for IP mediums.
- Add `medium` in `DeviceCapabilities`.
- Rename EthernetInterface to Interface.
- Add support to Interface for both Ethernet and IP mediums. The medium to use is detected from `device.capabilities().medium`.
- Ethernet-only features are gated behind the "ethernet" feature, as before.
- IP features are always enabled for now.
2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis
923d6375f8 Remove unnecessary semicolon 2021-01-08 19:25:21 +01:00
Alex Crawford
1cbc38d0ea Clean up examples
These were flagged by `cargo clippy`:

    warning: you seem to be trying to use match for destructuring a
             single pattern. Consider using `if let`
    warning: called `.nth(0)` on a `std::iter::Iterator`, when `.next()`
             is equivalent
    warning: using `write!()` with a format string that ends in a single
             newline
    warning: useless conversion to the same type:
             `smoltcp::wire::Ipv4Address`
    warning: called `map(f)` on an `Option` value where `f` is a closure
             that returns the unit type `()`
    warning: returning the result of a `let` binding from a block
    warning: use of `unwrap_or` followed by a function call
2021-01-04 10:39:27 -08:00
Alex Crawford
400432802e Remove an unneeded semicolon 2020-12-28 23:20:01 -08:00
Alex Crawford
1ff8edf201 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
323dfe2ab6 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
1e40b934bf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
Alex Crawford
ccf6915186 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
a3d6c1a0de Fix crash in server example due to returning length bigger than received buffer. 2020-04-16 07:39:11 +00:00
Jeremy Andrews
2b92dfcf95 replace the use of the deprecated item (#314) 2019-11-02 19:11:08 +00:00
whitequark
bd3912e53e Bump log dependency to version 0.4. NFC.
This doesn't affect downstream code because log 0.3.9 is a facade
crate implemented in terms of log 0.4, and so log 0.3 and log 0.4
APIs can be used together.
2019-06-22 08:31:11 +00:00
whitequark
a4d0a7e39c Fix unused mut in examples/ping.rs. NFC. 2019-06-22 08:20:41 +00:00
whitequark
83dba8ea31 Bump Rust version requirement to 1.27.
This allows us to use:
(1.26)
  - impl Trait
  - autoderef in pattern matching
  - fixed slice patterns
  - inclusive ranges
(1.27)
  - dyn Trait
  - #[must_use] on functions

To prepare for edition change, dyn is added where applicable. Other
edition changes would require bumping the requirement even higher,
and so they are not applied for now.
2019-06-22 08:19:39 +00:00
Astro
657c9aa63a Implement DHCPv4 client + example.
Closes: #186
Approved by: whitequark
2019-05-14 00:37:43 +08:00
Astro
58a54730db Implement IGMPv1/v2 processing.
Closes: #178
Approved by: whitequark
2018-08-01 10:26:51 +08:00
whitequark
185a0ca781 examples: remove the remaining panics on poll error. 2018-07-31 13:58:00 +00:00
whitequark
4a253fecdf Rename new method on Packet types to new_checked.
Fixes #195.

Closes: #254
Approved by: dlrobertson
2018-07-11 12:59:05 +08:00
Michal Podhradsky
4c7606d9c3 Log and print error for all examples 2018-06-22 19:30:03 +00:00
Valentin Lorentz
06d18130cd Add support for arbitrarily many routes instead of only gateways.
Closes: #219
Approved by: whitequark
2018-06-10 05:31:08 +08:00