unix_tap.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #![cfg(any(target_os = "android", target_os = "linux"))]
  5. use std::net;
  6. use base::test_utils::call_test_with_sudo;
  7. use net_util::sys::linux::Tap;
  8. use net_util::sys::linux::TapTLinux;
  9. use net_util::MacAddress;
  10. use net_util::TapTCommon;
  11. #[test]
  12. fn tap_create() {
  13. call_test_with_sudo("tap_create_impl")
  14. }
  15. #[test]
  16. #[ignore = "Only to be called by tap_create"]
  17. fn tap_create_impl() {
  18. Tap::new(true, false).unwrap();
  19. }
  20. #[test]
  21. fn tap_configure() {
  22. call_test_with_sudo("tap_configure_impl")
  23. }
  24. #[test]
  25. #[ignore = "Only to be called by tap_configure"]
  26. fn tap_configure_impl() {
  27. let tap = Tap::new(true, false).unwrap();
  28. let ip_addr: net::Ipv4Addr = "100.115.92.5".parse().unwrap();
  29. let netmask: net::Ipv4Addr = "255.255.255.252".parse().unwrap();
  30. let mac_addr: MacAddress = "a2:06:b9:3d:68:4d".parse().unwrap();
  31. tap.set_ip_addr(ip_addr).unwrap();
  32. tap.set_netmask(netmask).unwrap();
  33. tap.set_mac_address(mac_addr).unwrap();
  34. tap.set_vnet_hdr_size(16).unwrap();
  35. tap.set_offload(0).unwrap();
  36. }
  37. #[test]
  38. fn tap_enable() {
  39. call_test_with_sudo("tap_enable_impl")
  40. }
  41. #[test]
  42. #[ignore = "Only to be called by tap_enable"]
  43. fn tap_enable_impl() {
  44. let tap = Tap::new(true, false).unwrap();
  45. tap.enable().unwrap();
  46. }