Skip to content
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

Merged
merged 5 commits into from Dec 24, 2017
Merged

Conversation

dlrobertson
Copy link
Collaborator

@dlrobertson dlrobertson commented Dec 22, 2017

Users should be able to choose to use smoltcp without IPv4 support.

Fixes: #76

@dlrobertson dlrobertson mentioned this pull request Dec 22, 2017
3 tasks
@dlrobertson dlrobertson force-pushed the proto-ipv4 branch 2 times, most recently from 4125efe to 0983635 Compare December 22, 2017 02:52
@@ -1488,6 +1488,7 @@ impl<'a> fmt::Write for TcpSocket<'a> {
}

#[cfg(test)]
#[cfg(feature = "proto-ipv4")]
Copy link
Contributor

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...

Copy link
Collaborator Author

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.

Copy link
Contributor

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

@@ -257,6 +257,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
}

#[cfg(test)]
#[cfg(feature = "proto-ipv4")]
Copy link
Contributor

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")]
Copy link
Contributor

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")]
Copy link
Contributor

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"))]
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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

@@ -156,6 +156,7 @@ impl<'a> Cache<'a> {
}

#[cfg(test)]
#[cfg(feature = "proto-ipv4")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described elsewhere.

@@ -240,6 +243,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
}

#[cfg(test)]
#[cfg(feature = "proto-ipv4")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described elsewhere.

@whitequark
Copy link
Contributor

I've revised required-features even further and added them upstream, so you can discard my commit here.

@dlrobertson
Copy link
Collaborator Author

I've revised required-features even further and added them upstream, so you can discard my commit here.

👍 I'll rebase and force push

@dlrobertson dlrobertson force-pushed the proto-ipv4 branch 7 times, most recently from 22f5dc8 to 1659155 Compare December 24, 2017 01:46
 - Users should be able to choose to use smoltcp without IPv4 support.
 - Add MOCK_IP_ADDR_* to wire::ip::test for testers to use.
@dlrobertson
Copy link
Collaborator Author

Updated. I added the mock addrs to wire::ip::test. I did not update the RawSocket or IcmpSocket tests because we should have both IPv4 and IPv6 tests for RawSockets and IcmpSocket does not support IPv6 at the moment.

BTW the test_like_travis.rb script is a lifesaver.

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",
Copy link
Contributor

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.

_ => unreachable!()
#[cfg(feature = "proto-ipv6")]
IpRepr::Ipv6(_) => frame.set_ethertype(EthernetProtocol::Ipv6),
_ => { return; }
Copy link
Contributor

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))]
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@whitequark whitequark merged commit 507d2fe into smoltcp-rs:master Dec 24, 2017
@dlrobertson dlrobertson deleted the proto-ipv4 branch December 24, 2017 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants