Commit Graph

623 Commits

Author SHA1 Message Date
Dan Robertson 826ba29b72 Add has_solicited_node to EthernetInterface
- Add a function to EthernetInterface useful for determining if a
   received packet with the source address being a solicited node
   address is the solicited node address for an IPv6 address assigned
   to the interface.
 - Add SOLICITED_NODES_PREFIX to Ipv6Cidr
 - Fix some nits

Closes: #175
Approved by: whitequark
2018-03-04 03:23:12 +08:00
Astro e3e9d9d4c5 Allow broadcast/multicast traffic to UDP sockets
Closes: #173
Approved by: whitequark
2018-03-03 06:16:40 +08:00
Astro cd00d63c51 Add multicast capability to lookup_hardware_addr()
Closes: #172
Approved by: whitequark
2018-03-02 08:33:37 +08:00
Astro 8a862f4dbe Add as_bytes(), is_multicast() to IpAddress
Closes: #172
Approved by: whitequark
2018-03-02 08:33:37 +08:00
Dan Robertson 95991d8625 Remove trailing whitespace
Closes: #171
Approved by: whitequark
2018-02-26 23:17:40 +08: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 9353c37a62 Use storage::PacketBuffer for implementing socket::RawSocket.
This substantially increases its space efficiency.
2018-02-22 12:05:36 +00:00
whitequark 41de9c7ee0 Distinguish PacketBuffer running out of payload space and capacity.
This makes the behavior of UdpSocket resemble that of RawSocket.
2018-02-22 11:57:39 +00:00
whitequark c474d0c32e Factor out storage::PacketBuffer from socket::UdpSocket. 2018-02-22 11:34:58 +00:00
Herman J. Radtke III 8c9fc02f1d Add IPv6 Extension Fragment Header
Closes: #168
Approved by: whitequark
2018-02-22 15:19:18 +08: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
Herman J. Radtke III 785637957c Add IPv6 Extension Hop-by-Hop Options Header
Closes: #139
Approved by: whitequark
2018-02-18 06:30:21 +08: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 1f9e14de71 Update iface and phy_wait to use new time types
Update the EthernetInterface poll functions to use Instant and Duration
instead of a simple u64 value.

Closes: #141
Approved by: whitequark
2018-02-16 10:44:02 +08:00
Dan Robertson 8b0ab0dc94 time: Improve time types
- Correct from_system_time implementation
 - Add missing functions and implementations to Instant type
 - Add missing frnction to Duration type

Closes: #141
Approved by: whitequark
2018-02-16 10:44:02 +08:00
Andrew Cann cf53106208 Add Clone impl to EthernetFrame
Closes: #163
Approved by: whitequark
2018-02-16 07:47:24 +08:00
Andrew Cann ec4c48af6c Add `PrettyPrinter::print` convenience method
Closes: #165
Approved by: whitequark
2018-02-16 00:09:52 +08:00
Dan Robertson 1097ba3110 Documentation updates
- Update documentation about current support in the wire module
 - Ensure the possible panic is documented for Ipv6Option::data_mut
 - Add a Repr structure for Ethernet II headers
2018-02-14 18:00:19 +00:00
Andrew Cann 6ee9516697 impl `AsRef<[u8]>` for packet types
Closes: #158
Approved by: whitequark
2018-02-08 17:05:46 +08:00
Dan Robertson 9abf54d56e Add tests for ipv6 in wire::ip
- Make a macro to generate the current tests.
 - Generate the tests for all versions that are enabled.

Closes: #155
Approved by: whitequark
2018-02-08 14:45:19 +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
Dan Robertson e09e20df95 Add basic ICMPv6 reply
Add basic ICMPv6 handling

 - ICMPv6
   - Handle ICMPv6 echo requests
   - Send ICMPv6 error messages
     - When know listening UDP socket is found in process_udp
     - When the next header is not known
   - Update icmpv6 test to be more useful
 - ICMPv4
   - Handle one more case where we are sending too much data
