Remove dummy device type

pull/117/head
Dennis Schwerdel 2020-11-28 23:47:43 +01:00
parent d3402e1f50
commit ea049e4a4c
6 changed files with 17 additions and 51 deletions

View File

@ -2,6 +2,10 @@
This project follows [semantic versioning](http://semver.org).
### UNRELEASED
- [removed] Removed dummy device type
### v2.0.1 (2020-11-07)
- [changed] Changed documentation

View File

@ -106,7 +106,7 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
Mode::Normal => {
match config.device_type {
Type::Tap => (true, true),
Type::Tun | Type::Dummy => (false, false)
Type::Tun => (false, false)
}
}
Mode::Router => (false, false),

View File

@ -589,7 +589,7 @@ statsd:
#[test]
fn default_config_as_default() {
let mut default_config = Config {
device_type: Type::Dummy,
device_type: Type::Tun,
device_name: "".to_string(),
device_path: None,
fix_rp_filter: false,

View File

@ -51,18 +51,14 @@ pub enum Type {
Tun,
/// Tap interface: This interface transports Ethernet frames.
#[serde(rename = "tap")]
Tap,
/// Dummy interface: This interface does nothing.
#[serde(rename = "dummy")]
Dummy
Tap
}
impl fmt::Display for Type {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
Type::Tun => write!(formatter, "tun"),
Type::Tap => write!(formatter, "tap"),
Type::Dummy => write!(formatter, "dummy")
Type::Tap => write!(formatter, "tap")
}
}
}
@ -74,7 +70,6 @@ impl FromStr for Type {
Ok(match &text.to_lowercase() as &str {
"tun" => Self::Tun,
"tap" => Self::Tap,
"dummy" => Self::Dummy,
_ => return Err("Unknown device type")
})
}
@ -144,14 +139,10 @@ impl TunTapDevice {
#[allow(clippy::useless_conversion)]
pub fn new(ifname: &str, type_: Type, path: Option<&str>) -> io::Result<Self> {
let path = path.unwrap_or_else(|| Self::default_path(type_));
if type_ == Type::Dummy {
return Self::dummy(ifname, path, type_)
}
let fd = fs::OpenOptions::new().read(true).write(true).open(path)?;
let flags = match type_ {
Type::Tun => libc::IFF_TUN | libc::IFF_NO_PI,
Type::Tap => libc::IFF_TAP | libc::IFF_NO_PI,
Type::Dummy => unreachable!()
Type::Tap => libc::IFF_TAP | libc::IFF_NO_PI
};
let mut ifreq = IfReq::new(ifname);
ifreq.data.flags = flags as libc::c_short;
@ -172,33 +163,10 @@ impl TunTapDevice {
#[inline]
pub fn default_path(type_: Type) -> &'static str {
match type_ {
Type::Tun | Type::Tap => "/dev/net/tun",
Type::Dummy => "/dev/null"
Type::Tun | Type::Tap => "/dev/net/tun"
}
}
/// Creates a dummy device based on an existing file
///
/// This method opens a regular or special file and reads from it to receive packets and
/// writes to it to send packets. This method does not use a networking device and therefore
/// can be used for testing.
///
/// The parameter `path` is the file that should be used. Special files like `/dev/null`,
/// named pipes and unix sockets can be used with this method.
///
/// Both `ifname` and `type_` parameters have no effect.
///
/// # Errors
/// This method will return an error if the file can not be opened for reading and writing.
#[allow(dead_code)]
pub fn dummy(ifname: &str, path: &str, type_: Type) -> io::Result<Self> {
Ok(TunTapDevice {
fd: fs::OpenOptions::new().create(true).read(true).write(true).open(path)?,
ifname: ifname.to_string(),
type_
})
}
#[cfg(any(target_os = "linux", target_os = "android"))]
#[inline]
fn correct_data_after_read(&mut self, _buffer: &mut MsgBuffer) {}
@ -255,7 +223,7 @@ impl TunTapDevice {
+ 1 /* message type header */
+ match self.type_ {
Type::Tap => 14, /* inner ethernet header */
Type::Tun | Type::Dummy => 0
Type::Tun => 0
}
}
@ -357,7 +325,7 @@ impl MockDevice {
impl Device for MockDevice {
fn get_type(&self) -> Type {
Type::Dummy
Type::Tun
}
fn ifname(&self) -> &str {

View File

@ -286,7 +286,6 @@ fn main() {
debug!("Config: {:?}", config);
match config.device_type {
Type::Tap => run::<payload::Frame>(config),
Type::Tun => run::<payload::Packet>(config),
Type::Dummy => run::<payload::Frame>(config)
Type::Tun => run::<payload::Packet>(config)
}
}

View File

@ -6,7 +6,7 @@ use crate::device::Device;
use std::{io, os::unix::io::RawFd};
use super::WaitResult;
use crate::{device::Type, net::Socket};
use crate::net::Socket;
pub struct EpollWait {
poll_fd: RawFd,
@ -31,15 +31,10 @@ impl EpollWait {
if poll_fd == -1 {
return Err(io::Error::last_os_error())
}
let raw_fds = if device.get_type() != Type::Dummy {
vec![socket.as_raw_fd(), device.as_raw_fd()]
} else {
vec![socket.as_raw_fd()]
};
for fd in raw_fds {
event.u64 = fd as u64;
for fd in &[socket.as_raw_fd(), device.as_raw_fd()] {
event.u64 = *fd as u64;
event.events = flags;
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, fd, &mut event) };
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, *fd, &mut event) };
if res == -1 {
return Err(io::Error::last_os_error())
}