Skip to main content

Client

Struct Client 

Source
pub struct Client;
Expand description

High-level client for interacting with the BATMAN-adv mesh network.

Client provides asynchronous methods to query and configure BATMAN-adv interfaces and settings via netlink.

Mesh-targeted methods take a model::MeshSelector by value. You can build selectors explicitly with model::MeshSelector::with_name or model::MeshSelector::with_ifindex.

§Example

use batman_robin::{Client, MeshSelector};

let client = Client::new();
let selector = MeshSelector::with_name("bat0");

let neighbors = client.neighbors(selector.clone()).await?;
println!("{} neighbor entries", neighbors.len());

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Creates a new instance of Client.

§Example
use batman_robin::Client;

let client = Client::new();
let _ = client;
Source

pub async fn originators( &self, selector: MeshSelector, ) -> Result<Vec<Originator>, Error>

Retrieves the list of originators for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let entries = client.originators(MeshSelector::with_name("bat0")).await?;
println!("{} originators", entries.len());
Source

pub async fn gateways( &self, selector: Option<MeshSelector>, ) -> Result<Vec<Gateway>, Error>

Retrieves the list of gateways for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let gateways = client.gateways(Some(MeshSelector::with_name("bat0"))).await?;
println!("{} gateways", gateways.len());
// Pass None to query gateways across all mesh interfaces:
let all = client.gateways(None).await?;
Source

pub async fn subscribe_gateway_events( &self, selector: Option<MeshSelector>, ) -> Result<BoxStream<'static, Result<GatewayEvent, Error>>, Error>

Subscribes to gateway change events for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
use futures::StreamExt;

let client = Client::new();
let mut events = client
    .subscribe_gateway_events(Some(MeshSelector::with_name("bat0")))
    .await?;

while let Some(event) = events.next().await {
    println!("{:?}", event?);
}
Source

pub async fn get_gw_mode( &self, selector: MeshSelector, ) -> Result<GatewayInfo, Error>

Gets current gateway mode and related configuration for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let gw = client.get_gw_mode(MeshSelector::with_name("bat0")).await?;
println!("mode={:?}", gw.mode);
Source

pub async fn set_gw_mode( &self, selector: MeshSelector, mode: GwMode, down: Option<u32>, up: Option<u32>, sel_class: Option<u32>, ) -> Result<(), Error>

Sets gateway mode and optional parameters for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
  • mode - Gateway mode to apply.
  • down - Optional downstream bandwidth parameter.
  • up - Optional upstream bandwidth parameter.
  • sel_class - Optional gateway selection class.
§Errors

Returns Error if selector validation, selector resolution, or netlink write fails.

§Example
use batman_robin::{Client, GwMode, MeshSelector};

let client = Client::new();
client
    .set_gw_mode(
        MeshSelector::with_name("bat0"),
        GwMode::Client,
        None,
        None,
        Some(20),
    )
    .await?;
Source

pub async fn transglobal( &self, selector: MeshSelector, ) -> Result<Vec<TransglobalEntry>, Error>

Retrieves global translation table entries for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let tg = client.transglobal(MeshSelector::with_name("bat0")).await?;
println!("{} global entries", tg.len());
Source

pub async fn translocal( &self, selector: MeshSelector, ) -> Result<Vec<TranslocalEntry>, Error>

Retrieves local translation table entries for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let tl = client.translocal(MeshSelector::with_name("bat0")).await?;
println!("{} local entries", tl.len());
Source

pub async fn neighbors( &self, selector: MeshSelector, ) -> Result<Vec<Neighbor>, Error>

Retrieves the list of neighbors for the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let neighbors = client.neighbors(MeshSelector::with_name("bat0")).await?;
println!("{} neighbors", neighbors.len());
Source

pub async fn interface_list( &self, selector: MeshSelector, ) -> Result<Vec<Interface>, Error>

Retrieves the list of physical interfaces attached to the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let ifaces = client.interface_list(MeshSelector::with_name("bat0")).await?;
println!("{} attached interfaces", ifaces.len());
Source

pub async fn interface_add( &self, selector: MeshSelector, interface_selector: InterfaceSelector, ) -> Result<(), Error>

Adds a physical interface to a selected mesh interface.

§Arguments
  • selector - Mesh selector identifying the target mesh interface.
  • interface_selector - Interface selector for the physical interface to add.
§Example
use batman_robin::{Client, InterfaceSelector, MeshSelector};

let client = Client::new();
client
    .interface_add(
        MeshSelector::with_name("bat0"),
        InterfaceSelector::with_name("wlan0"),
    )
    .await?;
Source

pub async fn interface_remove( &self, interface_selector: InterfaceSelector, ) -> Result<(), Error>

Removes a physical interface from any mesh interface.

§Arguments
  • interface_selector - Interface selector for the physical interface to remove.
§Example
use batman_robin::{Client, InterfaceSelector};

