Commit Graph

112 Commits

Author SHA1 Message Date
whitequark d4fa764b23 Add the packet2pcap utility. 2018-01-30 03:24:50 +00:00
寧靜 1e5acf0799 Gate Linux-specific platform dependencies behind a #[cfg]. 2018-01-27 12:38:47 +00:00
Dan Robertson eb33e7f09f Add ICMPv6
Add support for ICMPv6 message types to the wire module.
2018-01-26 23:10:41 +00:00
Dan Robertson b653a6e421 Fix documentation warnings.
- There are several warnings that are thrown when running `cargo doc`. Fix
  these warnings.
- Convert all module documentation to use /*! for consistency.
2018-01-05 19:38:23 +00:00
whitequark b2c2214725 Convert all assert!s not documented as panics into debug_assert!s.
Document the rest.
2017-12-22 20:38:54 +00:00
whitequark ff530020dd Style. NFC. 2017-11-22 07:44:03 +00:00
whitequark c2994b9757 Reimplement {RawSocket,TapInterface}::receive correctly. 2017-11-06 09:38:44 +00:00
whitequark 9e783cb570 Add CODE_STYLE.md. 2017-11-03 23:34:12 +00:00
Philipp Oppermann 6a8e21cec0 Redesign the phy::Device trait to avoid Drop impls. 2017-11-03 23:15:07 +00:00
whitequark 3fa1d60be0 Only verify checksum in pretty printers, do not bail out if invalid.
This lets us e.g. deal with checksum offload on egress packets.
2017-10-03 07:09:53 +00:00
whitequark f60e689b04 Reword checksum-related documentations.
cc @steffengy
2017-10-02 21:52:30 +00:00
Steffen Butzer 61cb64406d support hardware based checksum settings in during packet send/recv
- makes sure the checksum is zeroed when not emitted by software
  (This is required by some implementations such as STM32 to work properly)
2017-10-02 21:40:08 +00:00
Steffen Butzer f9093d15aa phy: introduce hardware based checksum settings, rename DeviceLimits
this contains a rename of occurrences of
DeviceLimits -> DeviceCapabilities.
2017-10-02 21:40:08 +00:00
whitequark ba93552ccd Fix many warnings. 2017-09-25 00:55:54 +00:00
whitequark dd0f4b706a Enforce some lints. 2017-09-25 00:46:53 +00:00
whitequark 0a8a962e94 Reorganize features using namespaces, to match module hierarchy.
I'm about to add a whole lot more features, and it's going to get
quite confusing otherwise.
2017-09-24 23:51:19 +00:00
whitequark 8e13333988 Remove all remnants of the collections feature. 2017-09-22 20:40:13 +00:00
whitequark f8edf0faea Unbreak traffic shaper in the fault injector. 2017-08-31 21:39:01 +00:00
whitequark 6da3e5f217 Fix an inaccurate comment. 2017-08-31 14:33:10 +00:00
whitequark 47770a5ec2 Fix an unused import warning. 2017-08-31 14:31:32 +00:00
whitequark 996389d653 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 ae7e956573 Add a missing \0 in a C string. 2017-08-24 12:18:07 +00:00
whitequark 15085bd8ba Fix a file descriptor leak in TapInterfaceDesc::interface_mtu. 2017-08-21 07:28:32 +00:00
David Coffill 55ac6737b2 Fix build on i686 by using libc::suseseconds_t instead of i64 2017-08-02 07:12:36 +00:00
whitequark be0854127a Remove unused imports. 2017-07-30 01:09:14 +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 7ba49607bf Update fault injector so that rate limiting works without std. 2017-07-23 15:10:57 +00:00
whitequark 250a84e513 Implement a Device that emits a stream in libpcap format. 2017-07-23 14:56:24 +00:00
whitequark a9e6b49aa6 Rename into_lower → into_inner. 2017-07-23 10:20:05 +00:00
whitequark aeba4f9bc6 Clean up some type variable names and trait bounds. NFC. 2017-07-23 10:15:56 +00:00
whitequark b97cacd521 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 eae7907f60 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 051169a49d Determine MTU in TapInterface instead of hardcoding 1536. 2017-07-23 04:40:35 +00:00
whitequark 94796a566b Document the loopback. 2017-07-14 03:30:00 +00:00
whitequark 312ff93c86 Remove default impl for Device::limits().
We should not assume any default MTU.
2017-07-14 03:18:11 +00:00
whitequark f3e54966fd LoopbackInterface → Loopback. 2017-07-14 01:17:06 +00:00
whitequark 63ab7d4e7a Implement loopback interfaces.
This also adds a default implementation of Device::limits.
2017-07-14 01:14:40 +00:00
whitequark 74823b0dff try! → ? 2017-06-24 16:34:32 +00:00
whitequark cc5fb0e5ef Clean up a few doctests. 2017-06-24 09:02:12 +00:00
Egor Karavaev 59fc0c0358 Factor out the "raw_socket" and "tap_interface" features
This makes it possible to build smoltcp with the "std" feature on platforms
without libc, such as redox.
2017-06-15 10:12:11 +00:00
whitequark 5bac3e5a02 Fix no-std build. 2017-05-29 11:04:49 +00:00
whitequark 91ef5c60c3 Add packet shaping to the fault injector. 2017-05-29 10:53:30 +00:00
whitequark 1d46ccf432 fn Device::mtu() -> usize → Device::limits() -> DeviceLimits 2017-03-07 11:10:26 +00:00
whitequark 493a319132 Remove the `use_` prefix from feature names.
I haven't realized that a feature `log` with an optional crate
dependency `log` activates that dependency, and added the prefix
to avoid a "clash". This is unnecessary.
2017-03-05 05:49:38 +00:00
whitequark cc67e1f753 Don't block forever in TapInterface.
Ideally Devices should be non-blocking, but that would be really
annoying to implement, so for now, to get the examples working,
I'm using this hack.
2017-03-05 05:30:03 +00:00
whitequark 83bb8c6ae8 Update docs. 2017-01-10 12:29:24 +00:00
whitequark 716a1cf7fe Fix silliness in docs. 2017-01-01 08:15:38 +00:00
whitequark bf3b62bb25 Examples for the phy layer! 2016-12-31 12:28:59 +00:00
whitequark 818e98f47a TCP: retransmit ACK when receiving duplicate SEQ. 2016-12-31 01:33:46 +00:00
whitequark 64a8c36118 Fix length of tx buffers returned by fault injector. 2016-12-31 01:10:46 +00:00
whitequark e1e0c2e838 Impement fault injection. 2016-12-31 01:05:29 +00:00
whitequark 3ea9606827 Remove an unnecessary PhantomData. 2016-12-30 23:48:37 +00:00
whitequark de24d635fa Rename features: std→use_std, logging→use_log. 2016-12-27 23:45:24 +00:00
whitequark a6eab874be Parameterize tracer over the write function. 2016-12-26 15:46:30 +00:00
whitequark f86fac2223 Sort out buffer lengths. 2016-12-19 23:50:04 +00:00
whitequark fb172ed1ed Implement UDP sockets. 2016-12-14 17:39:44 +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 e7d6237279 Implement TAP interface support. 2016-12-11 00:30:40 +00:00
whitequark fb3faa9d28 Implement a trait for sending and receiving frames. 2016-12-10 19:27:07 +00:00
whitequark 683652a9a6 smoltcp::interface → smoltcp::phy. 2016-12-10 18:33:19 +00:00