39 Commits

Author SHA1 Message Date
Dario Nieuwenhuis
3a080d818b Clippy fixes 2023-01-02 00:20:05 +01:00
Dario Nieuwenhuis
13cc7f83ac Clippy fixes. 2022-11-06 21:45:21 +01:00
Dario Nieuwenhuis
4300e7cc3b GAT-based Device trait.
The current `'a` lifetime in the `Device` trait is essentially a workaround for lack of GATs.
I'm just experimenting how this would look like, it'll have to wait until GATs are stable to go in.

The main benefit is structs implementing `Device` can now borrow stuff. This wasn't possible
before because the `for<'d> T: Device<'d>` bounds would essentially imply `T: 'static`.
2022-11-06 21:18:02 +01:00
Dario Nieuwenhuis
ecb4cbc545 Clippy fixes. 2022-08-06 00:00:19 +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
Thibaut Vandervelden
3d782f19cd Add support for 802.15.4 and 6LoWPAN 2021-10-21 01:25:12 +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
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
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
Dario Nieuwenhuis
1e40b934bf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01: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
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
58a54730db Implement IGMPv1/v2 processing.
Closes: #178
Approved by: whitequark
2018-08-01 10:26:51 +08:00
Dan Robertson
470a08669f Update phy mod to use new time types
Update everything but the socket types to use the new time types instead
of a basic u64

Closes: #141
Approved by: whitequark
2018-02-16 10:44:03 +08:00
Dan Robertson
8e74fce11d Update examples to use time types
Closes: #141
Approved by: whitequark
2018-02-16 10:44:02 +08:00
寧靜
4aa8ec48ae Add missing #[cfg(feature = "phy-tap_interface")]. 2018-02-04 08:31:03 +00:00
whitequark
3868dcdb14 Split poll_at/poll_delay out of poll.
The previous model was flawed. Consider the following case:
  * The main loop looks as follows (pseudocode):
      loop {
        let _ = (tcp:1234).read_all()
        wait(iface.poll())
      }
  * The remote end is continuously transmitting data and at some
    point fills the window of (tcp:1234), stopping the transmission
    afterwards.
  * The local end processes the packets and, as a part of egress
    routine, emits an ACK. That also updates the window, and
    the socket's poll_at() routine returns None, since there is
    nothing to transmit or retransmit.
  * The local end now waits indefinitely even though it can start
    processing the data in the socket buffers right now.
2017-12-22 12:59:52 +00:00
whitequark
44db954f8e Add a stress test.
Run it without the `log` feature and in release mode:
  $ cargo run --release \
    --no-default-features \
    --features std,phy-tap_interface,socket-tcp \
    --example stress tap0 \
    [reader|writer]

There are currently two bugs exposed by it:
  * a crash in the reader mode,
  * slow-down in the writer mode.
2017-12-22 09:43:00 +00:00
whitequark
b1680368fe Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
Philipp Oppermann
198fe239f1 Redesign the phy::Device trait to avoid Drop impls. 2017-11-03 23:15:07 +00:00
whitequark
39464a53fc Compute soft deadline in poll() and use nonblocking sockets.
Before this commit, anything that touched RawSocket or TapInterface
worked partly by accident and partly because of a horrible crutch
that resulted in massive latencies as well as inevitable packet loss
every time an ARP request had to be issued. Also, there was no way
to use poll() other than by continuously calling it in a busy loop.

After this commit, poll() indicates when the earliest timer expires,
and so the caller can sleep until that moment (or until packets
arrive).

Note that there is a subtle problem remaining: every time poll()
is called, every socket with a pending outbound packet whose
IP address doesn't correspond to a MAC address will send a new
ARP request, resulting in potentially a whole lot of such requests.
ARP rate limiting is a separate topic though.
2017-08-29 19:47:11 +00:00
whitequark
2773fa72ec utils::Dispose → io::Sink. 2017-08-21 07:28:32 +00:00
whitequark
d73c2bdb81 Update fault injector so that rate limiting works without std. 2017-07-23 15:10:57 +00:00
whitequark
c799bfc398 Add --pcap option to all our examples.
Also, generally reorganize and clean up option handling.
2017-07-23 14:57:04 +00:00
whitequark
37ba81f807 Fix an off-by-three-orders-of-magnitude error. 2017-07-23 12:03:56 +00:00
whitequark
8c339d8b7a Fix argument order in Tracer::new callbacks. 2017-07-23 12:01:53 +00:00
whitequark
3a656c1529 Inject the current timestamp into Device::{transmit,receive}.
Various parts of smoltcp require an arrow of time; a monotonically
increasing timestamp. Most obviously this is TCP sockets, but
the tracer and the pcap writer devices also benefit from having
timestamps. There are a few ways this could be implemented:
  1. using a static Cell, global for the entire smoltcp crate;
  2. using a static method on Device;
  3. using an instance method on Device;
  4. passing the current timestamp into *Interface::poll.

The first two options are undesirable because they create a notion
of global clock, and interfere e.g. with mocking.
The third option is undesirable because not all devices are
inherently tied to a particular clock, e.g. a loopback device isn't.

Therefore, the timestamp is injected into both sockets and devices
through the *Interface::poll method.
2017-07-23 09:48:14 +00:00
whitequark
7d54157e77 Add EthernetTracer, a specialization of Tracer for EthernetFrame.
This makes the loopback example much nicer, #[cfg]-wise.
2017-07-23 06:28:00 +00:00
whitequark
12f92be419 Use proper clock mocking in the loopback example. 2017-07-23 06:08:13 +00:00
whitequark
15ce667743 Add a bare-metal usage example. 2017-07-14 03:18:11 +00:00
whitequark
103fca2387 In examples, trace the packets being dropped by the fault injector. 2017-06-26 08:44:07 +00:00
whitequark
86c1cbad9b In examples, print packet dumps with timestamps, too.
This helps debugging retransmit issues.
2017-06-26 08:01:00 +00:00
whitequark
21900288cc Add packet shaping to the fault injector. 2017-05-29 10:53:30 +00:00
whitequark
a0f2c62ac9 Add a TCP client example. 2017-03-05 04:47:45 +00:00
whitequark
b88204c607 Factor out common code from examples. 2017-03-05 04:19:19 +00:00