smoltcp-rs/smoltcp

Bug in IPv6 source address selection (#864) prevents sending packets to localhost to localhost

samueljero opened this issue · 1 comments

In particular, given an interface with only the IPv6 localhost address, it is not possible to send packets to one's self. If sending ICMP packets, smoltcp panics:

(this is version 0.11, but master has the same bug)

panicked at smoltcp-0.11.0/src/iface/interface/mod.rs:882:14:
called `Option::unwrap()` on a `None` value

This appears to result from a bug in #864, where localhost addresses are never considered for sending packets:

// Loopback addresses and multicast address can not be in the candidate source address
// list. Except when the destination multicast address has a link-local scope, then the
// source address can also be link-local multicast.
if src_addr.is_loopback() || src_addr.is_multicast() {
return false;
}

Presumably this should have an exception for when the destination address is localhost.

Note that this only effects unbound sockets, as the IPv6 source address selection algorithm is not run for bound sockets.

Thank you for reporting this! The loopback address should be in the candidate list of source addresses. I think line 45 should be src_addr.unspecified() instead of src_addr.is_loopback(), as line 45 covers the following in RFC6724:

In any case, multicast addresses and the unspecified address MUST NOT
be included in a candidate set.

I'll fix this and add more tests for the source address selection.