2018-02-05 16:24:25 +00:00
寧靜 49afb3a45a Add from_netmask()/netmask()/broadcast()/network() methods on IPv4Cidr 2018-02-05 15:13:52 +00:00
Dan Robertson c3d5790c8e Improve TimeExceeded and ParamProblem support
- Improve TimeExceeded support
   - Add support for message codes
   - Add the TimeExceeded enum type
 - Improve ParamProblem support
   - Add support for message codes
   - Add the ParamProblem enem type

Closes: #152
Approved by: whitequark
2018-02-05 22:55:04 +08:00
Andrew Cann 01f3b53e70 Add Clone impl to Packet types 2018-02-05 14:34:36 +00:00
Andrew Cann a9fc8c225b Add conversions to/from std wire types 2018-02-05 13:23:25 +00:00
寧靜 57f9bc213d Impl `Hash` trait on EthernetAddress. 2018-02-03 01:17:15 +00:00
whitequark 5fec38bad3 Remove internally inconsistent test that was left in 1d2ec8c. 2018-02-01 01:04:13 +00:00
whitequark 3bf64a32fb Remove length check that is redundant after 181083f1. 2018-02-01 00:27:49 +00:00
Herman J. Radtke III 4e88b1f82f Implement IPv6 Extension Headers Pad1 and PadN. 2018-01-30 19:45:25 +00:00
whitequark 8b6d8d7fce Reject certain malformed IPv4 packets.
Reported independently, but testcase found via cargo-fuzz.
2018-01-30 03:24:50 +00:00
whitequark d4fa764b23 Add the packet2pcap utility. 2018-01-30 03:24:50 +00:00
Philipp Oppermann 6b3f103c05 Return specific sockets from `new` functions instead of `Socket`.
* Add Into<Socket> implementations for sockets
* Make SocketSet::add generic over Into<Socket>
2018-01-28 14:36:23 +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
Egor Karavaev 864b4b7996 Treat unspecified IPv4/IPv6 addresses as IpAddress::Unspecified in IpRepr::lower.
Closes #127.
2018-01-26 19:26:01 +00:00
Dan Robertson 7778626788 Fix ICMPv4 check_len to not panic on truncated packets. 2018-01-26 18:59:11 +00:00
whitequark a65daade16 Fix some overly long comments. NFC. 2018-01-26 17:48:59 +00:00
Dan Robertson b017a16e98 Increase required size for ICMPv4 packets
- Increase the size required in Icmpv4Packet::check_len to 8 bytes
 - Add a test
2018-01-26 16:59:37 +00:00
luozijun b5646f1e98 Add `Hash` trait on `IpAddress/IpCidr` 2018-01-26 16:35:53 +00:00
whitequark 0ddd4c9001 Route broadcast packets directly.
Closes #120.
2018-01-15 11:56:14 +00:00
Dan Robertson 4a78b02fcf Add process_ipv6 to EthernetInterface
- Add `process_ipv6` to `EthernetInterface`
 - Add basic test for `process_ipv6`
 - Add `deny(unused)` if either proto-ipv4 or proto-ipv6 is enabled
 - Add `cfg`s where needed to avoid compile time errors due to the above
2018-01-15 11:54:26 +00:00
Dan Robertson 7edb7ee93d Implement the time module. 2018-01-13 14:51:21 +00:00
Herman J. Radtke III 2419147b45 Handle parsing and display of IPv4 mapped IPv6 addresses.
* The IPv6 address parser now handles IPv4 mapped IPv6 addresses which
  take on the form ::ffff:x.x.x.x.
* Implement Display for IPv4 mapped IPv6 addresses
* Implement From<IPv4Address> for IPv6Address

Fixes #86
2018-01-13 08:49:24 +00:00
Dan Robertson 6fd5ed8aaf Support IPv6 raw sockets
- Add support for IPv6 raw sockets.
 - Update tests.
