Commit Graph

837 Commits (master)

Author SHA1 Message Date
Alex Crawford e78c9576b2 Clean up iterator chains
These were flagged by `cargo clippy`:

    warning: called `is_some()` after searching an `Iterator` with find.
             This is more succinctly expressed by calling `any()`.
    warning: this `.into_iter()` call is equivalent to `.iter_mut()` and
             will not consume the `BTreeMap`
    warning: called `skip_while(p).next()` on an `Iterator`

The skip_while conversion is a little tricky. Clippy notes that:

    warning: called `skip_while(p).next()` on an `Iterator`
    help: this is more succinctly expressed by calling `.find(!p)` instead

So the condition of the skip_while is inverted and then simplified using
De Morgan's laws.
2020-12-27 17:00:03 -08:00
Alex Crawford 81ddfe734f Remove some redundant closures
These were flagged by `cargo clippy`:

    warning: redundant closure found
2020-12-27 17:00:03 -08:00
Alex Crawford 737fdf7bbf Use subsec_millis where possible
These were flagged by `cargo clippy`:

    warning: calling `subsec_millis()` is more concise than this
             calculation
2020-12-27 17:00:03 -08:00
Alex Crawford ec5c924d88 Prefer elided lifetimes
These were flagged by `cargo clippy`:

    warning: explicit lifetimes given in parameter types where they
             could be elided (or replaced with `'_` if needed by type
             declaration)
2020-12-27 17:00:03 -08:00
Alex Crawford d2b557e01c Prefer assignment operators
These were flagged by `cargo clippy`:

    warning: manual implementation of an assign operation
2020-12-27 17:00:03 -08:00
Alex Crawford a73c90ad08 Silence warning about matches macro
These were flagged by `cargo clippy`:

    warning: match expression looks like `matches!` macro

The matches! macro isn't stabilized until Rust 1.42.
2020-12-27 17:00:02 -08:00
Alex Crawford 79e81bf97f Silence warning about is_empty method
These were flagged by `cargo clippy`:

    warning: item has a public `len` method but no corresponding
             `is_empty` method
2020-12-27 16:59:39 -08:00
Alex Crawford 1a1861721b Silence warning about non-exhaustive pattern
These were flagged by `cargo clippy`:

    warning: this seems like a manual implementation of the
             non-exhaustive pattern

The non_exhaustive attribute isn't available until we increase the
minimum Rust version to 1.40, so we should just silence these warnings
in the meantime.
2020-12-27 16:59:30 -08:00
Alex Crawford 752e81489e Dereference match expressions to clean up patterns
These were flagged by `cargo clippy`:

    warning: you don't need to add `&` to all patterns

This should have happened in ac830e8b, but I guess I missed it.
2020-12-27 15:20:16 -08:00
Alex Crawford 321998eb66 Prefer if-let syntax over single-pattern match
These were flagged by `cargo clippy`:

    warning: you seem to be trying to use match for destructuring a
             single pattern. Consider using `if let`

This also silences a few cases where the match couldn't be replaced with
an if because of the following error:

    error: attributes are not yet allowed on `if` expressions

Once we increase the minimum Rust version to 1.43, these can be updated
as well.
2020-12-27 15:20:14 -08:00
Alex Crawford b2c04416c2 Use is_empty instead of length comparison
These were flagged by `cargo clippy`:

    warning: length comparison to zero
2020-12-27 15:18:51 -08:00
Dario Nieuwenhuis 708be1ccb5 Split Packet into EthernetPacket and IpPacket.
Functions that only deal with IP packets take/return IpPacket's. IpPacket's
are wrapped into EthernetPacket's as late as possible.

This will later allow generalizing Interface to handle both Ethernet
and pure-IP mediums.
2020-12-27 19:57:18 +01:00
Dario Nieuwenhuis 2d7b150984 Remove "None" variant from Packet, use Option<Packet> instead. 2020-12-27 19:25:25 +01:00
Dario Nieuwenhuis 2c8b780702 tcp: fix racey simultaneous close not sending FIN. 2020-12-27 19:11:52 +01:00
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
Dario Nieuwenhuis 4e11070ff4 Async/await waker support. 2020-12-27 17:31:49 +01:00
Dario Nieuwenhuis 29cc59c89d Merge pull request #395 from crawford/clippy
Various cleanup suggested by cargo clippy
2020-12-26 23:53:25 +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
Alex Crawford 0c7cdbb4ef Remove unnecessary returns
These were flagged by `cargo clippy`:

    warning: unneeded `return` statement
2020-12-26 10:32:51 -08:00
Alex Crawford c58711e11b Use newline variants of write macro
These were flagged by `cargo clippy`:

    warning: using `println!("")`
    warning: using `write!()` with a format string that ends in a single
             newline
