aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-net-tuntap/src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/embassy-net-tuntap/src/lib.rs b/embassy-net-tuntap/src/lib.rs
index 75c54c487..de30934eb 100644
--- a/embassy-net-tuntap/src/lib.rs
+++ b/embassy-net-tuntap/src/lib.rs
@@ -1,3 +1,5 @@
1#![warn(missing_docs)]
2#![doc = include_str!("../README.md")]
1use std::io; 3use std::io;
2use std::io::{Read, Write}; 4use std::io::{Read, Write};
3use std::os::unix::io::{AsRawFd, RawFd}; 5use std::os::unix::io::{AsRawFd, RawFd};
@@ -7,12 +9,19 @@ use async_io::Async;
7use embassy_net_driver::{self, Capabilities, Driver, HardwareAddress, LinkState}; 9use embassy_net_driver::{self, Capabilities, Driver, HardwareAddress, LinkState};
8use log::*; 10use log::*;
9 11
12/// Get the MTU of the given interface.
10pub const SIOCGIFMTU: libc::c_ulong = 0x8921; 13pub const SIOCGIFMTU: libc::c_ulong = 0x8921;
14/// Get the index of the given interface.
11pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; 15pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933;
16/// Capture all packages.
12pub const _ETH_P_ALL: libc::c_short = 0x0003; 17pub const _ETH_P_ALL: libc::c_short = 0x0003;
18/// Set the interface flags.
13pub const TUNSETIFF: libc::c_ulong = 0x400454CA; 19pub const TUNSETIFF: libc::c_ulong = 0x400454CA;
20/// TUN device.
14pub const _IFF_TUN: libc::c_int = 0x0001; 21pub const _IFF_TUN: libc::c_int = 0x0001;
22/// TAP device.
15pub const IFF_TAP: libc::c_int = 0x0002; 23pub const IFF_TAP: libc::c_int = 0x0002;
24/// No packet information.
16pub const IFF_NO_PI: libc::c_int = 0x1000; 25pub const IFF_NO_PI: libc::c_int = 0x1000;
17 26
18const ETHERNET_HEADER_LEN: usize = 14; 27const ETHERNET_HEADER_LEN: usize = 14;
@@ -47,6 +56,7 @@ fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io:
47 Ok(ifreq.ifr_data) 56 Ok(ifreq.ifr_data)
48} 57}
49 58
59/// A TUN/TAP device.
50#[derive(Debug)] 60#[derive(Debug)]
51pub struct TunTap { 61pub struct TunTap {
52 fd: libc::c_int, 62 fd: libc::c_int,
@@ -60,6 +70,7 @@ impl AsRawFd for TunTap {
60} 70}
61 71
62impl TunTap { 72impl TunTap {
73 /// Create a new TUN/TAP device.
63 pub fn new(name: &str) -> io::Result<TunTap> { 74 pub fn new(name: &str) -> io::Result<TunTap> {
64 unsafe { 75 unsafe {
65 let fd = libc::open( 76 let fd = libc::open(
@@ -126,11 +137,13 @@ impl io::Write for TunTap {
126 } 137 }
127} 138}
128 139
140/// A TUN/TAP device, wrapped in an async interface.
129pub struct TunTapDevice { 141pub struct TunTapDevice {
130 device: Async<TunTap>, 142 device: Async<TunTap>,
131} 143}
132 144
133impl TunTapDevice { 145impl TunTapDevice {
146 /// Create a new TUN/TAP device.
134 pub fn new(name: &str) -> io::Result<TunTapDevice> { 147 pub fn new(name: &str) -> io::Result<TunTapDevice> {
135 Ok(Self { 148 Ok(Self {
136 device: Async::new(TunTap::new(name)?)?, 149 device: Async::new(TunTap::new(name)?)?,