diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-08-03 14:23:11 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-03 14:23:11 +0200 |
| commit | 4d60c715e683aaadf25d9f066bde805c725fefb4 (patch) | |
| tree | d3601429cef8850fba4a99df0e148da19fd96efc | |
| parent | 2c96fe917de6e0120053e80d8da5a98d0d0f35d0 (diff) | |
net: move tuntap from std example to separate crate. (#1737)
| -rw-r--r-- | embassy-net-tuntap/Cargo.toml | 19 | ||||
| -rw-r--r-- | embassy-net-tuntap/README.md | 17 | ||||
| -rw-r--r-- | embassy-net-tuntap/src/lib.rs (renamed from examples/std/src/tuntap.rs) | 1 | ||||
| -rw-r--r-- | examples/std/Cargo.toml | 3 | ||||
| -rw-r--r-- | examples/std/src/bin/net.rs | 5 | ||||
| -rw-r--r-- | examples/std/src/bin/net_dns.rs | 5 | ||||
| -rw-r--r-- | examples/std/src/bin/net_udp.rs | 5 | ||||
| -rw-r--r-- | examples/std/src/bin/tcp_accept.rs | 5 |
8 files changed, 42 insertions, 18 deletions
diff --git a/embassy-net-tuntap/Cargo.toml b/embassy-net-tuntap/Cargo.toml new file mode 100644 index 000000000..08d309680 --- /dev/null +++ b/embassy-net-tuntap/Cargo.toml | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-net-tuntap" | ||
| 3 | version = "0.1.0" | ||
| 4 | description = "embassy-net driver for Linux TUN/TAP interfaces." | ||
| 5 | keywords = ["embedded", "tuntap", "embassy-net", "embedded-hal-async", "ethernet", "async"] | ||
| 6 | categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] | ||
| 7 | license = "MIT OR Apache-2.0" | ||
| 8 | edition = "2021" | ||
| 9 | |||
| 10 | [dependencies] | ||
| 11 | embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" } | ||
| 12 | async-io = "1.6.0" | ||
| 13 | log = "0.4.14" | ||
| 14 | libc = "0.2.101" | ||
| 15 | |||
| 16 | [package.metadata.embassy_docs] | ||
| 17 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-tuntap-v$VERSION/embassy-net-tuntap/src/" | ||
| 18 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-tuntap/src/" | ||
| 19 | target = "thumbv7em-none-eabi" \ No newline at end of file | ||
diff --git a/embassy-net-tuntap/README.md b/embassy-net-tuntap/README.md new file mode 100644 index 000000000..c5d9e746c --- /dev/null +++ b/embassy-net-tuntap/README.md | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | # `embassy-net` integration for Linux TUN/TAP interfaces. | ||
| 2 | |||
| 3 | [`embassy-net`](https://crates.io/crates/embassy-net) integration for for Linux TUN (IP medium) and TAP (Ethernet medium) interfaces. | ||
| 4 | |||
| 5 | ## Interoperability | ||
| 6 | |||
| 7 | This crate can run on any executor. | ||
| 8 | |||
| 9 | ## License | ||
| 10 | |||
| 11 | This work is licensed under either of | ||
| 12 | |||
| 13 | - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or | ||
| 14 | http://www.apache.org/licenses/LICENSE-2.0) | ||
| 15 | - MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) | ||
| 16 | |||
| 17 | at your option. | ||
diff --git a/examples/std/src/tuntap.rs b/embassy-net-tuntap/src/lib.rs index 167c3da5f..75c54c487 100644 --- a/examples/std/src/tuntap.rs +++ b/embassy-net-tuntap/src/lib.rs | |||
| @@ -19,6 +19,7 @@ const ETHERNET_HEADER_LEN: usize = 14; | |||
| 19 | 19 | ||
| 20 | #[repr(C)] | 20 | #[repr(C)] |
| 21 | #[derive(Debug)] | 21 | #[derive(Debug)] |
| 22 | #[allow(non_camel_case_types)] | ||
| 22 | struct ifreq { | 23 | struct ifreq { |
| 23 | ifr_name: [libc::c_char; libc::IF_NAMESIZE], | 24 | ifr_name: [libc::c_char; libc::IF_NAMESIZE], |
| 24 | ifr_data: libc::c_int, /* ifr_ifindex or ifr_mtu */ | 25 | ifr_data: libc::c_int, /* ifr_ifindex or ifr_mtu */ |
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 42adede10..544176828 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -9,7 +9,7 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["lo | |||
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "std", "nightly"] } | 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "std", "nightly"] } |
| 11 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dns", "dhcpv4", "unstable-traits", "proto-ipv6"] } | 11 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dns", "dhcpv4", "unstable-traits", "proto-ipv6"] } |
| 12 | embassy-net-driver = { version = "0.1.0", path = "../../embassy-net-driver" } | 12 | embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } |
| 13 | embedded-io = { version = "0.4.0", features = ["async", "std", "futures"] } | 13 | embedded-io = { version = "0.4.0", features = ["async", "std", "futures"] } |
| 14 | critical-section = { version = "1.1", features = ["std"] } | 14 | critical-section = { version = "1.1", features = ["std"] } |
| 15 | 15 | ||
| @@ -18,7 +18,6 @@ env_logger = "0.9.0" | |||
| 18 | futures = { version = "0.3.17" } | 18 | futures = { version = "0.3.17" } |
| 19 | log = "0.4.14" | 19 | log = "0.4.14" |
| 20 | nix = "0.26.2" | 20 | nix = "0.26.2" |
| 21 | libc = "0.2.101" | ||
| 22 | clap = { version = "3.0.0-beta.5", features = ["derive"] } | 21 | clap = { version = "3.0.0-beta.5", features = ["derive"] } |
| 23 | rand_core = { version = "0.6.3", features = ["std"] } | 22 | rand_core = { version = "0.6.3", features = ["std"] } |
| 24 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 3aadb029d..e0de14162 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -6,6 +6,7 @@ use clap::Parser; | |||
| 6 | use embassy_executor::{Executor, Spawner}; | 6 | use embassy_executor::{Executor, Spawner}; |
| 7 | use embassy_net::tcp::TcpSocket; | 7 | use embassy_net::tcp::TcpSocket; |
| 8 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 8 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 9 | use embassy_net_tuntap::TunTapDevice; | ||
| 9 | use embassy_time::Duration; | 10 | use embassy_time::Duration; |
| 10 | use embedded_io::asynch::Write; | 11 | use embedded_io::asynch::Write; |
| 11 | use heapless::Vec; | 12 | use heapless::Vec; |
| @@ -13,10 +14,6 @@ use log::*; | |||
| 13 | use rand_core::{OsRng, RngCore}; | 14 | use rand_core::{OsRng, RngCore}; |
| 14 | use static_cell::{make_static, StaticCell}; | 15 | use static_cell::{make_static, StaticCell}; |
| 15 | 16 | ||
| 16 | #[path = "../tuntap.rs"] | ||
| 17 | mod tuntap; | ||
| 18 | |||
| 19 | use crate::tuntap::TunTapDevice; | ||
| 20 | #[derive(Parser)] | 17 | #[derive(Parser)] |
| 21 | #[clap(version = "1.0")] | 18 | #[clap(version = "1.0")] |
| 22 | struct Opts { | 19 | struct Opts { |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index 65b5a2cd9..6c19874d5 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -6,15 +6,12 @@ use clap::Parser; | |||
| 6 | use embassy_executor::{Executor, Spawner}; | 6 | use embassy_executor::{Executor, Spawner}; |
| 7 | use embassy_net::dns::DnsQueryType; | 7 | use embassy_net::dns::DnsQueryType; |
| 8 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 8 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 9 | use embassy_net_tuntap::TunTapDevice; | ||
| 9 | use heapless::Vec; | 10 | use heapless::Vec; |
| 10 | use log::*; | 11 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 12 | use rand_core::{OsRng, RngCore}; |
| 12 | use static_cell::{make_static, StaticCell}; | 13 | use static_cell::{make_static, StaticCell}; |
| 13 | 14 | ||
| 14 | #[path = "../tuntap.rs"] | ||
| 15 | mod tuntap; | ||
| 16 | |||
| 17 | use crate::tuntap::TunTapDevice; | ||
| 18 | #[derive(Parser)] | 15 | #[derive(Parser)] |
| 19 | #[clap(version = "1.0")] | 16 | #[clap(version = "1.0")] |
| 20 | struct Opts { | 17 | struct Opts { |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 3fc46156c..98dcc9925 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -4,15 +4,12 @@ use clap::Parser; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::udp::{PacketMetadata, UdpSocket}; | 5 | use embassy_net::udp::{PacketMetadata, UdpSocket}; |
| 6 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 6 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 7 | use embassy_net_tuntap::TunTapDevice; | ||
| 7 | use heapless::Vec; | 8 | use heapless::Vec; |
| 8 | use log::*; | 9 | use log::*; |
| 9 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::{make_static, StaticCell}; | 11 | use static_cell::{make_static, StaticCell}; |
| 11 | 12 | ||
| 12 | #[path = "../tuntap.rs"] | ||
| 13 | mod tuntap; | ||
| 14 | |||
| 15 | use crate::tuntap::TunTapDevice; | ||
| 16 | #[derive(Parser)] | 13 | #[derive(Parser)] |
| 17 | #[clap(version = "1.0")] | 14 | #[clap(version = "1.0")] |
| 18 | struct Opts { | 15 | struct Opts { |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index df09986ac..0c920a3fb 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -7,6 +7,7 @@ use clap::Parser; | |||
| 7 | use embassy_executor::{Executor, Spawner}; | 7 | use embassy_executor::{Executor, Spawner}; |
| 8 | use embassy_net::tcp::TcpSocket; | 8 | use embassy_net::tcp::TcpSocket; |
| 9 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 9 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 10 | use embassy_net_tuntap::TunTapDevice; | ||
| 10 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 11 | use embedded_io::asynch::Write as _; | 12 | use embedded_io::asynch::Write as _; |
| 12 | use heapless::Vec; | 13 | use heapless::Vec; |
| @@ -14,10 +15,6 @@ use log::*; | |||
| 14 | use rand_core::{OsRng, RngCore}; | 15 | use rand_core::{OsRng, RngCore}; |
| 15 | use static_cell::{make_static, StaticCell}; | 16 | use static_cell::{make_static, StaticCell}; |
| 16 | 17 | ||
| 17 | #[path = "../tuntap.rs"] | ||
| 18 | mod tuntap; | ||
| 19 | |||
| 20 | use crate::tuntap::TunTapDevice; | ||
| 21 | #[derive(Parser)] | 18 | #[derive(Parser)] |
| 22 | #[clap(version = "1.0")] | 19 | #[clap(version = "1.0")] |
| 23 | struct Opts { | 20 | struct Opts { |