2020-12-26 10:32:42 -08:00
Alex Crawford d217c81e5d Remove explicit calls to as_ref/as_mut
These were flagged by `cargo clippy`:

    warning: this call to `as_ref` does nothing
    warning: this call to `as_mut` does nothing
2020-12-26 10:27:32 -08:00
Dario Nieuwenhuis a7d3f604a3 Don't use matches! macro, for Rust 1.36 support 2020-12-26 03:12:48 +01:00
Dario Nieuwenhuis 67e03b34b6 Fix seq_to_transmit incorrectly returning true when a FIN was enqueued.
If there's data queued that doesn't fit into the remote window, we can't
send the FIN either, so seq_to_transmit should return false.
2020-12-26 03:04:17 +01:00
Dario Nieuwenhuis 12f2e0f7e2 Merge pull request #372 from JOE1994/null_terminator
add null terminator to c-string passed to 'libc::open'
2020-12-26 00:24:27 +01:00
JOE1994 e12f4abaa0 add null terminator to c-string passed to libc API 2020-12-26 00:07:14 +01:00
Dario Nieuwenhuis 273f4d60b6 Fix MTU of RawSocket and TapInterface.
Linux's MTU is the IP MTU, while smoltcp's is the Ethernet MTU.
Therefore we have to add the ethernet header size to it.
2020-12-25 23:57:54 +01:00
Dario Nieuwenhuis f89d240c29 tcp: don't send data outside the remote window 2020-12-19 03:23:44 +00:00
Dario Nieuwenhuis 42dc04852b tcp: allow sending ACKs in FinWait2 state. 2020-12-19 01:13:59 +00:00
mustermeiszer 7b4997d5c7 Taking into account TCP and IP header
The MTU consists of TCP header, IP header and the payload.
In the former fix, this was not taken into account.
2020-10-23 15:13:18 +02:00
mustermeiszer d2aa3edbb7 Fixes unused MTU settings at TcpSocket dispatch
This commit fixes a small bug, where the TcpSocket computed the maximum
size per payload in a tx_buffer without taking into account the MTU
defined by the underlying network device.
2020-10-23 14:12:20 +02:00
Sam Jones d32c72aafd Changed Dhcpv4Client to use device checksum capabilities 2020-10-22 10:31:36 +00:00
whitequark 3e22502f61 Merge branch 'master' into dhcpv4-use-requested_ip 2020-10-22 09:53:38 +00:00
Dario Nieuwenhuis bc1f718589 igmp: centisecs are really decisecs 2020-10-22 03:48:19 +00:00
Ryan Summers 1ae400acaa Return RST to unexpected ACK in SYN-SENT state.
Before this commit, the socket got stuck in an unusable state.
2020-08-17 05:44:58 +00:00
whitequark f35057c19f Fix test that relied on matching panic messages.
The panic message for copy_from_slice changed in Rust 1.47.
2020-08-17 05:19:09 +00:00
Thales Fragoso 88d01234a8 Match silent_until behavior of NeighborState and Cache 2020-08-17 04:44:58 +00:00
Thales Fragoso 561708c34f Merge lookup and lookup_pure methods 2020-08-17 04:44:58 +00:00
Thales Fragoso 1e5de8d42c Only limit the neighbor cache rate after sending a request packet
Prior to this change, the neighbor cache would get limited even when the
device failed to process our arp packet, which could put the socket in
the waiting state in the next poll.

This change only limits the cache rate if the device successfully
consumed our packet.
2020-08-17 04:44:58 +00:00
whitequark 548a019991 Update src/socket/meta.rs 2020-08-11 16:26:53 +00:00
Thales Fragoso 24e4868761 Allow for ARP retry during egress 2020-08-10 22:06:06 -03:00
whitequark 6a38ace62c Improve docs for `DeviceCapabilities.checksum`. 2020-07-15 05:06:35 +00:00
Dario Nieuwenhuis 4cfe8dafdb Do not send window updates in states that shouldn't do so.
Previously, the window update was sent anytime it changed. This is
not desirable for 2 reasons:

- It would send window updates in TimeWait or Closed states, which is incorrect.
- It would send window updates in states where we've already received the
  remote side's FIN, such as CloseWait. This is not necessarily incorrect, but
  is useless, since the remote side is not going to send us more data, therefore
  it's not interested in our window size anymore.
2020-06-25 04:06:29 +00:00
YOUNGSUK KIM f6a55fa3c7 replace deprecated item 'mem::uninitialized'
This commit replaces the use of deprecated item 'mem::uninitialized'
with 'mem::MaybeUninit'.

