97 Commits

Author SHA1 Message Date
寧靜
d1ac62c2a2 Update examples/tcpdump.rs. 2017-12-28 04:48:23 +00:00
whitequark
ba1d5ed576 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
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
d5f11159d8 Make the log crate properly optional. 2017-12-22 09:57:38 +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
a7d289eac1 Add an HTTP client example. 2017-12-18 14:53:09 +00:00
Dan Robertson
ad56bacb56 Replace EthernetInterface::new with EthernetInterfaceBuilder. 2017-12-18 13:29:29 +00:00
whitequark
b1680368fe Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
whitequark
fe94691562 Fix clocking code in the loopback example. 2017-12-15 10:20:06 +00:00
whitequark
34c3a8c905 Rewrite the ARP cache to allow for flood protection and expiration. 2017-11-21 10:53:55 +00:00
Dan Robertson
ef4af850e0 Add ICMP sockets
- Add support for ICMP sockets
 - Add tests for ICMP sockets
 - Rename proto-<type> features to socket-<type>
 - Update documentation
2017-11-09 00:08:24 +00:00
Philipp Oppermann
4ae84ab36a Store plain DeviceT instead of Managed<_> in EthernetInterface 2017-11-08 09:34:35 +00:00
whitequark
f239e36bf3 Reimplement {RawSocket,TapInterface}::receive correctly. 2017-11-06 09:38:44 +00:00
Philipp Oppermann
198fe239f1 Redesign the phy::Device trait to avoid Drop impls. 2017-11-03 23:15:07 +00:00
whitequark
0091191cce Rework TcpSocket::{send,recv} to remove need for precomputing size.
Now, these functions give you the largest contiguous slice they can
grab, and you return however much you took from it.
2017-10-31 19:24:54 +00:00
Dan Robertson
fea462837d Implement set_ttl for Tcp and Udp sockets
- Add the ttl member to the IpRepr
 - Add the ttl member along with setters and getters to the tcp and udp
   socket types
 - Add unit tests for the new set_ttl parameter
 - Update usage of IpRepr to include the ttl value
2017-10-24 23:02:18 +00:00
Egor Karavaev
096ce02ac4 Implement a SocketRef smart pointer to detect state changes. 2017-10-05 03:44:20 +00:00
whitequark
d88ef3c8d3 Drop the pretense that anyone cares about non-IP over Ethernet.
To be precise, I'm talking about IPX, AppleTalk and DECnet here,
not things like PPPoE, ATAoE, FCoE, or PTP, which make sense
to implement on top of EthernetInterface but do not work on
the same level on top of it as IP.
2017-10-03 15:17:29 +00:00
Egor Karavaev
331dc10780 Add support for IPv4 default gateway. 2017-10-03 15:17:29 +00:00
Steffen Butzer
d5147efb82 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
whitequark
16e6e70d2f Fix many warnings. 2017-09-25 00:55:54 +00:00
whitequark
cedf66a733 Enforce some lints. 2017-09-25 00:46:53 +00:00
whitequark
6f5ae33501 Add a keep-alive and timeout demo to the examples. 2017-09-24 13:58:53 +00:00
whitequark
b7b4877a85 Fix an embarassing relative/absolute time mismatch in examples. 2017-09-24 13:57:35 +00:00
whitequark
49ed4ae5f3 Add a TCP data source endpoint to the server example. 2017-08-31 09:09:16 +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
7533542ba8 Fix warnings. 2017-07-31 07:59:01 +00:00
whitequark
6bc6cc7af7 Implement fmt::Write for TcpSocket. 2017-07-30 06:59:01 +00:00
whitequark
265e6f6cb7 Add UdpSocket::is_open, similar to TcpSocket::is_open in function.
Fixes #31.
2017-07-30 01:17:58 +00:00
whitequark
492fe3e4b1 Rework and test UDP sockets.
Before, errors such as packets not fitting into a buffer would have
resulted in panics, and errors such as unbound sockets were
simply ignored.
2017-07-27 22:30:01 +00:00
whitequark
53a3875452 Rework error handling in TcpSocket::connect. 2017-07-27 12:27:33 +00:00
whitequark
b971d91315 Accept TCP FIN packets in SYN-RECEIVED state. 2017-07-23 23:51:56 +00:00
whitequark
abb0c11b95 Fix double tracing in the loopback example. 2017-07-23 23:18:37 +00:00
whitequark
0904645c1b Fix determination of local address from incoming packets.
We've advertised this capability before in examples, but it did not
actually work.
2017-07-23 23:07:55 +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
735def7e1b 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
Egor Karavaev
78b717cd75 Add the ping example. 2017-06-21 03:51:02 +00:00
whitequark
961b12ce93 Add a sinkhole to the server example. 2017-05-29 16:54:51 +00:00
whitequark
21900288cc Add packet shaping to the fault injector. 2017-05-29 10:53:30 +00:00
whitequark
ddba30e9cf Update README to explain how the client example works. 2017-03-05 06:15:15 +00:00