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 support for IPv6 gateway, and use it to make examples IPv6-capable #207

Closed
wants to merge 1 commit into from

Conversation

progval
Copy link
Contributor

@progval progval commented May 10, 2018

Also contains a fix to #205 (Protocol::Icmp -> Protocol::Icmpv6).

Both examples were tested on my computer with both IP versions.

Instructions in the README should work, but they are a summary of a lot of trial-and-error to configure my computer so some command(s) might be missing.

examples/ping.rs Outdated

macro_rules! get_icmp_pong {
( $repr_type:ident, $repr:expr, $payload:expr, $waiting_queue:expr, $remote_addr:expr,
$timestamp:expr, $received:expr) => {{
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: whitespace.

examples/ping.rs Outdated
Ipv4Address, Icmpv4Repr, Icmpv4Packet};
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
use smoltcp::socket::{SocketSet, IcmpSocket, IcmpSocketBuffer, IcmpPacketMetadata, IcmpEndpoint};
use std::collections::HashMap;
use byteorder::{ByteOrder, NetworkEndian};

macro_rules! send_icmp_ping {
( $repr_type:ident, $packet_type:ident, $ident:expr, $seq_no:expr, $echo_payload:expr,
$socket:expr, $remote_addr:expr, $device_caps:expr ) => {{
Copy link
Collaborator

Choose a reason for hiding this comment

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

device_caps isn't used and what is the purpose of the double {?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to remove device_caps after an intermediate version.

The first { is part of the macro_rules! syntax, the second one means it's a block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to remove device_caps after an intermediate version.

The first { is part of the macro_rules! syntax, the second one means it's a block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah right, because the body is essentially a rvalue.

@@ -65,6 +65,8 @@ struct InterfaceInner<'b, 'c> {
ip_addrs: ManagedSlice<'c, IpCidr>,
#[cfg(feature = "proto-ipv4")]
ipv4_gateway: Option<Ipv4Address>,
#[cfg(feature = "proto-ipv6")]
ipv6_gateway: Option<Ipv6Address>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works for now, but we really need to add support for NDISC Router Advertisements and Solicitations. In IPv6 this should actually be default_routes or something like that, where some could have been statically assigned and some could have been dynamically acquired via a Router Advertisement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I added support for routes, to both IPv4 and IPv6.

neighbor_cache: NeighborCache<'b>,
ethernet_addr: EthernetAddress,
ip_addrs: ManagedSlice<'c, IpCidr>,
#[cfg(feature = "proto-ipv4")]
ipv4_gateway: Option<Ipv4Address>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like the idea of working on routing, but anything having to do with routes should probably be a separate PR.

@progval
Copy link
Contributor Author

progval commented May 11, 2018 via email

@dlrobertson
Copy link
Collaborator

I could remove the commits with routes, and put them in a new PR

Yeah, I think that would probably be better.

@progval
Copy link
Contributor Author

progval commented May 11, 2018 via email

let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24)];
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24),
IpCidr::new(IpAddress::v6(0xfd80, 0, 0, 0, 0, 0, 0, 1), 64),
IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line is repeated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, one is link-local (fe80::), the other is not (fd80::)

Copy link
Collaborator

Choose a reason for hiding this comment

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

My bad.

examples/ping.rs Outdated
let src_ipv6 = IpAddress::v6(0xfd80, 0, 0, 0, 0, 0, 0, 1);
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24),
IpCidr::new(src_ipv6, 64),
IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the same address as src_ipv6 right?

README.md Outdated
@@ -190,13 +190,19 @@ a specific user:
sudo ip tuntap add name tap0 mode tap user $USER
sudo ip link set tap0 up
sudo ip addr add 192.168.69.100/24 dev tap0
sudo ip -6 addr add fe80::100/64 dev tap0
sudo ip -6 addr add fd80::100/64 dev tap0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Address listed twice (for real this time 😄)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh I'm wrong again! The fe -> fd keeps confusing me lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think I should use a different prefix to make it clearer? (eg. fdaa::/64)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, that would be great! Could you also squash your commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
sudo ip -6 addr add fe80::100/64 dev tap0
sudo ip -6 addr add fd80::100/64 dev tap0
sudo ip -6 route fe80::/64 dev tap0
sudo ip -6 route fd80::/64 dev tap0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same. This command also fails for me. Did you mean ip -6 route add default via ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I forgot the add after route

let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24)];
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24),
IpCidr::new(IpAddress::v6(0xfd80, 0, 0, 0, 0, 0, 0, 1), 64),
IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

My bad.

@dlrobertson
Copy link
Collaborator

Looks good once the route command is fixed. Thanks for working on this!

@dlrobertson
Copy link
Collaborator

@m-labs-homu r+

@m-labs-homu
Copy link

📌 Commit c08b8b5 has been approved by dlrobertson

@m-labs-homu
Copy link

⌛ Testing commit c08b8b5 with merge 4bf917c...

@whitequark
Copy link
Contributor

@dlrobertson Thank you for reviewing this! I am very happy with how the code turned out, and even more so that I have been freed to do something else :D

@dlrobertson
Copy link
Collaborator

I am very happy with how the code turned out

@progval thanks for sticking with it! Sorry for criticizing you for duplicating lines so many times 😆 Also could you open up an RFC issue of sorts before you create a PR for multiple routes. I think some time spent discussing a design could be useful.

@m-labs-homu
Copy link

☀️ Test successful - status-travis
Approved by: dlrobertson
Pushing 4bf917c to master...

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

4 participants