Thank you for reviewing :)
2020-06-22 14:46:56 +00:00
Lucas Zanela d5c44a37d5 Fix overly strict lifetime in TcpSocket. 2020-06-15 12:39:06 +00:00
Dario Nieuwenhuis d1e614516a Remove now-redundant `remote_last_ack` update. 2020-06-12 18:49:33 +00:00
Dario Nieuwenhuis 544b3789d0 Document `Error::Finished` in `recv()`. 2020-06-12 09:43:44 +00:00
Dario Nieuwenhuis a176641192 Return `Error::Finished` in `recv()` on graceful close.
This allows applications to distinguish whether the remote end has
gracefully closed the connection with a FIN (in which case it has
received all the data intact), or the connection has failed due to e.g. a
RST or a timeout (in which case the received data may be truncated).
2020-06-12 09:43:44 +00:00
Dario Nieuwenhuis efbd3ec23d Add `Finished` error. 2020-06-12 09:43:44 +00:00
Dario Nieuwenhuis 0d31e0a134 Always send updated ack number in `ack_reply()`.
Previously, `ack_reply()` was sending the ack number present in `remote_last_ack`,
which is only updated by `dispatch`. This means the ack replies could contain
a wrong, old ack number.

Most of the time this simply caused wasting an extra roundtrip until the socket state
settles down, but in extreme cases it could lead to an infinite loop of packets, such
as in https://github.com/smoltcp-rs/smoltcp/issues/338

Fixes #338
2020-06-11 23:24:24 +00:00
Dario Nieuwenhuis ffcaa83502 Accept data packets in FIN_WAIT_2 state.
Previously, data packets were never accepted in FIN_WAIT_2. The missing
match case was dropping them as "unexpected packet"s.
2020-06-11 20:19:44 +00:00
Robin Lambertz 0b3858cb31 Re-export dhcp::clientv4::Config
The dhcpv4 client currently doesn't expose the Config struct returned by the poll function.
2020-06-02 16:58:56 +00:00
Zhaofeng Li d8c604f567 Specify concrete type for Bound::Unbounded
Somehow type inference got confused. Fixes #340.
2020-06-02 16:30:54 +00:00
Dario Nieuwenhuis 386f50dbd2 Assign map instead of using mem::replace.
This fixes build on latest nightly. The cause of the breakage
is this commit:

7c4ca59f4b

