Files
firezone/rust/connlib/shared/src/callbacks.rs
Reactor Scram 830302af43 test(linux): Low-risk changes to prepare for Linux DNS support (#3625)
This splits off the easy parts from #3605.

- Add quotes around `PHOENIX_SECURE_COOKIES` because my local
`docker-compose` considers unquoted 'false' to be a schema error - Env
vars are strings or numbers, not bools, it says
- Create `test.httpbin.docker.local` container in a new subnet so it can
be used as a DNS resource without the existing CIDR resource picking it
up
- Add resources and policies to `seeds.exs` per #3342
- Fix warning about `CONNLIB_LOG_UPLOAD_INTERVAL_SECS` not being set
- Add `resolv-conf` dep and unit tests to `firezone-tunnel` and
`firezone-linux-client`
- Impl `on_disconnect` in the Linux client with `tracing::error!`
- Add comments

```[tasklist]
- [x] (failed) Confirm that the client container actually does stop faster this way
- [x] Wait for tests to pass
- [x] Mark as ready for review
```
2024-02-12 19:04:51 +00:00

79 lines
2.4 KiB
Rust

use crate::messages::ResourceDescription;
use ip_network::IpNetwork;
use std::error::Error;
use std::fmt::{Debug, Display};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::PathBuf;
// Avoids having to map types for Windows
type RawFd = i32;
/// Traits that will be used by connlib to callback the client upper layers.
pub trait Callbacks: Clone + Send + Sync {
/// Error returned when a callback fails.
type Error: Debug + Display + Error;
/// Called when the tunnel address is set.
///
/// This should return a new `fd` if there is one.
/// (Only happens on android for now)
fn on_set_interface_config(
&self,
_: Ipv4Addr,
_: Ipv6Addr,
_: Vec<IpAddr>,
) -> Result<Option<RawFd>, Self::Error> {
Ok(None)
}
/// Called when the tunnel is connected.
fn on_tunnel_ready(&self) -> Result<(), Self::Error> {
tracing::trace!("tunnel_connected");
Ok(())
}
/// Called when when a route is added.
///
/// This should return a new `fd` if there is one.
/// (Only happens on android for now)
fn on_add_route(&self, _: IpNetwork) -> Result<Option<RawFd>, Self::Error> {
Ok(None)
}
/// Called when when a route is removed.
fn on_remove_route(&self, _: IpNetwork) -> Result<Option<RawFd>, Self::Error> {
Ok(None)
}
/// Called when the resource list changes.
fn on_update_resources(
&self,
resource_list: Vec<ResourceDescription>,
) -> Result<(), Self::Error> {
tracing::trace!(?resource_list, "resource_updated");
Ok(())
}
/// Called when the tunnel is disconnected.
///
/// If the tunnel disconnected due to a fatal error, `error` is the error
/// that caused the disconnect.
fn on_disconnect(&self, error: Option<&crate::Error>) -> Result<(), Self::Error> {
tracing::trace!(error = ?error, "tunnel_disconnected");
// Note that we can't panic here, since we already hooked the panic to this function.
std::process::exit(0);
}
/// Returns the system's default resolver(s)
///
/// It's okay for clients to include Firezone's own DNS here, e.g. 100.100.111.1.
/// connlib internally filters them out.
fn get_system_default_resolvers(&self) -> Result<Option<Vec<IpAddr>>, Self::Error> {
Ok(None)
}
fn roll_log_file(&self) -> Option<PathBuf> {
None
}
}