2018-01-13 03:07:10 +00:00
Alex Crawford 066d42c0e0 Clean up dispatch_socket!() syntax
This modified syntax is meant to more closely resemble standard Rust.
2018-01-08 07:44:15 +00:00
whitequark f494200c8c Disregard TCP FIN flag if it arrives in a segment not at window start.
Fixes #111.
2018-01-05 21:06:20 +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
Dan Robertson 22b048c225 Ensure ICMPv4 error replies comply with size requirements
- Add MIN_MTU constants to the IP version modules.
 - Ensure that ICMPv4 error replies comply with the size requirements
   specified in RFC 1812 § 4.3.2.3.
2018-01-05 19:21:45 +00:00
whitequark 7c0bae7d36 Simplify. NFC. 2017-12-27 00:09:50 +00:00
Dan Robertson 439e0a2cc1 Add the proto-ipv4 feature. 2017-12-24 13:28:59 +00:00
Herman J. Radtke III 260e3d996f Implement FromStr for IpEndpoint
Fixes #81
2017-12-24 12:08:16 +00:00
Josh Gangloff fe3e67d544 Make IP checksum loop use larger chunks to ease autovectorization. 2017-12-23 22:26:16 +00:00
whitequark d8685dbb1e Unswitch the IP checksum loop for 30% improvement in performance. 2017-12-23 12:17:39 +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 436f4ef624 Correctly handle retransmission of lost-received-lost TCP segments.
Thanks @pothos for initial analysis of the issue.
2017-12-22 19:31:04 +00:00
whitequark ae17151f2a Fix a few documentation issues. NFC. 2017-12-22 13:13:43 +00:00
whitequark a45b3d9eab TcpSocket::recv_impl should have never been public, oops. 2017-12-22 13:11:11 +00:00
whitequark 85487bf3bc EthernetInterface::set_ipv4_gateway should panic on non-unicast addrs. 2017-12-22 13:07:11 +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 8b6050f711 Clean up our feature story and more aggressively test features. 2017-12-22 08:54:58 +00:00
whitequark 3029341d5a Panic on an attempt of subtracting sequence numbers with underflow.
This would result in results near usize::MAX, and is indicative of
a bug. A panic is always used instead of a debug_assert!() because
debug builds are easily slow enough so that the underlying bugs
are not tripped.