let client = Client::new();
client
    .interface_remove(InterfaceSelector::with_name("wlan0"))
    .await?;
Source

pub async fn mesh_create( &self, mesh_if: &str, routing_algo: Option<&str>, mac_addr: Option<MacAddr6>, ) -> Result<(), Error>

Creates a new BATMAN-adv mesh interface with an optional routing algorithm and MAC address.

§Arguments
  • mesh_if - Name of the interface to create.
  • routing_algo - Optional routing algorithm string.
  • mac_addr - Optional hardware address. A random locally-administered address is generated if None to avoid conflicts with other devices on the network.
§Example
use batman_robin::Client;

let client = Client::new();
client.mesh_create("bat0", Some("BATMAN_V"), None).await?;
Source

pub async fn mesh_list(&self) -> Result<Vec<String>, Error>

Lists BATMAN-adv mesh interfaces available on the host.

This method returns interfaces whose kernel link kind is batadv. It is useful to discover existing mesh interfaces before selecting one for operations like neighbors, gateways, or interface management.

§Returns

Returns a vector of mesh interface names for every detected BATMAN-adv mesh interface.

§Example
use batman_robin::Client;

let client = Client::new();
let meshes = client.mesh_list().await?;

for mesh in meshes {
    println!("mesh={}", mesh);
}
Source

pub async fn mesh_delete(&self, selector: MeshSelector) -> Result<(), Error>

Destroys a BATMAN-adv mesh interface selected by name or ifindex.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
client.mesh_delete(MeshSelector::with_name("bat0")).await?;
Source

pub async fn interfaces_count( &self, selector: MeshSelector, ) -> Result<u32, Error>

Counts the number of physical interfaces attached to the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let count = client.interfaces_count(MeshSelector::with_name("bat0")).await?;
println!("{count}");
Source

pub async fn get_aggregation( &self, selector: MeshSelector, ) -> Result<bool, Error>

Gets whether packet aggregation is enabled on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let enabled = client.get_aggregation(MeshSelector::with_name("bat0")).await?;
println!("{enabled}");
Source

pub async fn set_aggregation( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>

Enables or disables packet aggregation on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
  • val - true to enable, false to disable.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
client
    .set_aggregation(MeshSelector::with_name("bat0"), true)
    .await?;
Source

pub async fn get_ap_isolation( &self, selector: MeshSelector, ) -> Result<bool, Error>

Gets whether AP isolation is enabled on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let enabled = client
    .get_ap_isolation(MeshSelector::with_name("bat0"))
    .await?;
println!("{enabled}");
Source

pub async fn set_ap_isolation( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>

Enables or disables AP isolation on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
  • val - true to enable, false to disable.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
client
    .set_ap_isolation(MeshSelector::with_name("bat0"), true)
    .await?;
Source

pub async fn get_bridge_loop_avoidance( &self, selector: MeshSelector, ) -> Result<bool, Error>

Gets whether bridge loop avoidance is enabled on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
let enabled = client
    .get_bridge_loop_avoidance(MeshSelector::with_name("bat0"))
    .await?;
println!("{enabled}");
Source

pub async fn set_bridge_loop_avoidance( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>

Enables or disables bridge loop avoidance on the selected mesh interface.

§Arguments
  • selector - Mesh selector.
  • val - true to enable, false to disable.
§Example
use batman_robin::{Client, MeshSelector};

let client = Client::new();
client
    .set_bridge_loop_avoidance(MeshSelector::with_name("bat0"), true)
    .await?;
Source

pub async fn get_default_routing_algo(&self) -> Result<String, Error>

Retrieves the system default routing algorithm for BATMAN-adv.

§Errors

Returns Error if the value cannot be retrieved from kernel state.

§Example
use batman_robin::Client;

let client = Client::new();
let algo = client.get_default_routing_algo().await?;
println!("{algo}");
Source

pub async fn get_active_routing_algos( &self, ) -> Result<Vec<(String, String)>, Error>

Retrieves all active routing algorithms currently in use and their interfaces.

Returns a vector of (interface_name, algorithm_name).

§Example
use batman_robin::Client;

let client = Client::new();
let active = client.get_active_routing_algos().await?;
for (iface, algo) in active {
    println!("{iface}: {algo}");
}
Source

pub async fn get_available_routing_algos(&self) -> Result<Vec<String>, Error>

Retrieves all routing algorithms available on the system.

§Example
use batman_robin::Client;

let client = Client::new();
let available = client.get_available_routing_algos().await?;
println!("{} available algos", available.len());
Source

pub async fn set_default_routing_algo(&self, algo: &str) -> Result<(), Error>

Sets the system default routing algorithm.

§Arguments
  • algo - Algorithm name to set as default.
§Example
use batman_robin::Client;

let client = Client::new();
client.set_default_routing_algo("BATMAN_V").await?;

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more