diff --git a/Cargo.lock b/Cargo.lock index ffb11769e..55a36f3e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -702,7 +702,6 @@ dependencies = [ "log 0.4.14", "net_gen", "pnet", - "rand 0.8.3", "serde", "serde_json", "virtio-bindings", diff --git a/net_util/Cargo.toml b/net_util/Cargo.toml index 042515dc5..5b2721dbb 100644 --- a/net_util/Cargo.toml +++ b/net_util/Cargo.toml @@ -8,7 +8,6 @@ epoll = ">=4.0.1" libc = "0.2.86" log = "0.4.14" net_gen = { path = "../net_gen" } -rand = "0.8.3" serde = "1.0.123" virtio-bindings = "0.1.0" vm-memory = { version = "0.5.0", features = ["backend-mmap", "backend-atomic"] } diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index 7d1320c4a..a226a4f64 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -14,7 +14,6 @@ extern crate libc; #[macro_use] extern crate log; extern crate net_gen; -extern crate rand; extern crate serde; extern crate virtio_bindings; extern crate vm_memory; diff --git a/net_util/src/mac.rs b/net_util/src/mac.rs index ebf246d6b..548829a48 100644 --- a/net_util/src/mac.rs +++ b/net_util/src/mac.rs @@ -5,7 +5,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the THIRD-PARTY file. -use rand::Rng; use std::fmt; use std::io; use std::result::Result; @@ -82,7 +81,22 @@ impl MacAddr { pub fn local_random() -> MacAddr { // Generate a fully random MAC - let mut random_bytes = rand::thread_rng().gen::<[u8; MAC_ADDR_LEN]>(); + let mut random_bytes = [0u8; MAC_ADDR_LEN]; + unsafe { + // Man page says this function will not be interrupted by a signal + // for requests less than 256 bytes + if libc::getrandom( + random_bytes.as_mut_ptr() as *mut _ as *mut libc::c_void, + MAC_ADDR_LEN, + 0, + ) < 0 + { + error!( + "Error populating MAC address with random data: {}", + std::io::Error::last_os_error() + ) + } + }; // Set the first byte to make the OUI a locally administered OUI random_bytes[0] = 0x2e;