Skip to content

Commit

Permalink
net: move tuntap from std example to separate crate. (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio authored Aug 3, 2023
1 parent 2c96fe9 commit 4d60c71
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
19 changes: 19 additions & 0 deletions embassy-net-tuntap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "embassy-net-tuntap"
version = "0.1.0"
description = "embassy-net driver for Linux TUN/TAP interfaces."
keywords = ["embedded", "tuntap", "embassy-net", "embedded-hal-async", "ethernet", "async"]
categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"]
license = "MIT OR Apache-2.0"
edition = "2021"

[dependencies]
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
async-io = "1.6.0"
log = "0.4.14"
libc = "0.2.101"

[package.metadata.embassy_docs]
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-tuntap-v$VERSION/embassy-net-tuntap/src/"
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-tuntap/src/"
target = "thumbv7em-none-eabi"
17 changes: 17 additions & 0 deletions embassy-net-tuntap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `embassy-net` integration for Linux TUN/TAP interfaces.

[`embassy-net`](https://crates.io/crates/embassy-net) integration for for Linux TUN (IP medium) and TAP (Ethernet medium) interfaces.

## Interoperability

This crate can run on any executor.

## License

This work is licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ETHERNET_HEADER_LEN: usize = 14;

#[repr(C)]
#[derive(Debug)]
#[allow(non_camel_case_types)]
struct ifreq {
ifr_name: [libc::c_char; libc::IF_NAMESIZE],
ifr_data: libc::c_int, /* ifr_ifindex or ifr_mtu */
Expand Down
3 changes: 1 addition & 2 deletions examples/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["lo
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] }
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "std", "nightly"] }
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dns", "dhcpv4", "unstable-traits", "proto-ipv6"] }
embassy-net-driver = { version = "0.1.0", path = "../../embassy-net-driver" }
embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" }
embedded-io = { version = "0.4.0", features = ["async", "std", "futures"] }
critical-section = { version = "1.1", features = ["std"] }

Expand All @@ -18,7 +18,6 @@ env_logger = "0.9.0"
futures = { version = "0.3.17" }
log = "0.4.14"
nix = "0.26.2"
libc = "0.2.101"
clap = { version = "3.0.0-beta.5", features = ["derive"] }
rand_core = { version = "0.6.3", features = ["std"] }
heapless = { version = "0.7.5", default-features = false }
Expand Down
5 changes: 1 addition & 4 deletions examples/std/src/bin/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::tcp::TcpSocket;
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use embassy_net_tuntap::TunTapDevice;
use embassy_time::Duration;
use embedded_io::asynch::Write;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::{make_static, StaticCell};

#[path = "../tuntap.rs"]
mod tuntap;

use crate::tuntap::TunTapDevice;
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
Expand Down
5 changes: 1 addition & 4 deletions examples/std/src/bin/net_dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::dns::DnsQueryType;
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use embassy_net_tuntap::TunTapDevice;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::{make_static, StaticCell};

#[path = "../tuntap.rs"]
mod tuntap;

use crate::tuntap::TunTapDevice;
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
Expand Down
5 changes: 1 addition & 4 deletions examples/std/src/bin/net_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::udp::{PacketMetadata, UdpSocket};
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use embassy_net_tuntap::TunTapDevice;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::{make_static, StaticCell};

#[path = "../tuntap.rs"]
mod tuntap;

use crate::tuntap::TunTapDevice;
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
Expand Down
5 changes: 1 addition & 4 deletions examples/std/src/bin/tcp_accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::tcp::TcpSocket;
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use embassy_net_tuntap::TunTapDevice;
use embassy_time::{Duration, Timer};
use embedded_io::asynch::Write as _;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::{make_static, StaticCell};

#[path = "../tuntap.rs"]
mod tuntap;

use crate::tuntap::TunTapDevice;
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
Expand Down

0 comments on commit 4d60c71

Please sign in to comment.