xref: /aosp_15_r20/external/crosvm/net_util/tests/unix_tap.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #![cfg(any(target_os = "android", target_os = "linux"))]
6 
7 use std::net;
8 
9 use base::test_utils::call_test_with_sudo;
10 use net_util::sys::linux::Tap;
11 use net_util::sys::linux::TapTLinux;
12 use net_util::MacAddress;
13 use net_util::TapTCommon;
14 
15 #[test]
tap_create()16 fn tap_create() {
17     call_test_with_sudo("tap_create_impl")
18 }
19 
20 #[test]
21 #[ignore = "Only to be called by tap_create"]
tap_create_impl()22 fn tap_create_impl() {
23     Tap::new(true, false).unwrap();
24 }
25 
26 #[test]
tap_configure()27 fn tap_configure() {
28     call_test_with_sudo("tap_configure_impl")
29 }
30 
31 #[test]
32 #[ignore = "Only to be called by tap_configure"]
tap_configure_impl()33 fn tap_configure_impl() {
34     let tap = Tap::new(true, false).unwrap();
35     let ip_addr: net::Ipv4Addr = "100.115.92.5".parse().unwrap();
36     let netmask: net::Ipv4Addr = "255.255.255.252".parse().unwrap();
37     let mac_addr: MacAddress = "a2:06:b9:3d:68:4d".parse().unwrap();
38 
39     tap.set_ip_addr(ip_addr).unwrap();
40     tap.set_netmask(netmask).unwrap();
41     tap.set_mac_address(mac_addr).unwrap();
42     tap.set_vnet_hdr_size(16).unwrap();
43     tap.set_offload(0).unwrap();
44 }
45 
46 #[test]
tap_enable()47 fn tap_enable() {
48     call_test_with_sudo("tap_enable_impl")
49 }
50 
51 #[test]
52 #[ignore = "Only to be called by tap_enable"]
tap_enable_impl()53 fn tap_enable_impl() {
54     let tap = Tap::new(true, false).unwrap();
55 
56     tap.enable().unwrap();
57 }
58