Commit Graph

837 Commits (master)

Author SHA1 Message Date
Dario Nieuwenhuis 9ac2cac075 Add support for IP mediums.
- Add `medium` in `DeviceCapabilities`.
- Rename EthernetInterface to Interface.
- Add support to Interface for both Ethernet and IP mediums. The medium to use is detected from `device.capabilities().medium`.
- Ethernet-only features are gated behind the "ethernet" feature, as before.
- IP features are always enabled for now.
2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis 1a1741660a Fix "leftover tokens" macro error 2021-03-25 00:06:35 +01:00
Dario Nieuwenhuis f6259f8113 Merge branch 'master' into feature/dhcp-lease-updates 2021-03-24 03:26:42 +01:00
Dario Nieuwenhuis 79dfc7e97e Merge branch 'master' into fix-phywait 2021-03-24 03:13:13 +01:00
Dario Nieuwenhuis a576389340 Fix timeval in phy_wait for times greater than 1 second 2021-03-24 02:58:51 +01:00
Dario Nieuwenhuis 067eee1681 Merge branch 'master' into feature/dhcp-lease-updates 2021-03-24 02:56:21 +01:00
Dario Nieuwenhuis 8e86318a13 Fix feature-related compilation issues. 2021-03-24 02:28:55 +01:00
Dario Nieuwenhuis e40b1442ce Remove support table from docs. Fixes #361
The table is no longer very informative since it's all "yes" now.
2021-03-24 02:21:12 +01:00
Ryan Summers 881123f849 Removing lease expiration on reset - the lease does not expire 2021-03-18 16:26:44 +01:00
Ryan Summers 2851a135df Adding parsing test with lease time 2021-03-12 17:36:43 +01:00
Ryan Summers 39c3e7ef1f Updating control logic 2021-03-12 17:28:00 +01:00
Ryan Summers c491962b3f Refactoring retry mechanism 2021-03-12 16:14:44 +01:00
Ryan Summers 647e27ed2b Adding DHCP lease management 2021-03-12 14:03:51 +01:00
whitequark b1db516b10 Enable all Linux `phy` components for Android as well.
Fixes #433.
2021-03-12 06:31:05 +00:00
whitequark 9f0213765c Simplify enum_with_unknown! macro. 2021-03-12 06:15:34 +00:00
Dario Nieuwenhuis 4933a0a19f Merge pull request #431 from dnadlinger/patch-2
socket/tcp: Fix missing ` in doc comment
2021-03-07 07:58:04 +01:00
David Nadlinger b5eca87885 socket/tcp: Fix missing ` in doc comment 2021-03-07 04:14:10 +00:00
David Nadlinger 3fb05f0857 socket/tcp: Fix is_active comment typo 2021-03-07 04:09:44 +00:00
Nathan K. Zhinn 4ac265fb46 Fix BPF header length on OpenBSD.
The actual header length may be larger than the bpf_hdr struct due to aligning:
37ecb4d066/sys/net/bpf.c (L1649)
8f02f2a044/bsd/net/bpf.c (L3580)

Tests are only valid for 32 and 64 bit architectures. I did not bother
guarding them with additional cfg flags.
2021-03-01 04:37:37 +00:00
Dario Nieuwenhuis 5388ef1f1d Merge pull request #419 from vkrasnov/vlad/solicit_dst
Ask for dst_addr in neighbor solicitation request
2021-02-20 13:03:47 +01:00
whitequark 9f51548f4d Merge pull request #421 from pk-j-xyz/openbsd-bpf
Fix bpf ffi and add OpenBSD bpf cfg
2021-02-18 01:30:12 +00:00
Nathan K. Zhinn 019653b0cf Fix bpf ffi and add OpenBSD bpf cfg
This fixes the ordering that was causing a dealloc before the FFI call
to libc open.
2021-02-17 15:11:56 +00:00
Ben Stabler 335099aa26 Silence clippy lint for const assert work-around, remove const where using features not yet stable in 1.40 2021-02-11 23:10:35 -08:00
Ben Stabler 851d26aaa6 Make wire/ipv4 functions const where possible. 2021-02-11 22:49:33 -08:00
Vlad Krasnov c6f7163638 Ask for dst_addr in neighbor solicitation request 2021-02-09 14:07:57 -05:00
Dario Nieuwenhuis 857c012f14 Fix build when with no socket features 2021-02-01 16:45:32 +01:00
Dario Nieuwenhuis 8da202ff7f Simplify EthernetInterface lifetimes. 2021-01-19 22:59:52 +01:00
Dario Nieuwenhuis 02a80a6000 Simplify SocketSet lifetimes 2021-01-19 22:45:15 +01:00
Dario Nieuwenhuis af2eb5a454 Clarify docs of DeviceCapabilities MTU. Fixes #392 2021-01-19 22:20:40 +01:00
Scott Mabin 47d27472b9 subnet_broadcasts
Adds `is_subnet_broadcast` to the ethernet interface which checks for
subnet broadcasts, which are discussed on page 8 in
https://tools.ietf.org/html/rfc917. The subnet broadcast addresses are
derived from the interfaces ipv4 addresses.
2021-01-16 15:36:27 +00:00
Alex Crawford 0cf0a7e386 Clean up clippy warnings about if-else blocks
This de-duplicates and (hopefully) simplifies a few if-else blocks. The
others were given an exception because I thought they were more readable
as is. I've verified that these changes don't result in larger binaries.
2021-01-10 14:30:31 -08:00
Alex Crawford 06d128ad22 Use #[non_exhaustive] on structs as well
This builds on 633e7c25, adding the #[non_exhaustive] attribute to
applicable struct definitions.
2021-01-10 13:54:29 -08:00
Niclas Hoyer ad7795f996 Use #[non_exhaustive] instead of manual variant 2021-01-09 02:06:00 +01:00
Dario Nieuwenhuis c09ca370b2 Simplify Socket lifetimes 2021-01-09 01:59:02 +01:00
Dario Nieuwenhuis 2ea2b7ff6b tcp: add Delayed ACK 2021-01-07 00:21:55 +01:00
Alex Crawford cb66f9f036 Allow DeviceCapabilities to be initialized
This was flagged by `cargo clippy`:

    warning: field assignment outside of initializer for an instance
             created with Default::default()

