New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the proto-ipv4 feature #98
Conversation
4125efe
to
0983635
Compare
src/socket/tcp.rs
Outdated
@@ -1488,6 +1488,7 @@ impl<'a> fmt::Write for TcpSocket<'a> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add pub(crate) const MOCK_IP_ADDRESS_1
in smoltcp::wire::ip::test
or something like this, it's not good to drop tests in IPv6...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the tests, I'm not sure how a set of mock IP addresses would work. So I added the ipv4
specific stuff in a ipv4_locals
module. Would the public mock IpAddress
be an IPv6
variant if proto-ipv6
was enabled and IPv4
if not? Or would we have a public collection of mock IPv4 addresses and a public collection of IPv6 addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the public mock IpAddress be an IPv6 variant if proto-ipv6 was enabled and IPv4 if not?
Yes
src/socket/udp.rs
Outdated
@@ -257,6 +257,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned elsewhere.
src/wire/tcp.rs
Outdated
@@ -853,6 +853,7 @@ impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned elsewhere.
src/wire/udp.rs
Outdated
@@ -281,6 +282,7 @@ impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned elsewhere.
@@ -21,7 +25,7 @@ use wire::{TcpPacket, TcpRepr, TcpControl}; | |||
use socket::{Socket, SocketSet, AnySocket}; | |||
#[cfg(feature = "socket-raw")] | |||
use socket::RawSocket; | |||
#[cfg(feature = "socket-icmp")] | |||
#[cfg(all(feature = "socket-icmp", feature = "proto-ipv4"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ICMP sockets should depend on proto-ipv4
. Sure, right now, since we don't have ICMPv6 at all, they would do nothing, but they should eventually be available, so let's keep them in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove this that would mean a build without default features and without proto-ipv4
but with proto-ipv6
would fail. If you're okay with that, I can simply remove this. Otherwise we need to make a generic IcmpRepr
/IcmpPacket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I've looked at making ICMP sockets work with ICMPv6 but it looks involved, so let's disable them on non-IPv4 builds for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll create an issue for this and https://github.com/dlrobertson/smoltcp/blob/proto-ipv4/src/lib.rs#L4-L5
src/iface/neighbor.rs
Outdated
@@ -156,6 +156,7 @@ impl<'a> Cache<'a> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described elsewhere.
src/socket/raw.rs
Outdated
@@ -240,6 +243,7 @@ impl<'a, 'b> RawSocket<'a, 'b> { | |||
} | |||
|
|||
#[cfg(test)] | |||
#[cfg(feature = "proto-ipv4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described elsewhere.
I've revised |
👍 I'll rebase and force push |
22f5dc8
to
1659155
Compare
- Users should be able to choose to use smoltcp without IPv4 support. - Add MOCK_IP_ADDR_* to wire::ip::test for testers to use.
1659155
to
550bc95
Compare
Updated. I added the mock addrs to BTW the |
Cargo.toml
Outdated
default = [ | ||
"std", "log", # needed for `cargo test --no-default-features --features default` :/ | ||
"phy-raw_socket", "phy-tap_interface", | ||
"phy-raw_socket", "phy-tap_interface", "proto-ipv4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should enable both in the default features, just like we enable all kinds of sockets.
src/iface/ethernet.rs
Outdated
_ => unreachable!() | ||
#[cfg(feature = "proto-ipv6")] | ||
IpRepr::Ipv6(_) => frame.set_ethertype(EthernetProtocol::Ipv6), | ||
_ => { return; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: _ => return
#![deny(unsafe_code, unused)] | ||
#![deny(unsafe_code)] | ||
// TODO: Change this to enable deny(unused) if IPv6 or IPv4 are enabled | ||
#![cfg_attr(feature = "proto-ipv4", deny(unused))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's holding up #![deny(unused)]
for IPv6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using it in EthernetInterface
. Things like Packet
and cmp
are unused at the moment when only IPv6 is enabled
Users should be able to choose to use smoltcp without IPv4 support.
Fixes: #76