Commit Graph

147 Commits (master)

Author SHA1 Message Date
寧靜 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
whitequark 75e371d947 Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
whitequark ec74e34239 Fix clocking code in the loopback example. 2017-12-15 10:20:06 +00:00
whitequark eaa50d0003 Rewrite the ARP cache to allow for flood protection and expiration. 2017-11-21 10:53:55 +00:00
Dan Robertson adb5014780 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 c3e07dad9a Store plain DeviceT instead of Managed<_> in EthernetInterface 2017-11-08 09:34:35 +00:00
whitequark c2994b9757 Reimplement {RawSocket,TapInterface}::receive correctly. 2017-11-06 09:38:44 +00:00
Philipp Oppermann 6a8e21cec0 Redesign the phy::Device trait to avoid Drop impls. 2017-11-03 23:15:07 +00:00
whitequark fe6b04a29a 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 eef65d2676 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 19b1b764ed Implement a SocketRef smart pointer to detect state changes. 2017-10-05 03:44:20 +00:00
whitequark bf9584555c 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 5be76b8dc1 Add support for IPv4 default gateway. 2017-10-03 15:17:29 +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
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 42b3a71f72 Add a keep-alive and timeout demo to the examples. 2017-09-24 13:58:53 +00:00
whitequark cfcbcea4eb Fix an embarassing relative/absolute time mismatch in examples. 2017-09-24 13:57:35 +00:00
whitequark 9a5d056d7f Add a TCP data source endpoint to the server example. 2017-08-31 09:09:16 +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 699f5daa3e utils::Dispose → io::Sink. 2017-08-21 07:28:32 +00:00
whitequark 8724157b54 Fix warnings. 2017-07-31 07:59:01 +00:00
whitequark 7825bc6070 Implement fmt::Write for TcpSocket. 2017-07-30 06:59:01 +00:00
whitequark ae903e8841 Add UdpSocket::is_open, similar to TcpSocket::is_open in function.
Fixes #31.
2017-07-30 01:17:58 +00:00
whitequark ad12573f62 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 8a2432dcd7 Rework error handling in TcpSocket::connect. 2017-07-27 12:27:33 +00:00
whitequark 38afc64f61 Accept TCP FIN packets in SYN-RECEIVED state. 2017-07-23 23:51:56 +00:00
whitequark ab4593ea6c Fix double tracing in the loopback example. 2017-07-23 23:18:37 +00:00
whitequark 1c41f2d7fa 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 7ba49607bf Update fault injector so that rate limiting works without std. 2017-07-23 15:10:57 +00:00
whitequark a89e57b128 Add --pcap option to all our examples.
Also, generally reorganize and clean up option handling.
2017-07-23 14:57:04 +00:00
whitequark e381f6ec3f Fix an off-by-three-orders-of-magnitude error. 2017-07-23 12:03:56 +00:00
whitequark cf37a34443 Fix argument order in Tracer::new callbacks. 2017-07-23 12:01:53 +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 6dd833f1f7 Use proper clock mocking in the loopback example. 2017-07-23 06:08:13 +00:00
whitequark 75ddbe9776 Add a bare-metal usage example. 2017-07-14 03:18:11 +00:00
whitequark 62c9b7d6fa In examples, trace the packets being dropped by the fault injector. 2017-06-26 08:44:07 +00:00
whitequark 02abd7a983 In examples, print packet dumps with timestamps, too.
This helps debugging retransmit issues.
2017-06-26 08:01:00 +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
Egor Karavaev 8d7fa94a6d Add the `ping` example. 2017-06-21 03:51:02 +00:00
whitequark 53be7a7747 Add a sinkhole to the server example. 2017-05-29 16:54:51 +00:00
whitequark 91ef5c60c3 Add packet shaping to the fault injector. 2017-05-29 10:53:30 +00:00
whitequark ae89abe0a4 Update README to explain how the client example works. 2017-03-05 06:15:15 +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 f49723bbf9 Add a TCP client example. 2017-03-05 04:47:45 +00:00
whitequark d20c98f870 Factor out common code from examples. 2017-03-05 04:19:19 +00:00
TÖRÖK Attila 4d8b4c09e9 examples/server: fix outdated/misleading variable name. 2017-01-26 16:59:12 +00:00
whitequark 8b04d8bebe Try to get TCP state query methods into a saner state. 2017-01-14 09:13:25 +00:00
whitequark cca835a45a Update TcpSocket::{can,may}_{send,recv} APIs. 2017-01-14 06:59:58 +00:00
whitequark 4b92c25fa3 Rework the user-facing error handling in UDP sockets. 2017-01-12 04:18:18 +00:00
whitequark 7f095f6429 Return the amount of bytes sent from UdpSocket::send_slice. 2017-01-11 06:39:27 +00:00
whitequark 3b18727032 Swap the data and endpoint in UdpSocket methods.
This is to match libstd.
2017-01-11 06:23:17 +00:00
whitequark 362c954624 Make interfaces not own the sockets. 2017-01-11 05:25:54 +00:00
whitequark 83b70b12af Make binding the UDP socket an explicit operation. 2017-01-11 04:44:42 +00:00
whitequark 234e5ef29e Implement socket sets. 2017-01-11 04:05:41 +00:00
whitequark 0e006383f2 Use Managed/ManagedSlice for EthernetInterface. 2017-01-10 11:37:12 +00:00
whitequark 08ac98e4bc Reorder type parameters of Interface. 2017-01-01 08:18:25 +00:00
whitequark 27ccfc1bb0 Implement TCP retransmission. 2016-12-31 08:35:46 +00:00
whitequark e1e0c2e838 Impement fault injection. 2016-12-31 01:05:29 +00:00
whitequark 287affb447 Implement the TCP TIME-WAIT state. 2016-12-28 05:33:12 +00:00
whitequark 22b0406c59 More sensible naming for examples. 2016-12-28 00:18:10 +00:00
whitequark 979cd4c1bf Implement the TCP LAST-ACK state. 2016-12-27 23:27:33 +00:00
whitequark 874264503d Implement the TCP close operation. 2016-12-27 22:43:16 +00:00
whitequark 71d1b4061f Fix ACK validation of TCP RST packets. 2016-12-27 20:17:35 +00:00
whitequark 69427c9e2f Add TcpSocket::is_connected(). 2016-12-27 18:54:45 +00:00
whitequark bbff907e87 Fix examples. 2016-12-27 18:04:39 +00:00
whitequark 751a2269c3 Add support for TCP FIN in ESTABLISHED state. 2016-12-27 13:34:48 +00:00
whitequark 3917ba5836 Shrink the buffers in examples for ease of testing. 2016-12-26 16:29:33 +00:00
whitequark d7e73a36f0 Add some colors for readability. 2016-12-26 15:46:36 +00:00
whitequark a8b4ed2deb Implement the userspace side of TCP sockets. 2016-12-26 15:05:46 +00:00
whitequark 3c05139204 Add logging capability. 2016-12-23 07:59:38 +00:00
whitequark 6539019f19 Get rid of explicit backlog. 2016-12-23 07:34:10 +00:00
whitequark 1ad8f9c9bd Implement conversion of incoming TCP connections into TCP streams. 2016-12-20 22:57:21 +00:00
whitequark bddb5f9127 Implement TCP server sockets. 2016-12-20 19:51:52 +00:00
whitequark 5a64a87dbe Reply with ICMP dest. unreachable or TCP RST from unused ports. 2016-12-20 19:18:35 +00:00
whitequark a3481537d9 Add some sanity into buffer names (avoid clases with wire::*). 2016-12-20 13:56:59 +00:00
whitequark 0d9a8a417d Add some sanity into enumeration names (avoid "*Type"). 2016-12-20 13:54:11 +00:00
whitequark 77b2819691 Fix a pointless crash in smoltcpserver. 2016-12-20 00:17:49 +00:00
whitequark fe96ff3015 UdpBufferElem → UdpPacket 2016-12-18 19:40:02 +00:00
whitequark 31e44445f5 Working UDP loopback. 2016-12-17 05:12:45 +00:00
whitequark c672b94ef7 Rethink the buffering strategy with Managed<T>. 2016-12-17 04:15:55 +00:00
whitequark d1d910b46d Significantly simplify buffering. 2016-12-15 17:27:17 +00:00
whitequark 3fb5f04b07 Implement network part of communication through UDP sockets. 2016-12-15 05:40:55 +00:00
whitequark 2b01a3dace Implement UDP representation parsing and emission. 2016-12-14 02:11:50 +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 2a438b6e8d Factor out pretty-printing of packets. 2016-12-11 00:48:44 +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
whitequark b1149e746c Implement raw socket interface and tcpdump. 2016-12-10 16:58:30 +00:00