Skip to content

Commit

Permalink
builder: remove bool parameter of tap and packet_info
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 committed Sep 10, 2024
1 parent 0acb98c commit 96b0f1d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
name = "tokio-tun"
readme = "README.md"
repository = "https://github.com/yaa110/tokio-tun"
version = "0.11.5"
version = "0.12.0"

[dependencies]
libc = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ async fn main() {
let tun = Arc::new(
Tun::builder()
.name("") // if name is empty, then it is set by kernel.
.tap(false) // false (default): TUN, true: TAP.
.packet_info(false) // false: IFF_NO_PI, default is true.
.tap() // uses TAP instead of TUN (default).
.packet_info() // avoids setting IFF_NO_PI.
.up() // or set it up manually using `sudo ip link set <tun-name> up`.
.try_build() // or `.try_build_mq(queues)` for multi-queue support.
.unwrap(),
Expand Down
2 changes: 0 additions & 2 deletions examples/read-mq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ async fn main() {

let tuns = Tun::builder()
.name("")
.tap(false)
.packet_info(false)
.mtu(1350)
.up()
.address(Ipv4Addr::new(10, 0, 0, 1))
Expand Down
6 changes: 3 additions & 3 deletions examples/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ async fn main() {
let tun = Arc::new(
Tun::builder()
.name("")
.tap(false)
.packet_info(false)
.tap()
.packet_info()
.mtu(1350)
.up()
.address(Ipv4Addr::new(10, 0, 0, 1))
Expand All @@ -21,7 +21,7 @@ async fn main() {
);

println!("-----------");
println!("tun created");
println!("tap created");
println!("-----------");

println!(
Expand Down
10 changes: 5 additions & 5 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Default for TunBuilder {
persist: false,
up: false,
mtu: None,
packet_info: true,
packet_info: false,
address: None,
destination: None,
broadcast: None,
Expand Down Expand Up @@ -61,8 +61,8 @@ impl TunBuilder {
///
/// In contrast, *TUN* devices are layer 3 devices which means that IP packets are transmitted
/// over it.
pub fn tap(mut self, is_tap: bool) -> Self {
self.is_tap = is_tap;
pub fn tap(mut self) -> Self {
self.is_tap = true;
self
}

Expand All @@ -74,8 +74,8 @@ impl TunBuilder {
///
/// If you don't need this kind of information, you can set `packet_info` to false to only
/// receive the raw packet (whatever it may be).
pub fn packet_info(mut self, packet_info: bool) -> Self {
self.packet_info = packet_info;
pub fn packet_info(mut self) -> Self {
self.packet_info = true;
self
}

Expand Down

0 comments on commit 96b0f1d

Please sign in to comment.