tun_easytier/platform/linux/mod.rs
1// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2// Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13// 0. You just DO WHAT THE FUCK YOU WANT TO.
14
15//! Linux specific functionality.
16
17pub mod sys;
18
19mod device;
20pub use self::device::Device;
21
22use crate::configuration::Configuration;
23use crate::error::Result;
24
25/// Linux-only interface configuration.
26#[derive(Copy, Clone, Debug)]
27pub struct PlatformConfig {
28 /// switch of Enable/Disable packet information for network driver
29 pub(crate) packet_information: bool,
30 /// root privileges required or not
31 pub(crate) ensure_root_privileges: bool,
32}
33
34/// `packet_information` is default to be `false` and `ensure_root_privileges` is default to be `true`.
35impl Default for PlatformConfig {
36 fn default() -> Self {
37 PlatformConfig {
38 packet_information: false,
39 ensure_root_privileges: true,
40 }
41 }
42}
43
44impl PlatformConfig {
45 /// Enable or disable packet information, the first 4 bytes of
46 /// each packet delivered from/to Linux underlying API is a header with flags and protocol type when enabled.
47 ///
48 /// [Note: This configuration just applies to the Linux underlying API and is a no-op on tun2(i.e. the packets delivered from/to tun2 always contain no packet information) -- end note].
49 #[deprecated(
50 since = "1.0.0",
51 note = "No effect applies to the packets delivered from/to tun2 since the packets always contain no header on all platforms."
52 )]
53 pub fn packet_information(&mut self, value: bool) -> &mut Self {
54 self.packet_information = value;
55 self
56 }
57
58 /// Indicated whether tun2 running in root privilege,
59 /// since some operations need it such as assigning IP/netmask/destination etc.
60 pub fn ensure_root_privileges(&mut self, value: bool) -> &mut Self {
61 self.ensure_root_privileges = value;
62 self
63 }
64}
65
66/// Create a TUN device with the given name.
67pub fn create(configuration: &Configuration) -> Result<Device> {
68 Device::new(configuration)
69}