use nl_fou::FouConfig;
async fn add_fou_listener() -> Result<(), Box<dyn std::error::Error>> {
let (conn, mut handle, _) = nl_fou::new_connection()?;
tokio::spawn(conn);
let mut config = FouConfig::new(5555);
config.ipproto = Some(17);
handle.add(&config).await?;
Ok(())
}FouHandle::get_all() returns one FouConfig per listener:
async fn show_fou_listeners() -> Result<(), Box<dyn std::error::Error>> {
let (conn, mut handle, _) = nl_fou::new_connection()?;
tokio::spawn(conn);
for listener in handle.get_all().await? {
println!("{listener:?}");
}
Ok(())
}The local port, the address family and the addresses identify a listener,
FouConfig::new() sets the defaults of ip fou del:
use nl_fou::FouConfig;
async fn delete_fou_listener() -> Result<(), Box<dyn std::error::Error>> {
let (conn, mut handle, _) = nl_fou::new_connection()?;
tokio::spawn(conn);
handle.delete(&FouConfig::new(5555)).await?;
Ok(())
}FouConfig::new(port)creates a listener with the IPv4 address family and direct FOU encapsulation, the encapsulation type ofip fou add port 5555.FouHandle::add()validates the configuration asip foudoes: a direct listener needsipproto, a GUE listener must not set it, and a peer address and a peer port come in pairs.FouHandle::add()fails when a listener which holds the same local port, address family and addresses exists, delete it first to replace it.FouConfigis#[non_exhaustive], it can not be built with a struct literal outside of this crate. UseDefault::default()orFouConfig::new()and assign the properties instead.FouConfig::build()validates the configuration and turns it into aFouMessage, for example forFouHandle::request().FouHandle::get_all()parses every attribute the kernel reports, the result of a dump can be applied again withFouHandle::add().- The
foukernel module does not auto-load when the generic netlink family is resolved, load it withmodprobe foubefore adding a listener.