Ensure that coarsetime::Updater is stopped on Proxy::shutdown()
This commit is contained in:
parent
9ffa829add
commit
de255f4240
|
|
@ -9,7 +9,7 @@ use crate::host::Host;
|
||||||
use crate::host::NetType;
|
use crate::host::NetType;
|
||||||
use crate::poller::Poller;
|
use crate::poller::Poller;
|
||||||
use crate::vm::VM;
|
use crate::vm::VM;
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
pub use exposed_port::ExposedPort;
|
pub use exposed_port::ExposedPort;
|
||||||
use ipnet::Ipv4Net;
|
use ipnet::Ipv4Net;
|
||||||
use mac_address::MacAddress;
|
use mac_address::MacAddress;
|
||||||
|
|
@ -27,6 +27,7 @@ pub struct Proxy<'proxy> {
|
||||||
poller: Poller<'proxy>,
|
poller: Poller<'proxy>,
|
||||||
vm_mac_address: smoltcp::wire::EthernetAddress,
|
vm_mac_address: smoltcp::wire::EthernetAddress,
|
||||||
dhcp_snooper: DhcpSnooper,
|
dhcp_snooper: DhcpSnooper,
|
||||||
|
coarsetime_updater: coarsetime::Updater,
|
||||||
rules: PrefixMap<Ipv4Net, Action>,
|
rules: PrefixMap<Ipv4Net, Action>,
|
||||||
enobufs_encountered: bool,
|
enobufs_encountered: bool,
|
||||||
port_forwarder: PortForwarder,
|
port_forwarder: PortForwarder,
|
||||||
|
|
@ -66,6 +67,7 @@ impl Proxy<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let coarsetime_update_interval_millis = 100;
|
let coarsetime_update_interval_millis = 100;
|
||||||
|
let coarsetime_updater =
|
||||||
coarsetime::Updater::new(coarsetime_update_interval_millis).start()?;
|
coarsetime::Updater::new(coarsetime_update_interval_millis).start()?;
|
||||||
|
|
||||||
Ok(Proxy {
|
Ok(Proxy {
|
||||||
|
|
@ -76,6 +78,7 @@ impl Proxy<'_> {
|
||||||
dhcp_snooper: DhcpSnooper::new(Duration::from_millis(
|
dhcp_snooper: DhcpSnooper::new(Duration::from_millis(
|
||||||
coarsetime_update_interval_millis,
|
coarsetime_update_interval_millis,
|
||||||
)),
|
)),
|
||||||
|
coarsetime_updater,
|
||||||
rules,
|
rules,
|
||||||
enobufs_encountered: false,
|
enobufs_encountered: false,
|
||||||
port_forwarder: PortForwarder::new(exposed_ports),
|
port_forwarder: PortForwarder::new(exposed_ports),
|
||||||
|
|
@ -121,6 +124,12 @@ impl Proxy<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shutdown(self) -> Result<()> {
|
||||||
|
self.coarsetime_updater
|
||||||
|
.stop()
|
||||||
|
.context("failed to shutdown coarsetime updater")
|
||||||
|
}
|
||||||
|
|
||||||
fn read_from_vm(&mut self, buf: &mut [u8]) -> Result<()> {
|
fn read_from_vm(&mut self, buf: &mut [u8]) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
match self.vm.read(buf) {
|
match self.vm.read(buf) {
|
||||||
|
|
@ -193,6 +202,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "66.66.66.66").is_none());
|
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "66.66.66.66").is_none());
|
||||||
|
|
||||||
|
proxy.shutdown().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -212,6 +223,8 @@ mod tests {
|
||||||
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.32").is_none());
|
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.32").is_none());
|
||||||
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.33").is_some());
|
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.33").is_some());
|
||||||
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.34").is_none());
|
assert!(allowed_from_vm_ipv4(&proxy, vm_ip, "33.33.33.34").is_none());
|
||||||
|
|
||||||
|
proxy.shutdown().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_proxy<'test>(vm_ip: Ipv4Address, allow: Vec<&str>, block: Vec<&str>) -> Proxy<'test> {
|
fn create_proxy<'test>(vm_ip: Ipv4Address, allow: Vec<&str>, block: Vec<&str>) -> Proxy<'test> {
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,9 @@ fn try_main() -> anyhow::Result<()> {
|
||||||
.context("failed to drop privileges")?;
|
.context("failed to drop privileges")?;
|
||||||
|
|
||||||
// Run proxy
|
// Run proxy
|
||||||
proxy.run()
|
proxy.run()?;
|
||||||
|
|
||||||
|
proxy.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sudo_escalation_works() -> bool {
|
fn sudo_escalation_works() -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue