Commit Graph

140 Commits (55c22b9865039dabf89c13fa09378157448add00)

Author SHA1 Message Date
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
qiujiangkun acfa7f0b19 use micros in Instant and Duration 2021-10-05 22:33:58 +02:00
Dario Nieuwenhuis b674f0d0ba phy: simplify PcapSink trait 2021-10-03 21:29:40 +02:00
Dario Nieuwenhuis 1ac34f34eb Fix redundant closure clippy 2021-06-27 10:43:05 +02:00
Dario Nieuwenhuis 98fe17890a rustfmt 2021-06-27 09:31:59 +02:00
Dario Nieuwenhuis 743f9de039 dhcp: address review comments. 2021-05-28 18:23:50 +02:00
Dario Nieuwenhuis a916888ab8 dhcp: add max_lease_duration option 2021-04-13 20:23:28 +02:00
Dario Nieuwenhuis 0d53163c55 dhcp: convert to socket 2021-04-07 19:00:36 +02:00
Dario Nieuwenhuis d64c8593f0 Add defmt logging support 2021-04-01 01:30:47 +02:00
Dario Nieuwenhuis 6e8c2a8455 Add IP medium support to PcapWriter and Tracer. 2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis 9e3b373e36 Add support for TUN interfaces. 2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis 9ac2cac075 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 f5f7037045 Remove unnecessary semicolon 2021-01-08 19:25:21 +01:00
Alex Crawford ea4579d68a 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 33236f23f4 Remove an unneeded semicolon 2020-12-28 23:20:01 -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 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 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01: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 7782b24427 Fix crash in server example due to returning length bigger than received buffer. 2020-04-16 07:39:11 +00:00
Jeremy Andrews bce8d13c7f replace the use of the deprecated item (#314) 2019-11-02 19:11:08 +00:00
whitequark be7750486f 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 04d1430fc9 Fix unused mut in examples/ping.rs. NFC. 2019-06-22 08:20:41 +00:00
whitequark 0134bb7399 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 49f638e2d2 Implement DHCPv4 client + example.
Closes: #186
Approved by: whitequark
2019-05-14 00:37:43 +08:00
Astro a8f2725784 Implement IGMPv1/v2 processing.
Closes: #178
Approved by: whitequark
2018-08-01 10:26:51 +08:00
whitequark 06c7e6eb54 examples: remove the remaining panics on poll error. 2018-07-31 13:58:00 +00:00
whitequark 5bcb358eb5 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 3e124ef482 Log and print error for all examples 2018-06-22 19:30:03 +00:00
Valentin Lorentz 728ae3fbb5 Add support for arbitrarily many routes instead of only gateways.
Closes: #219
Approved by: whitequark
2018-06-10 05:31:08 +08:00
Michal Podhradsky 6249f69bd9 Log and print poll errors instead of crashing the server
Closes: #228
Approved by: dlrobertson
2018-06-06 06:30:18 +08:00
Dan Robertson 3a3ac474f6 Fix server example
Make the IPv6 address used in the server example the same as the IPv6
address used in the others.

Closes: #217
Approved by: dlrobertson
2018-05-19 04:34:02 +08:00
Valentin Lorentz 2d716883b6 Add support for IPv6 gateways.
Closes: #207
Approved by: dlrobertson
2018-05-14 09:39:39 +08:00
Dan Robertson bed3d8bd4b Add Address Resolution for IPv6
Add Address Resolution via NDISC for IPv6.

Closes: #196
Approved by: whitequark
2018-05-07 23:49:56 +08:00
whitequark 485b46a5e6 fn PacketMetadata::empty() → const PacketMetadata::EMPTY.
Fixes #181.
2018-03-24 03:23:37 +00:00
whitequark b1f0011056 Fix an off-by-1000 in time display in examples/ping.rs. 2018-02-22 12:25:07 +00:00
whitequark 3d12690009 Use storage::PacketBuffer for implementing socket::IcmpSocket.
This substantially increases its space efficiency.
2018-02-22 12:23:35 +00:00
whitequark c474d0c32e Factor out storage::PacketBuffer from socket::UdpSocket. 2018-02-22 11:34:58 +00:00
Philipp Oppermann ed2dcaaff9 Use separate metadata and payload buffers for UDP sockets.
Co-authored-by: Dan Robertson <danlrobertson89@gmail.com>
2018-02-22 06:33:11 +00:00
Dan Robertson 9747733dd7 Use time types in socket
Use the time types (Instant and Duration) in the socket modules instead
of a simple u64.

Closes: #141
Approved by: whitequark
2018-02-16 10:44:03 +08:00
Dan Robertson e0b48caca3 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 20d1dd8a4a Update examples to use time types
Closes: #141
Approved by: whitequark
2018-02-16 10:44:02 +08:00
寧靜 96fd18ff8f Add missing #[cfg(feature = "phy-tap_interface")]. 2018-02-04 08:31:03 +00:00
寧靜 98679f9a1b Update examples/tcpdump.rs. 2017-12-28 04:48:23 +00:00
whitequark fb11c4a84d Convert the stress.rs example into a simple benchmark.
There are no more bugs exposed by stress.rs as far as I can tell,
so let's make it do something more useful.
2017-12-22 20:59:30 +00:00
whitequark f1a7fbe973 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 fec3bb32eb Make the log crate properly optional. 2017-12-22 09:57:38 +00:00
whitequark 5ea177e6ab 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 8863eb8db1 Add an HTTP client example. 2017-12-18 14:53:09 +00:00
Dan Robertson 4a98190f9b Replace EthernetInterface::new with EthernetInterfaceBuilder. 2017-12-18 13:29:29 +00:00