Skip to content

Commit

Permalink
Fixes to compile without feature proto-ipv6.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed May 9, 2018
1 parent 9d006a9 commit e9ea1b2
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 179 deletions.
27 changes: 24 additions & 3 deletions src/iface/ethernet.rs
Expand Up @@ -34,7 +34,7 @@ use wire::{TcpPacket, TcpRepr, TcpControl};
use socket::{Socket, SocketSet, AnySocket};
#[cfg(feature = "socket-raw")]
use socket::RawSocket;
#[cfg(all(feature = "socket-icmp", feature = "proto-ipv4"))]
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
use socket::IcmpSocket;
#[cfg(feature = "socket-udp")]
use socket::UdpSocket;
Expand Down Expand Up @@ -426,7 +426,7 @@ impl<'b, 'c, DeviceT> Interface<'b, 'c, DeviceT>
Socket::Raw(ref mut socket) =>
socket.dispatch(&caps.checksum, |response|
respond!(Packet::Raw(response))),
#[cfg(all(feature = "socket-icmp", feature = "proto-ipv4"))]
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
Socket::Icmp(ref mut socket) =>
socket.dispatch(&caps, |response| {
match response {
Expand Down Expand Up @@ -751,6 +751,23 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
let icmp_repr = Icmpv6Repr::parse(&ip_repr.src_addr(), &ip_repr.dst_addr(),
&icmp_packet, &checksum_caps)?;

#[cfg(feature = "socket-icmp")]
let mut handled_by_icmp_socket = false;

#[cfg(all(feature = "socket-icmp", feature = "proto-ipv6"))]
for mut icmp_socket in _sockets.iter_mut().filter_map(IcmpSocket::downcast) {
if !icmp_socket.accepts(&ip_repr, &icmp_repr.into(), &checksum_caps) { continue }

match icmp_socket.process(&ip_repr, &icmp_repr.into(), &checksum_caps) {
// The packet is valid and handled by socket.
Ok(()) => handled_by_icmp_socket = true,
// The socket buffer is full.
Err(Error::Exhausted) => (),
// ICMP sockets don't validate the packets in any way.
Err(_) => unreachable!(),
}
}

match icmp_repr {
// Respond to echo requests.
Icmpv6Repr::EchoRequest { ident, seq_no, data } => {
Expand All @@ -776,6 +793,11 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
_ => Ok(Packet::None)
},

// Don't report an error if a packet with unknown type
// has been handled by an ICMP socket
#[cfg(feature = "socket-icmp")]
_ if handled_by_icmp_socket => Ok(Packet::None),

// FIXME: do something correct here?
_ => Err(Error::Unrecognized),
}
Expand Down Expand Up @@ -872,7 +894,6 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
},

// Ignore any echo replies.
#[cfg(feature = "proto-ipv4")]
Icmpv4Repr::EchoReply { .. } => Ok(Packet::None),

// Don't report an error if a packet with unknown type
Expand Down

0 comments on commit e9ea1b2

Please sign in to comment.