Files
firezone/rust/gui-client/src-tauri/src/client/network_changes/linux.rs
Reactor Scram deefabd8f8 refactor(firezone-tunnel): move routes and DNS control out of connlib and up to the Client (#5111)
Refs #3636 (This pays down some of the technical debt from Linux DNS)
Refs #4473 (This partially fulfills it)
Refs #5068 (This is needed to make `FIREZONE_DNS_CONTROL` mandatory)

As of dd6421:

- On both Linux and Windows, DNS control and IP setting (i.e.
`on_set_interface_config`) both move to the Client
- On Windows, route setting stays in `tun_windows.rs`. Route setting in
Windows requires us to know the interface index, which we don't know in
the Client code. If we could pass opaque platform-specific data between
the tunnel and the Client it would be easy.
- On Linux, route setting moves to the Client and Gateway, which
completely removes the `worker` task in `tun_linux.rs`
- Notifying systemd that we're ready moves up to the headless Client /
IPC service

```[tasklist]
### Before merging / notes
- [x] Does DNS roaming work on Linux on `main`? I don't see where it hooks up. I think I only set up DNS in `Tun::new` (Yes, the `Tun` gets recreated every time we reconfigure the device)
- [x] Fix Windows Clients
- [x] Fix Gateway
- [x] Make sure connlib doesn't get the DNS control method from the env var (will be fixed in #5068)
- [x] De-dupe consts
- [ ] ~~Add DNS control test~~ (failed)
- [ ] Smoke test Linux
- [ ] Smoke test Windows
```
2024-06-03 14:32:08 +00:00

73 lines
1.8 KiB
Rust

//! Not implemented for Linux yet
use anyhow::Result;
use firezone_headless_client::dns_control::system_resolvers_for_gui;
use std::net::IpAddr;
use tokio::time::Interval;
pub(crate) fn run_dns_debug() -> Result<()> {
tracing::warn!("network_changes not implemented yet on Linux");
Ok(())
}
pub(crate) fn run_debug() -> Result<()> {
tracing::warn!("network_changes not implemented yet on Linux");
Ok(())
}
/// TODO: Implement for Linux
pub(crate) fn check_internet() -> Result<bool> {
Ok(true)
}
pub(crate) struct Worker {}
impl Worker {
pub(crate) fn new() -> Result<Self> {
Ok(Self {})
}
pub(crate) fn close(&mut self) -> Result<()> {
Ok(())
}
/// Not implemented on Linux
///
/// On Windows this returns when we gain or lose Internet.
pub(crate) async fn notified(&mut self) {
futures::future::pending().await
}
}
pub(crate) struct DnsListener {
interval: Interval,
last_seen: Vec<IpAddr>,
}
impl DnsListener {
pub(crate) fn new() -> Result<Self> {
Ok(Self {
interval: create_interval(),
last_seen: system_resolvers_for_gui().unwrap_or_default(),
})
}
pub(crate) async fn notified(&mut self) -> Result<Vec<IpAddr>> {
loop {
self.interval.tick().await;
tracing::trace!("Checking for DNS changes");
let new = system_resolvers_for_gui().unwrap_or_default();
if new != self.last_seen {
self.last_seen.clone_from(&new);
return Ok(new);
}
}
}
}
fn create_interval() -> Interval {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(5));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
interval
}