This changes the visibility of the dummy field to be public, but only to
the crate.
2021-01-04 10:39:33 -08:00
Alex Crawford 6b524dc74d Various cleanups
These were flagged by `cargo clippy`:

    warning: using `clone` on a `Copy` type
    warning: passing a unit value to a function
    warning: redundant closure found
    warning: called `iter().cloned().collect()` on a slice to create a
             `Vec`. Calling `to_vec()` is both faster and more readable
2021-01-04 10:39:06 -08:00
Dario Nieuwenhuis bb891ce7c1 tcp: Add RTT estimation. 2021-01-04 03:26:55 +01:00
Dario Nieuwenhuis 0752945161 Make some time funcs const. 2021-01-04 01:37:06 +01:00
Dario Nieuwenhuis 45df367d7e More clippy fixes. 2021-01-04 01:19:20 +01:00
Alex Crawford bc957da1ea Collapse redundant closure
This was flagged by `cargo clippy`:

    warning: redundant closure found
2020-12-28 23:31:17 -08:00
Alex Crawford 039a55e1bf Remove unnecessary clones
These were flagged by `cargo clippy`:

    warning: using `clone` on a `Copy` type
2020-12-28 23:20:21 -08:00
Alex Crawford 0e21e8524f Silence warning about mapping to unit type
This was flagged by `cargo clippy`:

    warning: called `map(f)` on an `Option` value where `f` is a closure
             that returns the unit type `()`

I decided to disable this because it was suggesting changes like the
following and I prefer the original:

    @@ -1 +1 @@
    -self.waker.take().map(|w| w.wake());
    +if let Some(w) = self.waker.take() { w.wake() }
2020-12-28 23:10:05 -08:00
Alex Crawford 27232041e7 Silence a few warnings from clippy
These were flagged by `cargo clippy`:

    warning: the operation is ineffective. Consider reducing it to `number`
    warning: this function has too many arguments (8/7)
    warning: you should consider adding a `Default` implementation for
             `phy::loopback::Loopback`

I like the code better as it is.
2020-12-28 23:09:53 -08:00
Alex Crawford 8a961b7d7c Use iterators instead of manually looping
These were flagged by `cargo clippy`:

    warning: the loop variable is used to index

I've verified that this doesn't increase the size of consuming binaries.
Pretty impressive. I tested this with a project that uses the following
features: ethernet, proto-dhcpv4, socket-tcp.
2020-12-28 22:28:07 -08:00
Alex Crawford 20c82238df Remove some unneeded imports and a variable
These were flagged by `cargo clippy`:

    warning: returning the result of a `let` binding from a block
    warning: this import is redundant
2020-12-28 22:28:06 -08:00
Alex Crawford fff5926210 Clean up a couple of if-blocks
These were flagged by `cargo clippy`:

    warning: this `else { if .. }` block can be collapsed
2020-12-28 22:27:24 -08:00
Alex Crawford e27f6cb564 Remove redundant field names from structs
These were flagged by `cargo clippy`:

    warning: redundant field names in struct initialization

There are plenty more redundant field names, but I only changed the ones
where the initialization was a single line of code. I still prefer the
redundant style for multi-line initializations (and I'm under the
impression that others agree), so I've also disabled the warning.
2020-12-28 22:27:24 -08:00
Dario Nieuwenhuis adce62a795 Merge pull request #398 from smoltcp-rs/simultaneous-close
tcp: fix racey simultaneous close not sending FIN.
2020-12-28 14:49:13 +01:00
Dario Nieuwenhuis f67097cf3f Merge pull request #399 from smoltcp-rs/medium-ip-part1
Add IP medium support, part 1
2020-12-28 14:31:33 +01:00
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