Compare commits

..

No commits in common. "26689a3003f1ad0e5f4c787614c65925b53db7c2" and "d3402e1f50d0e4690737cfb4c03eeaddcee6b617" have entirely different histories.

8 changed files with 51 additions and 58 deletions

View File

@ -1,6 +0,0 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.148.1/containers/rust/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends asciidoctor

View File

@ -1,35 +0,0 @@
{
"name": "Rust",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"rust-lang.rust",
"bungcip.better-toml",
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"asciidoctor.asciidoctor-vscode"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

View File

@ -2,10 +2,6 @@
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 => (false, false)
Type::Tun | Type::Dummy => (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::Tun,
device_type: Type::Dummy,
device_name: "".to_string(),
device_path: None,
fix_rp_filter: false,

View File

@ -51,14 +51,18 @@ pub enum Type {
Tun,
/// Tap interface: This interface transports Ethernet frames.
#[serde(rename = "tap")]
Tap
Tap,
/// Dummy interface: This interface does nothing.
#[serde(rename = "dummy")]
Dummy
}
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::Tap => write!(formatter, "tap"),
Type::Dummy => write!(formatter, "dummy")
}
}
}
@ -70,6 +74,7 @@ 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")
})
}
@ -139,10 +144,14 @@ 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::Tap => libc::IFF_TAP | libc::IFF_NO_PI,
Type::Dummy => unreachable!()
};
let mut ifreq = IfReq::new(ifname);
ifreq.data.flags = flags as libc::c_short;
@ -163,10 +172,33 @@ impl TunTapDevice {
#[inline]
pub fn default_path(type_: Type) -> &'static str {
match type_ {
Type::Tun | Type::Tap => "/dev/net/tun"
Type::Tun | Type::Tap => "/dev/net/tun",
Type::Dummy => "/dev/null"
}
}
/// 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) {}
@ -223,7 +255,7 @@ impl TunTapDevice {
+ 1 /* message type header */
+ match self.type_ {
Type::Tap => 14, /* inner ethernet header */
Type::Tun => 0
Type::Tun | Type::Dummy => 0
}
}
@ -325,7 +357,7 @@ impl MockDevice {
impl Device for MockDevice {
fn get_type(&self) -> Type {
Type::Tun
Type::Dummy
}
fn ifname(&self) -> &str {

View File

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

View File

@ -6,7 +6,7 @@ use crate::device::Device;
use std::{io, os::unix::io::RawFd};
use super::WaitResult;
use crate::net::Socket;
use crate::{device::Type, net::Socket};
pub struct EpollWait {
poll_fd: RawFd,
@ -31,10 +31,15 @@ impl EpollWait {
if poll_fd == -1 {
return Err(io::Error::last_os_error())
}
for fd in &[socket.as_raw_fd(), device.as_raw_fd()] {
event.u64 = *fd as u64;
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;
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())
}