Related to #62.
2017-12-21 12:35:15 +00:00
whitequark bd40265d3a Use a more specific log message for keep-alive or probe TCP packets. 2017-12-21 10:39:54 +00:00
whitequark bf53b73e09 Fix accidental conversion of a slice to owned.
This broke #![no_std] builds.
2017-12-18 15:03:38 +00:00
whitequark 946376897e Make EthernetInterfaceBuilder::ip_addrs optional.
It's perfectly reasonable to have an interface with no addresses
assigned to it.
2017-12-18 13:53:27 +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
Dan Robertson 4a98190f9b Replace EthernetInterface::new with EthernetInterfaceBuilder. 2017-12-18 13:29:29 +00:00
whitequark 278bb4b2c9 Trace the TCP socket acknowledging incoming segment. 2017-12-18 12:47:42 +00:00
whitequark 05677dbd76 Fix 14185a16. 2017-12-18 11:42:55 +00:00
whitequark 19f52bd46c Do not fill neighbor cache with IPs not on the same network as us.
This is pointless (`route` doesn't even check the cache in that case)
and wastes cache space.
2017-12-18 11:06:26 +00:00
whitequark 8dd9bdeaad Trace neighbor discovery status on a per-socket basis.
This avoids delaying the first packets for new neighbors by
(at least) the ARP cache silence time, or potentially even
indefinitely.
2017-12-18 11:06:24 +00:00
whitequark 16b59eefad Style. NFC. 2017-12-16 21:45:24 +00:00
whitequark 75e371d947 Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
whitequark c19bd1da7c Make elaborated reasons for sending a TCP packet more precise. 2017-12-15 06:31:50 +00:00
whitequark 1c7ce85004 Log an elaborated reason for sending a TCP packet.
Otherwise, it is hard to debug e.g. ACK loops.
2017-12-15 05:24:17 +00:00
Dan Robertson 888b098dca Process the Icmpv4Repr in IcmpSocket::process
- Use the Icmpv4Repr in IcmpSocket::process instead of the raw payload.
 - Update the IcmpSocket tests.
2017-12-09 00:10:09 +00:00
whitequark 26b8052ee9 Make packet dumps emitted for broken packets more useful.
Before this commit, only the outermost frame (the Ethernet one)
would be shown, which is really no help at all.
2017-12-08 07:11:08 +00:00
Dan Robertson be43f4067a Minor doc improvements to wire::ipv6
- Add links to the Addressing Achitecture RFC where appropriate
 - Add comments to functions where appropriate
2017-11-30 19:20:42 +00:00
Dan Robertson b97c592671 Add IPv6 address and cidr to wire
- Add the ipv6 feature
   - Ensure a travis build with the ipv6 feature enabled.
 - Add the necessary infrastructure to wire for ipv6 support.
   - Ipv6Address
   - Ipv6Cidr
 - Add Ipv6 Address and Cidr parsing to parsers
 - Add basic tests.
2017-11-29 12:57:22 +00:00
Jeremy Soller 8604eaa8f9 Allow receiving broadcast packets via UDP sockets. 2017-11-23 07:01:35 +00:00
Dan Robertson 308afc5a25 Remove debug println in test_evict
The println's surrounding the final cache fill in test_evict that causes
PADDR_B to be evicted are not needed.
2017-11-22 08:03:39 +00:00
whitequark ff530020dd Style. NFC. 2017-11-22 07:44:03 +00:00
whitequark 98a3ec8c3a Limit the rate at which sockets will request neighbor discovery.
The rate of emission of neighbor discovery packets is already
limited at the level of the entire neighbor cache, but poll()
would uselessly spin until the answer arrives (if ever).
2017-11-22 07:20:31 +00:00
whitequark 6c83936872 Extract socket handle into a new SocketMeta structure.
This paves way for adding more metadata apart from handles,
such as caches and so on.

This commit also removes SocketHandle::EMPTY in favor of
SocketHandle::default() since they are functionally identical.
2017-11-22 03:50:09 +00:00
whitequark 715aa4b217 Add a missing feature check. 2017-11-21 12:02:25 +00:00
whitequark 52a6e27206 Implement eviction in neighbor cache for fixed storage size. 2017-11-21 11:53:26 +00:00
whitequark 29a338228d Fix a broken macro invocation. 2017-11-21 11:06:53 +00:00
whitequark eaa50d0003 Rewrite the ARP cache to allow for flood protection and expiration. 2017-11-21 10:53:55 +00:00
Kai Lüke 2a52234d53 Don't panic on TCP sequence number wrapping in debug mode. 2017-11-13 18:03:36 +00:00
Egor Karavaev 1e809daf7a Make `Error::Unaddressable` ignored for ICMP sockets as well. 2017-11-13 14:16:03 +00:00
Egor Karavaev eb7d0e346e ICMP sockets don't end ICMP packets processing. 2017-11-13 14:16:03 +00:00
Kai Lüke 3db035bbac Preserve retransmission timer for Dup-ACKs
Duplicate ACKs should not replace the retransmission timer,
but if not in retransmission, still set the keep-alive timer
as normal ACKs do.
2017-11-13 06:26:26 +00:00
whitequark 959e4829a9 Fix ICMP socket documentation. NFC. 2017-11-13 04:54:49 +00:00
whitequark 19373c58c8 Style. NFCI. 2017-11-09 02:07:24 +00:00
whitequark 65c8aea921 Remove impl Ord/PartialOrd for Cidr.
It's not obvious that CIDRs are ordered in any particular meaningful
way.
2017-11-09 01:50:34 +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 d9fa7f6bc6 Rename proto-* features back to socket-*.
A proto-* feature does not make sense for ICMP, where the protocol
is always enabled, but sockets, not.
2017-11-06 09:51:03 +00:00
whitequark c2994b9757 Reimplement {RawSocket,TapInterface}::receive correctly. 2017-11-06 09:38:44 +00:00
whitequark 7039ec8b04 Rename a few tests. NFC. 2017-11-04 02:42:51 +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
Dan Robertson b64257812b Do not send ICMPv4 responses to broadcasts
- Do not send ICMPv4 responses for packets with a broadcast destination
   address.
   - Do not send DstUnreachable with ProtoUnreachable on receipt of a
     packet with an unknown protocol with a non-unicast destination
     address.
   - Do not send DstUnreachable with PortUnreachable on receipt of a
     UDP packet when no sockets are listening on the destination port
     and the destination address is a non-unicast address.
 - Send the correct amount of the original datagram when sending Destination
   Unreachable error responses.
   - Do not assume that a ip datagram has a payload when sending a proto
     unreachable ICMPv4 error response.
 - Add tests to iface tests.
   - Ensure ICMP error responses are correctly formed when the
     datagram has no payload.
   - Ensure ICMP error responses are correctly handled for UDP packets
     when no socket is listening on the destination port.
   - Ensure the correct amount of the original payload is returned in
     Destination Unreachable responses.
2017-11-01 06:34:10 +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
whitequark 0b22943ddd Fix Cidr::contains_addr for zero length prefixes. 2017-10-30 08:25:32 +00:00
whitequark 33fa859665 Do not parse an empty string as an IpAddress.
This is more likely to result in downstream confusion than not.
Let downstream code decide exactly what it wants to do with
an empty string; be conservative here.
2017-10-30 07:20:55 +00:00
Dan Robertson 1cafcfc19f Tests: Add basic interface tests
- Add tests for the following
   - ICMP error responses are not sent in response to broadcast requests
   - ARP requests are responded to and inserted into the cache
   - ARP requests for someone else are not responded to, but the sender
     is still inserted in the cache
2017-10-28 19:33:01 +00:00
whitequark d37f4ef254 Use a much more sensible method naming for SocketRef. 2017-10-25 02:16:23 +00:00
whitequark 103fff9233 Expose wrapping and unwrapping of SocketRefs. 2017-10-25 01:28:59 +00:00
whitequark a9a00baa49 Rename Cargo features: socket-* → proto-*. 2017-10-25 00:20:40 +00:00
whitequark e495544a85 Fix a naming mishap. NFCI. 2017-10-24 23:55:58 +00:00
whitequark a7e6a1b5ae Simplify. NFC. 2017-10-24 23:12:55 +00:00
whitequark 1cd3625bf4 Small adjustments to TTL code; style, docs, and tests. NFCI. 2017-10-24 23:12:55 +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
whitequark 4f689be81b Dump malformed ingress packets at DEBUG log level. 2017-10-24 20:37:52 +00:00
whitequark fa636b9fcb Style fixes. 2017-10-24 18:08:22 +00:00
whitequark af69c6de82 Fix a (future) syntax error in the net_log macro. 2017-10-15 10:10:08 +00:00
Egor Karavaev 19b1b764ed Implement a SocketRef smart pointer to detect state changes. 2017-10-05 03:44:20 +00:00
whitequark 52600cd521 Replace "socket debug identifiers" with just socket handles.
This is basically a rename that now calls an apple an apple,
except user code can no longer change it. It's not obvious if
user code getting the socket handle from the socket is very useful,
but it's not harmful either, so why not.
2017-10-05 03:02:41 +00:00
whitequark eb33cdcf68 Fix a typo. 2017-10-04 01:54:39 +00:00
whitequark b2cfb94b48 Explain the return value of poll(). 2017-10-03 20:41:45 +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
Egor Karavaev f57de10625 Implement wire::{IpCidr/Ipv4Cidr}. 2017-10-03 14:27:17 +00:00
whitequark 72481c2661 Formatting. NFC. 2017-10-03 14:27:01 +00:00
whitequark e4fb2b2997 Make sure IpAddress prohibits exhaustive matches.
I forgot to ensure this.
2017-10-03 13:22:09 +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 cf986bf20b Fix insufficient length validation in IPv4 packets.
Found via cargo-fuzz.
2017-10-02 23:03:41 +00:00
whitequark f60e689b04 Reword checksum-related documentations.
cc @steffengy
2017-10-02 21:52:30 +00:00
whitequark 30754efc4f Formatting. NFC. 2017-10-02 21:51:43 +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 4826d37c45 Allow disabling any of: raw, TCP or UDP sockets. 2017-09-25 00:20:22 +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 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 9c3534e452 A few cosmetic changes to TCP socket trace messages.
No functional change.
2017-09-24 13:39:23 +00:00
whitequark 32d720831a Completely redo the logic of TCP socket polling.
The previous implementation made no sense. It is obvious that
poll_at() should use the same mechanisms to decide whether dispatch()
should be called as dispatch() itself uses to decide whether to send
anything.

This fixes numerous busy looping issues that arise if the return
value of poll() is used for waiting.
2017-09-24 13:20:56 +00:00
whitequark 96b284a30f Fix two issues that may cause TCP sockets to be polled too late.
1. Apart from non-empty transmit buffer, a state which transmits
   a FIN flag should also be considerd. Otherwise, closing a socket
   with an empty transmit buffer may retransmit the FIN flag forever.
2. Timeout poll requests should only be overridden by timer poll
   requests when the latter is earlier.
2017-09-24 11:04:55 +00:00
whitequark 8db752eb7a Fix a typo in documentation. 2017-09-24 08:23:46 +00:00
whitequark 8e13333988 Remove all remnants of the collections feature. 2017-09-22 20:40:13 +00:00
whitequark 711c05f7b1 Make TCP more RFC 5681 compliant wrt immediate ACKs. 2017-09-22 18:57:47 +00:00
whitequark a5a9bb44c9 Clarify inline TCP documentation. 2017-09-22 18:40:23 +00:00
whitequark a1b2605af7 Revert "Keep dispatching packets from a socket as long as there are any."
This reverts commit 51b2f18d1165bf7257de8894df101299cc93b094.

There's no throughput difference so far as I could measure, but
this greatly increases worst-case latency. At some later point
we could perhaps pass a deadline to the poll function, but for now
reverting this is simple enough.
2017-09-22 18:09:18 +00:00
whitequark 05a480575c Keep dispatching packets from a socket as long as there are any.
Typically, the poll function is used as a part of a larger RTOS.
If we only dispatch one packet per socket per poll() call,
then we have to wait for a complete scheduler roundtrip,
which is potentially a lot of time, and as a result we are
not filling the peer's window efficiently.
2017-09-22 17:55:49 +00:00
whitequark b90cee43bb Fix a warning. 2017-09-22 17:38:58 +00:00
whitequark 8166037a91 Handle buffer wraparound in TCP reassembly code. 2017-09-22 17:10:51 +00:00
whitequark 075a2ebb83 Make sure all side-effectful RingBuffer methods are #[must_use].
Some of them already use Result, but the ones that can return
an empty slice (or a slice shorter than requested) also must have
their return value (at least) checked.
2017-09-22 17:08:46 +00:00
whitequark 0bbab2aeed Add RingBuffer::{enqueue_allocated,dequeue_allocated}.
These should be used instead of enqueue_many because they do not
require the caller to handle wraparound explicitly.
2017-09-22 17:04:56 +00:00
whitequark e6bf27d078 Add RingBuffer::{read_allocated,write_unallocated}. 2017-09-22 16:23:37 +00:00
whitequark 5aae15aaba Fix an issue where TCP packets would have zero IP payload length. 2017-09-22 10:14:26 +00:00
whitequark a9d6a9b7b8 Fix a few warnings. 2017-09-22 10:06:40 +00:00
whitequark 7a2cd7842d Implement reassembly of out-of-order TCP segments. 2017-09-22 10:06:40 +00:00
whitequark b6e4e23868 Clean up PSH flag handling. 2017-09-22 08:15:29 +00:00
whitequark d7da46fd3b Do not clear remote_last_ts in TcpSocket::set_timeout().
After this change, if an 1s timeout is set on a socket that received
no packet for 2s, it will be instantly aborted, which seems
more reasonable. Also, this makes the `self.remote_last_ts.is_none()`
branch in TcpSocket::dispatch() actually behave as described.
2017-09-22 06:16:58 +00:00
whitequark f23bfe2014 Clean up and document TCP MSS calculations. 2017-09-22 06:02:03 +00:00
whitequark ba2d7f483a Implement a buffer (re)assembler. 2017-09-20 20:46:15 +00:00
whitequark 2c4222a0b6 smoltcp;:parsing → smoltcp::parsers. 2017-09-20 20:18:50 +00:00
whitequark 9281733209 Implement TCP timeouts. 2017-09-18 11:05:40 +00:00
whitequark fe80bca19d Implement TCP keep-alive. 2017-09-16 10:54:59 +00:00
whitequark be0dcb145c Fix warnings. 2017-09-15 06:05:41 +00:00
whitequark e8788be3a0 RingBuffer::{empty,full}→is_{empty,full}.
Query methods in Rust conventionally start with the "is" prefix.
2017-09-08 23:23:40 +00:00
whitequark 5ffce2c1a6 Remove Error::Rejected.
This wasn't an actual error, just a poorly designed communication
mechanism between sockets and whatever lies on the layer below them.
2017-09-08 00:59:46 +00:00
Egor Karavaev 8404fe908c Factor out TcpSocket::accepts. 2017-09-08 00:57:42 +00:00
Egor Karavaev 02b699e18c Factor out UdpSocket::accepts. 2017-09-08 00:57:19 +00:00
Egor Karavaev b4d6a53e34 Factor out RawSocket::accepts. 2017-09-08 00:56:42 +00:00
whitequark 9b242c7099 Send a challenge ACK in response to an unacceptable TCP ACK. 2017-09-08 00:11:44 +00:00
whitequark 844843c4bc Remove RingBuffer::set_len().
set_len() with a positive length change is better represented
with enqueue(), and set_len() with a negative length change
is not really a valid operation on its own.
2017-09-07 23:54:39 +00:00
whitequark 1102bd94e7 Refactor the "random access" ring buffer interface. 2017-09-07 23:47:42 +00:00
whitequark 5dc0353b2a Refactor the "continuous" ring buffer interface.
This also makes TcpSocket::{send,recv}_slice slightly more efficient
in case when the slice wraps around the corresponding buffer,
halving the necessary amount of calls.
2017-09-07 21:17:31 +00:00
whitequark a9719f4a13 Merge the TCP ring buffer and generic ring buffer.
This adds a few methods to RingBuffer that don't quite fit into
its interface (the slice ones), but we can fix that later.
2017-09-07 00:09:34 +00:00
whitequark 27a23ed3c3 Don't instantly ACK every received TCP segment.
This is prohibited by RFC 1122. Instead, aggregate them, and respond
once in the egress function.

However, still instantly send challenge ACKs to trigger fast
retransmit.
2017-09-05 23:23:50 +00:00
whitequark 8876d71802 According to RFC 1122, unsupported IP options MUST be ignored. 2017-09-01 19:31:09 +00:00
whitequark 7db21529e5 An unaddressable egress packet should not be a reportable error. 2017-09-01 10:30:56 +00:00
whitequark f8edf0faea Unbreak traffic shaper in the fault injector. 2017-08-31 21:39:01 +00:00
whitequark b585fbd368 Exhaustion of transmit buffers should not be a reportable error. 2017-08-31 16:27:50 +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 a71542b2f2 Allow querying the size of the TCP transmit and receive buffers.
This may be useful to e.g. ensure the complete transmit buffer
is flushed before proceeding.
2017-08-31 13:22:20 +00:00
whitequark 13dbe09fba TCP socket debug messages "sending <flags>" should be at DEBUG level.
They're not exceptional.
2017-08-31 12:39:05 +00:00
whitequark 80e510c9e2 Dispatch a TCP ACK every time window increases at all.
Commit 21282fdb was not completely sufficient because e.g. receiving
one octet and then blocking meant that an ACK with window length
of one is then sent, and this isn't motivating the other TCP stacks
all that much.

In any case, preemptively notifying the peer of window size increase
can only be beneficial, modulo network congestion.
2017-08-31 00:14:29 +00:00
whitequark 5e48567297 Send a TCP ACK after window increases from zero to non-zero. 2017-08-30 23:09:31 +00:00
whitequark 6324d3384a More rigorously treat the TcpSocket::remote_last_ack field.
Zero is a valid sequence number, treating it as an absence of value
isn't any good. This is unlikely to cause any real harm but it
just isn't good practice, nor does it make for understandable code.
2017-08-30 22:40:07 +00:00
whitequark 41ceeea9ac Fix the TCP SEQ acceptability check.
It has nothing to do with the last ACK transmitted.
2017-08-30 22:26:35 +00:00
whitequark c2bc20e9bf Move the TCP receive window clamping hack downwards in stack.
Otherwise, our response ACKs did not get the clamping treatment,
and severe packet loss resulted.

Also, explain why it's needed and how it works.
2017-08-30 14:00:14 +00:00
whitequark d53bdab029 Fix Ipv4Packet::payload{,_mut}() returning overly long buffers.
These functions only skipped the header, but what they should have
done is cut the packet at its total length and skip the header.
Otherwise, if the buffer the IP packet is constructed from contains
padding, such as Ethernet packets, the payload would be too long.
2017-08-30 13:34:50 +00:00
whitequark 5a066fbc6c Return from EthernetInterface::poll() on errors, don't swallow them.
We still print them into our debug log though, because it has more
context; the caller may opt to ignore any poll errors and only
use the smoltcp debug log as a, well, debugging aid, or it could
print user-visible warnings to alert the user to unusual network
conditions.
2017-08-30 10:20:11 +00:00
whitequark 7b3574e6ee Rework TCP retransmit logic to be much more robust.
Before this commit, if the amount of data in the buffer caused it
to be split among many outgoing packets, and retransmit timer
was active, the socket would behave very erratically and flood
the peer.
2017-08-30 10:12:53 +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 7cd7bd4683 Reset the timer transitioning from TCP FIN-WAIT-1 to FIN-WAIT-2.
We don't transmit anything in FIN-WAIT-2, so we don't need the timer
running, or we'll get spurious log messages about retransmissions.
This also makes logic cleaner, although with no functional change.
2017-08-29 19:47:11 +00:00
whitequark cdf236412f Clarify a function name. 2017-08-28 12:45:33 +00:00
whitequark f84b234a38 Add a test for TCP sockets returning ACKs even with zero window. 2017-08-28 06:01:21 +00:00
whitequark 695c61fd05 Break up the EthernetInterface::dispatch macro atrocity into functions.
There wasn't any real reason for it to be a macro, it was ugly
and unreadable, and it resulted in combinatorial bloat when compiled.
2017-08-28 05:49:56 +00:00
whitequark 34db543cac Factor out packet parsing from Socket::process.
Not only is it incredibly wasteful, but this information is
in any case already necessary within the EthernetInterface::process_*
methods.
2017-08-28 05:48:16 +00:00
whitequark 379bc60924 Get rid of unused arguments in Socket::{process,dispatch}.
I've left those "for consistency" but it just implies data
dependencies where there are none, and bloats signatures.
2017-08-28 04:14:25 +00:00