which added a #[must_use = "if you don't need the old value, you
can just assign the new value directly"] hint to mem::replace.
2020-05-02 05:46:18 +00:00
fdb-hiroshima 09f4a8f551 use provided ip for TcpSocket::connect instead of 0.0.0.0 2020-04-16 07:55:17 +00:00
nabijaczleweli 41fe0f828a Fix support table in toplevel doc 2020-04-16 07:18:52 +00:00
Gary Guo 18b728ebba Fix packet buffer panic caused by large payload (#332)
When packet buffer's payload buffer does not have enough contiguous
window left, the ring buffer roll over uses an incorrect size
causing the ring buffer pointer not resetting to the head.

When the payload enqueued is larger than 1/2 of the payload ring
buffer, this bug will cause the slice returned by
`PacketBuffer::enqueue` to not match the requested size, and
trigger `debug_assert` in debug profile or size mismatch panic in
`copy_from_slice` when compiled in release profile.
2020-04-14 10:48:31 +02:00
Scott Mabin a4198d3a2a s/recieve/receive/ 2020-01-06 09:43:56 +00:00
Pierre Krieger 9c5f77dd7e Implement Hash for SocketHandle
Closes: #320
Approved by: whitequark
2019-12-23 03:53:53 +08:00
ficapy d01e23e396 Support different types of ioctl request argument 2019-12-15 06:25:43 +00:00
Scott Mabin 39462d24f4 Add suppor for DHCP maximum message size option. 2019-11-07 04:47:36 +00:00
Scott Mabin d7916c9a92 Add capacity methods to all sockets. 2019-11-05 23:07:12 +00:00
Scott Mabin cd48a2ef12 Revert to prevous ordering of TCP options.
Although ordering is not specified in the spec, some implementations expect
some ordering (unforntunately I have found one that does, and blocks outbound
packets due to 'invalid tcp options').
2019-11-01 22:04:19 +00:00
Scott Mabin 287e4f2814 raw_socket: gracefully handle packet truncation errors 2019-10-08 23:55:48 +00:00
Scott Mabin 0edd7d3a13 dhcpv4:
Instead of configuring the ifaces ip address when a dhcp server offers
and ip, we now use the requested_ip option, based on the offered ip
(yiaddr). The user now only has to configure the iface once the dhcp
transaction has completed (Ack'd).
2019-10-06 22:02:40 +01:00
Ruben De Smet eebd8e431a Add ethernet feature-gate as default.
Disable ethernet-related features and framing based on a feature gate.

Add a no-ethernet option to Travis.

notes:
- allow(unused) is added when not using ethernet feature
- Don't run pretty-print doctest, ethernet is optional.

Closes: #308
Approved by: whitequark
2019-10-04 22:49:54 +08:00
Chris Ballance 0df7e51a9f Only use first 3 DHCP advertised DNS servers.
The OPT_DOMAIN_NAME_SERVER DHCP option field can advertise an unbounded
DNS servers, but we currently use a fixed length array to store these
servers. This commit ensures only the first 3 (highest priority) servers
are used.

Fixes #305.
2019-09-30 17:19:05 +00:00
Richard Meadows 186bc05d77 Allow TCPSockets in a SocketSet without 'static storage lifetime
`TCPSocket` buffers are type `RingBuffer<'a, _>` whilst other
socket types have buffers with type `PacketBuffer<'a, 'b,
_>`.

There is an enum over socket types `pub enum Socket<'a, 'b: 'a>`,
 which is in turn used by `set::Item` and `SocketSet`. The lifetime
 `'b` is not required for `TcpSocket`, but the `Into<Socket>`
 implementation for `TCPSocket` specifies the `'static` lifetime for
 `'b`.

Therefore using `TCPSocket` in a `SocketSet` currently requires the
lifetime `'b` for other sockets to be `'static` which is unnecessarily
restrictive. This patch fixes this.

The lifetime signature of socket specifies `'b: 'a`, that is `'b`
outlives `'a`. Instead of `'static`, this is also satisfied by
`impl<'a> Into<Socket<'a, 'a>> for TcpSocket<'a>` as `'a` "outlives"
`'a` by definition.

The example
[here](https://gist.github.com/richardeoin/b562e79d0d499e00a8bf4944f00594d9)
fails to compile without this patch.

Closes: #304
Approved by: whitequark
2019-08-15 08:31:48 +08:00
Andreas Molzer 8e1fa540c3 Restore Session::finish call in socket ref
Using move semantics allows an Option to keep track of the
initialization state while satisfying the borrow checker. This replaces
the functionality that the 'consumed' flag had before. It also retains
the smaller object size since the Option of a reference can use the
representation of the null pointer, which is an invalid reference, as a
niche for the None variant.

Closes: #301
Approved by: whitequark
2019-07-23 20:13:07 +08:00
whitequark 10e251b0aa Bump log dependency to version 0.4.4. NFC.
Since 0.4.4, log uses #[macro_export(local_inner_macros)], which is
the right thing to do, but it breaks our CI because of a now-unused
\#[macro_use(log)].
2019-07-23 12:10:38 +00:00
whitequark 2902ca00c0 Fix potential unsoundness in SocketRef::into_inner()/drop().
This didn't ever actually cause UB because the drop implementation
should have compiled to a no-op under all conditions; `finish` is
a part of a patchset that never got in. (Even if it didn't, the code
should have been dynamically sound, under all but the most strict
interpretations of Rust's aliasing requirements.)

But it's still a problem, at least because there is a warning for
this potential unsoundness that will become an error in the future.
So everything else aside, we can't use this pattern going forward.

For now, remove the Drop impl, exploiting the fact that `finish`
is a no-op. Going forward this will likely require unsafe code, or
some fundamental change in the way SocketRef is implemented, but
I could not come up with any way to do it. :(
2019-06-22 10:52:39 +00:00
whitequark b5d5023ac6 Bump Rust version requirement to 1.28.
Actually, this is not a new requirement at all; because we do not
check the minimum version on CI, some dependencies on 1.28 have
already sneaked in. In particular, our required version of the crate
managed only works on 1.28+.

This allows us to use:
(1.28)
  - ops::RangeBounds
  - num::NonZero

Some trait bounds were added to make sure everything builds on 1.28.
2019-06-22 09:04:45 +00:00
whitequark 563434997c Fix spurious crash in commit bd3912e5. 2019-06-22 09:04:30 +00:00
whitequark be7750486f Bump log dependency to version 0.4. NFC.
This doesn't affect downstream code because log 0.3.9 is a facade
crate implemented in terms of log 0.4, and so log 0.3 and log 0.4
APIs can be used together.
2019-06-22 08:31:11 +00: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 59f76f1868 Fix docstring for SocketRef::into_inner(). NFC. 2019-06-22 07:49:27 +00:00
whitequark f32522bef7 Fix docstrings for TcpSocket::{send,recv}_slice(). NFC. 2019-06-22 07:49:24 +00:00
whitequark 4e77a29c91 Clarify TcpSocket::recv_queue() semantics. NFC. 2019-06-22 07:03:15 +00:00
whitequark efdf3a2fb3 Fix typo in docstring. NFC. 2019-06-22 06:50:58 +00:00
David Wood 67653fbf38 Pad output of `Display` on `Instant`
Zero-pad the milliseconds part of a displayed `Instant` to include
three leading zeros.
Closes: #297
Approved by: whitequark
2019-05-28 06:25:37 +08:00
jhwgh1968 1bdf155ead Implement Fuzz Injector
Closes: #284
Approved by: whitequark
2019-05-19 06:41:07 +08:00
Astro 49f638e2d2 Implement DHCPv4 client + example.
Closes: #186
Approved by: whitequark
2019-05-14 00:37:43 +08:00
Astro 69bc2de64c process_ipv4(): stub handled_by_raw_socket in absence of feature="socket-raw"
Closes: #295
Approved by: whitequark
2019-05-09 03:45:07 +08:00
Astro 1276234e98 Partially revert "Suppress ICMP error replies […]", still allow reception by other sockets.
This reverts commit f56666a26722c4f4f962937119d71792b51c396e.

Adds another test case.

Closes: #295
Approved by: whitequark
2019-05-09 03:45:07 +08:00
jhwgh1968 9f2febcaea Allow mutation of data buffer in RxToken
Closes: #294
Approved by: whitequark
2019-05-05 03:48:25 +08:00
Astro a009e0ad9d Suppress ICMP error replies for packets that are accepted by raw sockets.
Closes: #293
Approved by: whitequark
2019-05-01 10:22:52 +08:00
Astro ebf449340b test_icmp_reply_size: fix for ipv4-only case
Closes: #292
Approved by: whitequark
2019-05-01 10:11:50 +08:00
Andreas Molzer 4172ce1301 Implement accessors for the Tracer
This makes the `Tracer` wrapper for a phy device close to a drop-in
replacement for the encapsulated device.

Closes: #289
Approved by: whitequark
2019-04-26 20:30:20 +08:00
Andreas Molzer 8c3bdf907b Allow access to phy-device in ethernet
Adds accessor functions to the device implementing the phy::Device trait
within an ethernet interface. The intent is to allow access to read-only
methods such as gathering of device statistics or other diagnostics
while the interface is running. The interface does not hold any internal
invariants on the device, so that a mutable accessor can be added as
well.

Closes: #289
Approved by: whitequark
2019-04-26 20:30:20 +08:00
Andreas Molzer b27cbad6f4 Fix omission of udp checksum
Allow the control flow to continue when udp parsing encounters an
invalid checksum within an ipv4 packet, instead of returning with an
error. Additionally adds a test to ensure the correct behaviour.

Closes: #280

Closes: #290
Approved by: whitequark
2019-04-26 20:14:01 +08:00
Andreas Molzer c9fbd56977 Remove an unused mut qualifier on a variable
Fixes a denied lint uncovered on a recent nightly compiler version,
apparently through improved analysis. The code in question is only
compiled with the proto-ipv6 feature and older compiler versions did not
detect the unused qualifier, sometime around 2019-04-23.

Closes: #291
Approved by: whitequark
2019-04-26 20:01:48 +08:00
Adam Greig 59f5cbbe64 Fix IPv4 broadcast handling
A regression meant broadcast IPv4 packets were ignored. Restore
handling those packets and also reply to broadcast ICMPv4 echo requests.

Closes #287.

Closes: #288
Approved by: whitequark
2019-04-15 01:57:17 +08:00
Andreas Molzer d9e0c8246c Add ip version specific addr/endpoint converters
Converting from `::std::net::*` types to the ip related library structs
previously required both ip-version features to be enabled. This
introduced dedicated converters from the ip-version specific standard
address and endpoint representations (`IpV4Addr`, `IpV6Addr`,
`SocketAddrV4`, and `SocketAddrV6`) that are enabled without requiring
the other ip-version feature to be selected.

Closes: #286
Approved by: whitequark
2019-04-13 14:31:55 +08:00
Chris Branch 8ef6637b0b Implement Any-IP feature
Any-IP is the capability to accept packets locally even when the
destination address is not configured on any interface. This lets
a service bind to an entire subnet of addresses and is particularly
useful in anycast deployments.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4465b469008bc03b98a1b8df4e9ae501b6c69d4b
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ab79ad14a2d51e95f0ac3cef7cd116a57089ba82

This feature is not available for IPv6 as it would be a nop: the current
IPv6 handler doesn't filter packets by the interface's IP address(es).

Closes: #276
Approved by: whitequark
2019-03-19 05:47:29 +08:00
Kai Lüke 49e985a66e Implement peek functions for UDP sockets
This needed a peek function for the packet buffer.

Closes: #278
Approved by: whitequark
2019-02-28 00:58:33 +08:00
Derk Bell 4bb0e5f21a fix indentation
Closes: #274
Approved by: dlrobertson
2019-02-01 23:13:35 +08:00
Derk Bell a1d3b94f7b make fill method public #273
Closes: #274
Approved by: dlrobertson
2019-02-01 23:13:35 +08:00
Alex Crawford 2477355516 Allow more integer types when creating Instants
This allows any type that can be converted into an `i64` to be used when
creating an Instant. Because this is no longer a concrete type, this
change may break existing code like the following:

    error: attempt to multiply with overflow
       --> src/time.rs:282:37
        |
    282 |         epoc = Instant::from_millis(2085955200 * 1000).into();
        |                                     ^^^^^^^^^^^^^^^^^
        |
        = note: #[deny(const_err)] on by default

Closes: #272
Approved by: whitequark
2019-01-28 06:37:39 +08:00
jhwgh1968 e867832214 Minimal Implementation of TCP Selective Acknowledgement
Closes: #266
Approved by: whitequark
2019-01-01 13:51:02 +08:00
Luka Atanasovski 04c9518dd2 Implement raw sockets via BPF on macOS. 2018-12-28 11:46:43 +00:00
whitequark bbc526fcd6 Fix rust-1.28 feature name (should be rust_1.28). 2018-10-29 07:05:49 +00:00
Kai Lüke 15c6c24a87 Increase number of assembler gaps to 32 for std/alloc targets
Only allowing four missing packets is hurting
performance for large receive windows.

The new value was picked by observing good
performance with 500 kB socket buffers.

Closes: #264
Approved by: whitequark
2018-10-05 18:36:35 +08:00
Kai Lüke 2047aaea28 Only change the assembler state on success
The current hole was always shrinked even if the
packet assembler rejected adding a packet due to
not being able to insert a new hole.

Shrink only after a new hole was added.
Shrinking before or after does not make a difference
because offset + size < hole_size and thus
contigs[index] is not empty, passing the
debug_assert in add_contig_at.

https://github.com/m-labs/smoltcp/issues/261

Closes: #265
Approved by: whitequark
2018-09-22 22:00:14 +08:00
jhwgh1968 05d5183ccc Fix fault injection on TCP streams
Closes: #263
Approved by: whitequark
2018-09-16 04:19:57 +08:00
jhwgh1968 ed3862f63b Add iter_data() to Assembler
Closes: #262
Approved by: whitequark
2018-09-01 08:29:59 +08:00
jhwgh1968 88016e675f Fully implement TCP Window Scaling
Closes: #253
Approved by: whitequark
2018-08-20 06:57:44 +08:00
whitequark 2b7a25b1e2 Add an ARTIQ-specific cargo feature "rust-1.28".
This cargo feature only exists because (a) ARTIQ uses a fork of Rust,
(b) Rust has some ridiculous renaming going on in the alloc crate,
(c) smoltcp exists because of ARTIQ.

Such features will not be ordinarily provided by smoltcp.
2018-08-10 14:53:28 +00:00
Astro a8f2725784 Implement IGMPv1/v2 processing.
Closes: #178
Approved by: whitequark
2018-08-01 10:26:51 +08:00
Astro c2c08b4c35 Add IpAddress.to_prefix_len()
Closes: #255
Approved by: whitequark
2018-07-31 19:26:47 +08:00
Astro 633d89b78e Add a few DHCP options
Closes: #255
Approved by: whitequark
2018-07-31 19:26:47 +08:00
M@ Dunlap f3d34b09a2 fixed DHCP constants
Closes: #257
Approved by: whitequark
2018-07-30 22:32:15 +08: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
Dan Robertson 8a214f3850 Add MLDv2 Repr support
Closes: #252
Approved by: whitequark
2018-07-11 10:47:52 +08:00
whitequark 125a102b71 Update to track changes in liballoc. 2018-07-11 01:57:56 +00:00
Kai Lüke 970502e9fb Proper calculation of TCP header length
The presence of TCP options will only increase
the header length to muliples of 4. The added
padding consists of zeros.

This also fixes an emit panic when the Window
Scale and MSS options result in a length of 27
which then gets floored to 24 when applied to
the header.

Closes: #251
Approved by: whitequark
2018-06-28 19:30:43 +08:00
Dan Robertson 56463f19bd Fix code syle nits
- phy: Fix unused mut ref
 - wire: Fix comment collapse unneeded impl block

Closes: #250
Approved by: whitequark
2018-06-27 21:17:50 +08:00
jhwgh1968 1745df2110 Implement TCP Window Scaling, Phase 1 (Issue #106)
Closes: #232
Approved by: whitequark
2018-06-25 03:08:44 +08:00
Sidharth Shanker c7e35d143c Add GC & threshold to the ARP cache.
Closes: #234
Approved by: whitequark
2018-06-25 02:55:53 +08:00
Dan Robertson 82f822930c Move more iface tests to test ipv6
Closes: #249
Approved by: whitequark
2018-06-24 15:24:37 +08:00
Dan Robertson 0563fdf921 Add MLDv2 packet parsing support to wire
Add the basics for parsing MLDv2 packets with the Icmpv6Packet structure
in the wire module.

Closes: #235
Approved by: whitequark
2018-06-23 10:53:10 +08:00
Dan Robertson 276acfb7ef Fix packet buffer enqueue logic error
The size of the contiguous window should be prioritized over the size of
the contiguous window if padding were added.

For example, given the following packet buffer:

  1   2     3
|---|----|------|

If 2 is used and 1 and 3 are empty, enqueing a buffer of size 4 should
be placed in contiguous window 3 and the size of 1 should not cause
any issues in enqueue.

Closes: #247
Approved by: whitequark
2018-06-21 21:04:50 +08:00
jD91mZM2 3d141489a2 Fix impossible lifetime bounds
Using Routes<'static> used to make these functions impossible because it created a reference that needed to be valid for the static lifetime

Closes: #243
Approved by: dlrobertson
2018-06-19 21:14:20 +08:00
Dan Robertson eb078ecf63 Add clippy to CI
Closes: #240
Approved by: dlrobertson
2018-06-19 11:04:39 +08:00
Kai Lüke b23df24a2a Only trigger fast retransmit for data to send
This fixes entering a loop when both endpoints
are stuck in retransmission.

https://github.com/m-labs/smoltcp/issues/224

Closes: #233
Approved by: whitequark
2018-06-18 22:19:42 +08:00
Kai Lüke 272baab3ef Reset retrasmission delay after fast retrasmit
Closes: #233
Approved by: whitequark
2018-06-18 22:19:42 +08:00
Dan Robertson 126f144295 Update docs and fix warnings
Closes: #238
Approved by: dlrobertson
2018-06-18 10:49:16 +08:00
Valentin Lorentz 728ae3fbb5 Add support for arbitrarily many routes instead of only gateways.
Closes: #219
Approved by: whitequark
2018-06-10 05:31:08 +08:00
Ole Martin Ruud 022cad8b11 Fix implementation of fast retransmit (TcpSocket)
Improve detection of duplicate ACKs by checking that the segment does
not contain data.

Move implementation from the 'reject unacceptable acknowledgements'
to later in the process function, because a duplicate ACK is not an
'unacceptable' acknowledgement but rather a condition to update state.

Implement more tests to verify the operation of the fast retransmit
implementation.

Related issue: #224

Closes: #225
Approved by: whitequark
2018-06-10 02:53:35 +08:00
Dan Robertson e88f58739b Improve the Iterator for IPv6 options
- Add a helper function for returning an error in the implementation of
   next
 - Add an assert in Ipv6OptionsIterator::new that ensures that an
   iterator is not created with a length field larger than that of the
   data buffer we're iterating over.

Closes: #230
Approved by: dlrobertson
2018-06-07 05:08:11 +08:00
Dan Robertson 938fd55763 Fix the ipv6 option structure
The IPv6 Option representation layer structure includes the type value
as the raw u8. This should be stored as the Type enum.

Closes: #229
Approved by: whitequark
2018-06-06 07:42:35 +08:00
Dan Robertson 4d01ee3807 Remove v4 from udp/tcp of ChecksumCapabilities
Closes: #220
Approved by: dlrobertson
2018-05-28 09:41:07 +08:00
Dan Robertson 7462664954 iface: Begin parsing Hop-By-Hop extension headers
Begin add support for parsing extension headers.

Closes: #212
Approved by: whitequark
2018-05-27 16:14:29 +08:00
Dan Robertson 42a1da4d72 Improve IPv6 options parsing
- Do not require the packet structure of the header have the same
    lifetime as the underlying bytes or the parsed representation.
  - Add the bytes of the contained options to the parsed representation
    structure.
  - Add the IPv6OptionsIterator structure to make iterating over the
    contained options easier.

Closes: #212
Approved by: whitequark
2018-05-27 16:14:29 +08:00
Dan Robertson be32144ba2 NDISC flags should be located in ndisc module
Closes: #212
Approved by: whitequark
2018-05-27 16:14:29 +08:00
Astro e5a3de210c Optimize RingBuffer::enqueue_many_with to an empty buffer.
This optimization makes sure that enqueueing to an empty ring buffer
would never wrap around, in turn ensuring that enqueueing to an empty
packet buffer would never use more than one metadata entry.
Right now, pushing buffer-sized packets into a packet buffer requires
at least two metadata entries, which is surprising and wasteful.
2018-05-24 22:00:00 +00:00
Herman J. Radtke III 053a6f36e5 CR fixes deux
Closes: #218
Approved by: whitequark
2018-05-23 05:51:21 +08:00
Herman J. Radtke III 4898d5ab2a CR fixes
Closes: #218
Approved by: whitequark
2018-05-23 05:51:21 +08:00
Herman J. Radtke III 9403f1bf23 Add IPv6 Extension Routing Header
Fixes #160

Closes: #218
Approved by: whitequark
2018-05-23 05:51:21 +08:00
Ole Martin Ruud f501198a68 Implement fast retransmit for TcpSocket
Implement a simple way to discover and respond to three duplicate ACKs
from the reciver of the data. This leads to a fast retransmit of the
last unacknowledged seqment. This is feature is described in [RFC 5681].

Closes: #104

Closes: #214
Approved by: whitequark
2018-05-18 00:40:47 +08:00
Ole Martin Ruud 9533e3ac17 Update the docstrings of PollAt
Closes: #214
Approved by: whitequark
2018-05-18 00:40:47 +08:00
Ole Martin Ruud 9694949172 Add conditional compile attr to `is_ingress`
Closes: #216
Approved by: whitequark
2018-05-17 06:17:47 +08:00
Ole Martin Ruud 0c59e3f5f9 Implement new type for `poll_at`
Change return-type for `poll_at` for sockets to be a `PollAt` instead of
the former `Option<Instant>`.

Closes: #216
Approved by: whitequark
2018-05-17 06:17:47 +08:00
whitequark ca743cba24 Fix format strings using time to not include extraneous ms suffix. 2018-05-15 14:49:53 +00:00
Valentin Lorentz a4e42880f8 Ignore unrecognized NDISC options (as per RFC 4861).
Closes: #210
Approved by: whitequark
2018-05-15 01:14:32 +08:00
Valentin Lorentz 2d716883b6 Add support for IPv6 gateways.
Closes: #207
Approved by: dlrobertson
2018-05-14 09:39:39 +08:00
Valentin Lorentz 2afc538fd9 Add support for IPv6 to ICMP sockets.
Closes: #205
Approved by: whitequark
2018-05-10 07:12:33 +08:00
Dan Robertson 435292cc35 wire: Add the FailureType for IPv6 ext hdr options
Add the FailureType enumeration that can be acquired from a IPv6
extension header option which determines the required action if the
extension header option type is not known or is not supported.

Closes: #204
Approved by: whitequark
2018-05-09 20:58:50 +08:00
Kai Lüke fada9d4e27 Update remote_last_win for all ACKs
Only ACKs generated by `dispatch` were updating
`remote_last_win` but not the ACKs generated by
`process`, failing to keep track of the last
announced receive window. This left
`window_to_update` to return false in `dispatch`
after the RX buffer was emptied, thus not announcing
that the receive window is not zero anymore.

The change updates `remote_last_win` for immediate
ACKs generated by `process`.

Closes: #200
Approved by: whitequark
2018-05-08 01:27:28 +08:00
Dan Robertson bed3d8bd4b Add Address Resolution for IPv6
Add Address Resolution via NDISC for IPv6.

Closes: #196
Approved by: whitequark
2018-05-07 23:49:56 +08:00
Dan Robertson 010e55beed Fix ICMPv6 checksum function
The ICMPv6 checksum calculation requires the pseudo header.

Closes: #196
Approved by: whitequark
2018-05-07 23:49:56 +08:00
whitequark 6067607442 Fix errors caused by an update to #[deny(unused)]. 2018-05-07 15:00:18 +00:00
Michal Podhradsky 0ce9f56c26 Do not export phy::wait on non-Unix platforms 2018-04-29 01:58:53 +00:00
Dan Robertson 867eb1b7f8 NDISC: Improve the representation layer for NDISC
Each given NDISC packet type may only include one of a few options.
Instead of including the options in the NDISC repr as a &[u8] include
the packet types available options as `Option<T>`.

Closes: #194
Approved by: whitequark
2018-04-21 00:33:41 +08:00
Dan Robertson 13fe5734ec Add Repr support for NDISC packets
Add Representation layer support for NDISC packets.
2018-04-20 11:09:11 +00:00
Dan Robertson e97b50419f Add Packet support for NDISC packet types
Add packet layer support for NDISC packet types.

Closes: #180
Approved by: whitequark
2018-04-12 14:04:50 +08:00
Adam Greig 96118d370d Use core::time::Duration. Closes #182.
Duration is now in core, so we can use that instead of conditional
compilation on std and std::time::Duration.

Closes: #189
Approved by: whitequark
2018-04-11 07:24:32 +08:00
Astro 00b66231e3 Fix DhcpOption::Other serialization. 2018-04-10 20:25:51 +00:00
whitequark 485b46a5e6 fn PacketMetadata::empty() → const PacketMetadata::EMPTY.
Fixes #181.
2018-03-24 03:23:37 +00:00
Dan Robertson bca0ff638b Add NDISC Option Type to wire
Add support for NDISC options parsing in wire.

Closes: #167
Approved by: whitequark
2018-03-12 06:08:58 +08:00
Corentin Henry 55e75fe85e document the dhcp packet representation (phil-opp/smoltcp#1)
Closes: #75
Approved by: whitequark
2018-03-12 02:29:21 +08:00
Philipp Oppermann 745df22709 Create a DHCP wire module
Closes: #75
Approved by: whitequark
2018-03-12 02:29:21 +08:00
Philipp Oppermann da7cffe533 Allow trailing commas in enum_with_unknown macro
Closes: #75
Approved by: whitequark
2018-03-12 02:29:21 +08:00
whitequark 6811a6bff1 Update Packet/Repr support table. 2018-03-11 18:18:31 +00:00
Andrew Cann cc8f45df40 Add EthernetRepr type 2018-03-11 18:17:20 +00:00
Astro 714602b948 Implement wire::igmp. 2018-03-11 18:08:08 +00:00
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