Commit Graph

38 Commits (88256dbdcfc3b284f5533e5aa2969bf5061db22a)

Author SHA1 Message Date
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +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
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
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
Andrew Cann cc8f45df40 Add EthernetRepr type 2018-03-11 18:17:20 +00:00
Andrew Cann cf53106208 Add Clone impl to EthernetFrame
Closes: #163
Approved by: whitequark
2018-02-16 07:47:24 +08:00
Andrew Cann 6ee9516697 impl `AsRef<[u8]>` for packet types
Closes: #158
Approved by: whitequark
2018-02-08 17:05:46 +08:00
Andrew Cann 1b308a439e Relax type constraints on payload_mut methods
Closes: #153
Approved by: whitequark
2018-02-06 16:17:15 +08:00
寧靜 57f9bc213d Impl `Hash` trait on EthernetAddress. 2018-02-03 01:17:15 +00:00
Dan Robertson 439e0a2cc1 Add the proto-ipv4 feature. 2017-12-24 13:28:59 +00:00
Dan Robertson c5c2264cdc Use hop limit instead of ttl
Use hop limit instead of ttl for method and member names.
2017-12-18 13:47:34 +00:00
Dan Robertson ee60efefd3 Add Ipv6Repr and Ipv6Packet to wire
- Add the Ipv6Repr and Ipv6Packet structures to the wire module
 - Add basic tests for the new structures
 - Update IpRepr to include the Ipv6 variant
2017-12-18 13:47:34 +00:00
whitequark 75e371d947 Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
whitequark 38f648affb Add some docs. 2017-09-24 23:29:42 +00:00
Egor Karavaev 0e88617b82 Uncomment associated constants. 2017-09-24 23:25:18 +00:00
whitequark 8d8a4ea583 Get rid of Result<_, ()>.
The use of this type has several drawbacks:
  * It does not allow distinguishing between different error
    conditions. In fact, we wrongly conflated some of them
    before this commit.
  * It does not allow propagation via ? and requires manual use
    of map_err, which is especially tiresome for downstream code.
  * It prevents us from expanding the set of error conditions
    even if right now we have only one.
  * It prevents us from blanket using Result<T> everywhere
    (a nitpick at most).

Instead, use Result<T, Error> everywhere, and differentiate error
conditions where applicable.
2017-07-27 13:55:47 +00:00
whitequark 0f0c545755 Make sure representation emission covers every octet of the buffer.
Also fix a bug where TcpRepr::emit would not clear the urgent
pointer.
2017-06-26 03:44:36 +00:00
whitequark 74823b0dff try! → ? 2017-06-24 16:34:32 +00:00
whitequark 8b27330c8b Do not attempt to validate length of packets being emitted.
This is a form of an uninitialized read bug; although safe it caused
panics. In short, transmit buffers received from the network stack
should be considered uninitialized (in practice they will often
contain previously transmitted packets or parts thereof). Wrapping
them with the only method we had (e.g. Ipv4Packet) treated the buffer
as if it contained a valid incoming packet, which can easily fail
with Error::Truncated.

This commit splits every `fn new(buffer: T) -> Result<Self, Error>`
method on a `Packet` into three smaller ones:
  * `fn check_len(&self) -> Result<(), Error>`, purely a validator;
  * `fn new(T) -> Self`, purely a wrapper;
  * `fn new_checked(T) -> Result<Self, Error>`, a validating wrapper.

This makes it easy to process ingress packets (using `new_checked`),
egress packets (using `new`), and, if needed, maintain the invariants
at any point during packet construction (using `check_len`).

Fixes #17.
2017-06-24 11:42:32 +00:00
whitequark 393ebbe682 Don't put non-unicast (IP or Ethernet) addresses into ARP cache.
Thanks @little-dude for pointing this out--it's probably a DoS bug.
2017-03-07 06:32:18 +00:00
whitequark 5137608aed Follow-up to b9e79d19; always process broadcast frames. 2017-03-06 04:00:13 +00:00
whitequark bc1d65ea89 Send the TCP MSS option. 2017-01-27 02:56:27 +00:00
whitequark be68066152 #[inline(always)] → #[inline] 2016-12-30 16:55:31 +00:00
whitequark 151b3ba07b Get rid of the #![feature(associated_consts)]. 2016-12-28 00:12:15 +00:00
whitequark 5a64a87dbe Reply with ICMP dest. unreachable or TCP RST from unused ports. 2016-12-20 19:18:35 +00:00
whitequark f86fac2223 Sort out buffer lengths. 2016-12-19 23:50:04 +00:00
whitequark 5a721a7b11 Implement UDP packet support. 2016-12-14 00:11:45 +00:00
whitequark 57e544cc8c Return interior pointers more uniformly. 2016-12-13 22:37:05 +00:00
whitequark 1c616218a1 Respond with ICMP echo request data in echo reply. 2016-12-13 17:02:50 +00:00
whitequark c5bdf30458 Implement IPv4 representation parsing and emission. 2016-12-12 20:09:37 +00:00
whitequark 921ca353b4 Implement IPv4 packet support. 2016-12-12 17:26:06 +00:00
whitequark 7f1b88ef45 Implement ARP snooping. 2016-12-12 12:30:35 +00:00
whitequark 4421b2fe27 Implement ARP replies. 2016-12-12 07:19:53 +00:00
whitequark d862512582 Implement an ARP LRU cache. 2016-12-12 02:39:46 +00:00
whitequark 2a438b6e8d Factor out pretty-printing of packets. 2016-12-11 00:48:44 +00:00
whitequark 77225b77a9 Fix tests. 2016-12-11 00:30:40 +00:00
whitequark b1149e746c Implement raw socket interface and tcpdump. 2016-12-10 16:58:30 +00:00
whitequark 32ff49a795 Move protocol-related data structures to smoltcp::wire. 2016-12-10 13:13:13 +00:00