Rename proto-* features back to socket-*.
A proto-* feature does not make sense for ICMP, where the protocol is always enabled, but sockets, not.v0.7.x
parent
c2994b9757
commit
d9fa7f6bc6
16
.travis.yml
16
.travis.yml
|
@ -10,21 +10,21 @@ matrix:
|
|||
- rust: nightly
|
||||
env: FEATURES='default' MODE='test'
|
||||
- rust: nightly
|
||||
env: FEATURES='phy-raw_socket proto-udp' MODE='build'
|
||||
env: FEATURES='phy-raw_socket socket-udp' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='phy-tap_interface proto-udp' MODE='build'
|
||||
env: FEATURES='phy-tap_interface socket-udp' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-raw' MODE='build'
|
||||
env: FEATURES='socket-raw' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-udp' MODE='build'
|
||||
env: FEATURES='socket-udp' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-tcp' MODE='build'
|
||||
env: FEATURES='socket-tcp' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-raw proto-udp proto-tcp' MODE='build'
|
||||
env: FEATURES='socket-raw socket-udp socket-tcp' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-raw proto-udp proto-tcp std' MODE='build'
|
||||
env: FEATURES='socket-raw socket-udp socket-tcp std' MODE='build'
|
||||
- rust: nightly
|
||||
env: FEATURES='proto-raw proto-udp proto-tcp alloc' MODE='build'
|
||||
env: FEATURES='socket-raw socket-udp socket-tcp alloc' MODE='build'
|
||||
script:
|
||||
- cargo "$MODE" --no-default-features --features "$FEATURES"
|
||||
notifications:
|
||||
|
|
|
@ -28,12 +28,12 @@ alloc = ["managed/alloc"]
|
|||
verbose = []
|
||||
"phy-raw_socket" = ["std", "libc"]
|
||||
"phy-tap_interface" = ["std", "libc"]
|
||||
"proto-raw" = []
|
||||
"proto-udp" = []
|
||||
"proto-tcp" = []
|
||||
"socket-raw" = []
|
||||
"socket-udp" = []
|
||||
"socket-tcp" = []
|
||||
default = ["std", "log",
|
||||
"phy-raw_socket", "phy-tap_interface",
|
||||
"proto-raw", "proto-udp", "proto-tcp"]
|
||||
"socket-raw", "socket-udp", "socket-tcp"]
|
||||
|
||||
[[example]]
|
||||
name = "tcpdump"
|
||||
|
|
|
@ -12,12 +12,18 @@ use wire::{IpAddress, IpProtocol, IpRepr, IpCidr};
|
|||
use wire::{ArpPacket, ArpRepr, ArpOperation};
|
||||
use wire::{Ipv4Packet, Ipv4Repr};
|
||||
use wire::{Icmpv4Packet, Icmpv4Repr, Icmpv4DstUnreachable};
|
||||
#[cfg(feature = "proto-udp")] use wire::{UdpPacket, UdpRepr};
|
||||
#[cfg(feature = "proto-tcp")] use wire::{TcpPacket, TcpRepr, TcpControl};
|
||||
#[cfg(feature = "socket-udp")]
|
||||
use wire::{UdpPacket, UdpRepr};
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
use wire::{TcpPacket, TcpRepr, TcpControl};
|
||||
|
||||
use socket::{Socket, SocketSet, AnySocket};
|
||||
#[cfg(feature = "proto-raw")] use socket::RawSocket;
|
||||
#[cfg(feature = "proto-udp")] use socket::UdpSocket;
|
||||
#[cfg(feature = "proto-tcp")] use socket::TcpSocket;
|
||||
#[cfg(feature = "socket-raw")]
|
||||
use socket::RawSocket;
|
||||
#[cfg(feature = "socket-udp")]
|
||||
use socket::UdpSocket;
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
use socket::TcpSocket;
|
||||
use super::ArpCache;
|
||||
|
||||
/// An Ethernet network interface.
|
||||
|
@ -50,11 +56,11 @@ enum Packet<'a> {
|
|||
None,
|
||||
Arp(ArpRepr),
|
||||
Icmpv4(Ipv4Repr, Icmpv4Repr<'a>),
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
Raw((IpRepr, &'a [u8])),
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
Udp((IpRepr, UdpRepr<'a>)),
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
Tcp((IpRepr, TcpRepr<'a>))
|
||||
}
|
||||
|
||||
|
@ -210,21 +216,21 @@ impl<'a, 'b, 'c, DeviceT> Interface<'a, 'b, 'c, DeviceT>
|
|||
let &mut Self { ref mut device, ref mut inner } = self;
|
||||
let socket_result =
|
||||
match *socket {
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
Socket::Raw(ref mut socket) =>
|
||||
socket.dispatch(|response| {
|
||||
let tx_token = device.transmit().ok_or(Error::Exhausted)?;
|
||||
device_result = inner.dispatch(tx_token, timestamp, Packet::Raw(response));
|
||||
device_result
|
||||
}, &caps.checksum),
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
Socket::Udp(ref mut socket) =>
|
||||
socket.dispatch(|response| {
|
||||
let tx_token = device.transmit().ok_or(Error::Exhausted)?;
|
||||
device_result = inner.dispatch(tx_token, timestamp, Packet::Udp(response));
|
||||
device_result
|
||||
}),
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
Socket::Tcp(ref mut socket) =>
|
||||
socket.dispatch(timestamp, &caps, |response| {
|
||||
let tx_token = device.transmit().ok_or(Error::Exhausted)?;
|
||||
|
@ -355,11 +361,11 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
let ip_repr = IpRepr::Ipv4(ipv4_repr);
|
||||
let ip_payload = ipv4_packet.payload();
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
let mut handled_by_raw_socket = false;
|
||||
|
||||
// Pass every IP packet to all raw sockets we have registered.
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
for mut raw_socket in sockets.iter_mut().filter_map(RawSocket::downcast) {
|
||||
if !raw_socket.accepts(&ip_repr) { continue }
|
||||
|
||||
|
@ -382,15 +388,15 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
IpProtocol::Icmp =>
|
||||
self.process_icmpv4(ipv4_repr, ip_payload),
|
||||
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
IpProtocol::Udp =>
|
||||
self.process_udp(sockets, ip_repr, ip_payload),
|
||||
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
IpProtocol::Tcp =>
|
||||
self.process_tcp(sockets, _timestamp, ip_repr, ip_payload),
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
_ if handled_by_raw_socket =>
|
||||
Ok(Packet::None),
|
||||
|
||||
|
@ -453,7 +459,7 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
fn process_udp<'frame>(&self, sockets: &mut SocketSet,
|
||||
ip_repr: IpRepr, ip_payload: &'frame [u8]) ->
|
||||
Result<Packet<'frame>>
|
||||
|
@ -493,7 +499,7 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
fn process_tcp<'frame>(&self, sockets: &mut SocketSet, timestamp: u64,
|
||||
ip_repr: IpRepr, ip_payload: &'frame [u8]) ->
|
||||
Result<Packet<'frame>>
|
||||
|
@ -550,13 +556,13 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
icmpv4_repr.emit(&mut Icmpv4Packet::new(payload), &checksum_caps);
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
Packet::Raw((ip_repr, raw_packet)) => {
|
||||
self.dispatch_ip(tx_token, timestamp, ip_repr, |_ip_repr, payload| {
|
||||
payload.copy_from_slice(raw_packet);
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
Packet::Udp((ip_repr, udp_repr)) => {
|
||||
self.dispatch_ip(tx_token, timestamp, ip_repr, |ip_repr, payload| {
|
||||
udp_repr.emit(&mut UdpPacket::new(payload),
|
||||
|
@ -564,7 +570,7 @@ impl<'b, 'c> InterfaceInner<'b, 'c> {
|
|||
&checksum_caps);
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
Packet::Tcp((ip_repr, mut tcp_repr)) => {
|
||||
let caps = self.device_capabilities.clone();
|
||||
self.dispatch_ip(tx_token, timestamp, ip_repr, |ip_repr, payload| {
|
||||
|
|
|
@ -69,9 +69,9 @@
|
|||
//! of a packet, it is still logged correctly and in full.
|
||||
|
||||
/* XXX compiler bug
|
||||
#![cfg(not(any(feature = "proto-raw",
|
||||
feature = "proto-udp",
|
||||
feature = "proto-tcp")))]
|
||||
#![cfg(not(any(feature = "socket-raw",
|
||||
feature = "socket-udp",
|
||||
feature = "socket-tcp")))]
|
||||
compile_error!("at least one socket needs to be enabled"); */
|
||||
|
||||
extern crate byteorder;
|
||||
|
|
|
@ -13,23 +13,26 @@
|
|||
use core::marker::PhantomData;
|
||||
use wire::IpRepr;
|
||||
|
||||
#[cfg(feature = "proto-raw")] mod raw;
|
||||
#[cfg(feature = "proto-udp")] mod udp;
|
||||
#[cfg(feature = "proto-tcp")] mod tcp;
|
||||
#[cfg(feature = "socket-raw")]
|
||||
mod raw;
|
||||
#[cfg(feature = "socket-udp")]
|
||||
mod udp;
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
mod tcp;
|
||||
mod set;
|
||||
mod ref_;
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
pub use self::raw::{PacketBuffer as RawPacketBuffer,
|
||||
SocketBuffer as RawSocketBuffer,
|
||||
RawSocket};
|
||||
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
pub use self::udp::{PacketBuffer as UdpPacketBuffer,
|
||||
SocketBuffer as UdpSocketBuffer,
|
||||
UdpSocket};
|
||||
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
pub use self::tcp::{SocketBuffer as TcpSocketBuffer,
|
||||
State as TcpState,
|
||||
TcpSocket};
|
||||
|
@ -52,11 +55,11 @@ pub(crate) use self::ref_::Session as SocketSession;
|
|||
/// [SocketSet::get]: struct.SocketSet.html#method.get
|
||||
#[derive(Debug)]
|
||||
pub enum Socket<'a, 'b: 'a> {
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
Raw(RawSocket<'a, 'b>),
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
Udp(UdpSocket<'a, 'b>),
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
Tcp(TcpSocket<'a>),
|
||||
#[doc(hidden)]
|
||||
__Nonexhaustive(PhantomData<(&'a (), &'b ())>)
|
||||
|
@ -65,11 +68,11 @@ pub enum Socket<'a, 'b: 'a> {
|
|||
macro_rules! dispatch_socket {
|
||||
($self_:expr, |$socket:ident [$( $mut_:tt )*]| $code:expr) => ({
|
||||
match $self_ {
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
&$( $mut_ )* Socket::Raw(ref $( $mut_ )* $socket) => $code,
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
&$( $mut_ )* Socket::Udp(ref $( $mut_ )* $socket) => $code,
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
&$( $mut_ )* Socket::Tcp(ref $( $mut_ )* $socket) => $code,
|
||||
&$( $mut_ )* Socket::__Nonexhaustive(_) => unreachable!()
|
||||
}
|
||||
|
@ -117,9 +120,9 @@ macro_rules! from_socket {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
from_socket!(RawSocket<'a, 'b>, Raw);
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
from_socket!(UdpSocket<'a, 'b>, Udp);
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
from_socket!(TcpSocket<'a>, Tcp);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
use socket::RawSocket;
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
use socket::UdpSocket;
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
use socket::TcpSocket;
|
||||
|
||||
/// A trait for tracking a socket usage session.
|
||||
|
@ -17,11 +17,11 @@ pub trait Session {
|
|||
fn finish(&mut self) {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
impl<'a, 'b> Session for RawSocket<'a, 'b> {}
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
impl<'a, 'b> Session for UdpSocket<'a, 'b> {}
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
impl<'a> Session for TcpSocket<'a> {}
|
||||
|
||||
/// A smart pointer to a socket.
|
||||
|
|
|
@ -2,7 +2,8 @@ use core::{fmt, slice};
|
|||
use managed::ManagedSlice;
|
||||
|
||||
use super::{Socket, SocketRef, AnySocket};
|
||||
#[cfg(feature = "proto-tcp")] use super::TcpState;
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
use super::TcpState;
|
||||
|
||||
/// An item of a socket set.
|
||||
///
|
||||
|
@ -140,13 +141,13 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
|
|||
let mut may_remove = false;
|
||||
if let &mut Some(Item { refs: 0, ref mut socket }) = item {
|
||||
match socket {
|
||||
#[cfg(feature = "proto-raw")]
|
||||
#[cfg(feature = "socket-raw")]
|
||||
&mut Socket::Raw(_) =>
|
||||
may_remove = true,
|
||||
#[cfg(feature = "proto-udp")]
|
||||
#[cfg(feature = "socket-udp")]
|
||||
&mut Socket::Udp(_) =>
|
||||
may_remove = true,
|
||||
#[cfg(feature = "proto-tcp")]
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
&mut Socket::Tcp(ref mut socket) =>
|
||||
if socket.state() == TcpState::Closed {
|
||||
may_remove = true
|
||||
|
|
Loading…
Reference in New Issue