batman-robin 1.2.1

Rust library and CLI tool for interacting with the BATMAN-adv kernel module for mesh networking
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
use super::Error;
use crate::commands;
use crate::model;
use futures::stream::BoxStream;
use validator::Validate;

/// 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
///
/// ```no_run
/// use batman_robin::{Client, MeshSelector};
///
/// # async fn example() -> Result<(), batman_robin::Error> {
/// let client = Client::new();
/// let selector = MeshSelector::with_name("bat0");
///
/// let neighbors = client.neighbors(selector.clone()).await?;
/// println!("{} neighbor entries", neighbors.len());
/// # Ok(())
/// # }
/// ```
#[derive(Clone)]
pub struct Client;

impl Default for Client {
    fn default() -> Self {
        Self::new()
    }
}

impl Client {
    /// Creates a new instance of `Client`.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// let client = Client::new();
    /// let _ = client;
    /// ```
    pub fn new() -> Self {
        Self {}
    }

    /// Resolves a `MeshSelector` into a concrete interface index.
    ///
    /// This method validates the selector first, then resolves by `ifindex` directly
    /// when present or by interface `name` via `if_nametoindex`.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector (by name and/or ifindex).
    ///
    /// # Errors
    /// Returns [`Error::Argument`] if validation fails.
    /// Returns [`Error::Netlink`] if name resolution fails.
    async fn selector_to_ifindex(&self, selector: model::MeshSelector) -> Result<u32, Error> {
        selector
            .validate()
            .map_err(|err| Error::Argument(err.to_string()))?;

        if let Some(ifindex) = selector.ifindex {
            return Ok(ifindex);
        }

        if let Some(name) = selector.name {
            return commands::if_nametoindex(name.as_str()).await.map_err(|_| {
                Error::Netlink(format!(
                    "Error - interface '{}' is not present or not a batman-adv interface",
                    name
                ))
            });
        }

        Err(Error::Argument("Invalid selector".to_string()))
    }

    /// Resolves an `InterfaceSelector` into a concrete interface index.
    ///
    /// This method validates the selector first, then resolves by `ifindex` directly
    /// when present or by interface `name` via `if_nametoindex`.
    ///
    /// # Arguments
    /// * `selector` - Interface selector (by name and/or ifindex).
    ///
    /// # Errors
    /// Returns [`Error::Argument`] if validation fails.
    /// Returns [`Error::Netlink`] if name resolution fails.
    async fn interface_selector_to_ifindex(
        &self,
        selector: model::InterfaceSelector,
    ) -> Result<u32, Error> {
        selector
            .validate()
            .map_err(|err| Error::Argument(err.to_string()))?;

        if let Some(ifindex) = selector.ifindex {
            return Ok(ifindex);
        }

        if let Some(name) = selector.name {
            return commands::if_nametoindex(name.as_str()).await.map_err(|_| {
                Error::Netlink(format!("Error - interface '{}' is not present", name))
            });
        }

        Err(Error::Argument("Invalid selector".to_string()))
    }

    /// Retrieves the list of originators for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let entries = client.originators(MeshSelector::with_name("bat0")).await?;
    /// println!("{} originators", entries.len());
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn originators(
        &self,
        selector: model::MeshSelector,
    ) -> Result<Vec<model::Originator>, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_originators(ifindex).await
    }

    /// Retrieves the list of gateways for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// 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?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn gateways(
        &self,
        selector: Option<model::MeshSelector>,
    ) -> Result<Vec<model::Gateway>, Error> {
        let ifindex = if let Some(selector) = selector {
            Some(self.selector_to_ifindex(selector).await?)
        } else {
            None
        };
        commands::get_gateways_list(ifindex).await
    }

    /// Subscribes to gateway change events for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    /// use futures::StreamExt;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// 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?);
    /// }
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn subscribe_gateway_events(
        &self,
        selector: Option<model::MeshSelector>,
    ) -> Result<BoxStream<'static, Result<model::GatewayEvent, Error>>, Error> {
        let ifindex = if let Some(selector) = selector {
            Some(self.selector_to_ifindex(selector).await?)
        } else {
            None
        };
        commands::UeventListener::subscribe_events(ifindex).await
    }

    /// Gets current gateway mode and related configuration for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let gw = client.get_gw_mode(MeshSelector::with_name("bat0")).await?;
    /// println!("mode={:?}", gw.mode);
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_gw_mode(
        &self,
        selector: model::MeshSelector,
    ) -> Result<model::GatewayInfo, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_gateway(ifindex).await
    }

    /// 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
    ///
    /// ```no_run
    /// use batman_robin::{Client, GwMode, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .set_gw_mode(
    ///         MeshSelector::with_name("bat0"),
    ///         GwMode::Client,
    ///         None,
    ///         None,
    ///         Some(20),
    ///     )
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn set_gw_mode(
        &self,
        selector: model::MeshSelector,
        mode: model::GwMode,
        down: Option<u32>,
        up: Option<u32>,
        sel_class: Option<u32>,
    ) -> Result<(), Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::set_gateway(mode, down, up, sel_class, ifindex).await
    }

    /// Retrieves global translation table entries for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let tg = client.transglobal(MeshSelector::with_name("bat0")).await?;
    /// println!("{} global entries", tg.len());
    /// # Ok(())
    /// # }
    /// ```
    pub async fn transglobal(
        &self,
        selector: model::MeshSelector,
    ) -> Result<Vec<model::TransglobalEntry>, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_transglobal(ifindex).await
    }

    /// Retrieves local translation table entries for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let tl = client.translocal(MeshSelector::with_name("bat0")).await?;
    /// println!("{} local entries", tl.len());
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn translocal(
        &self,
        selector: model::MeshSelector,
    ) -> Result<Vec<model::TranslocalEntry>, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_translocal(ifindex).await
    }

    /// Retrieves the list of neighbors for the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let neighbors = client.neighbors(MeshSelector::with_name("bat0")).await?;
    /// println!("{} neighbors", neighbors.len());
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn neighbors(
        &self,
        selector: model::MeshSelector,
    ) -> Result<Vec<model::Neighbor>, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_neighbors(ifindex).await
    }

    /// Retrieves the list of physical interfaces attached to the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let ifaces = client.interface_list(MeshSelector::with_name("bat0")).await?;
    /// println!("{} attached interfaces", ifaces.len());
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn interface_list(
        &self,
        selector: model::MeshSelector,
    ) -> Result<Vec<model::Interface>, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_interfaces(ifindex).await
    }

    /// 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
    ///
    /// ```no_run
    /// use batman_robin::{Client, InterfaceSelector, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .interface_add(
    ///         MeshSelector::with_name("bat0"),
    ///         InterfaceSelector::with_name("wlan0"),
    ///     )
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    pub async fn interface_add(
        &self,
        selector: model::MeshSelector,
        interface_selector: model::InterfaceSelector,
    ) -> Result<(), Error> {
        let mesh_ifindex = self.selector_to_ifindex(selector).await?;
        let iface_ifindex = self
            .interface_selector_to_ifindex(interface_selector)
            .await?;

        commands::set_interface(iface_ifindex, Some(mesh_ifindex)).await
    }

    /// Removes a physical interface from any mesh interface.
    ///
    /// # Arguments
    /// * `interface_selector` - Interface selector for the physical interface to remove.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, InterfaceSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .interface_remove(InterfaceSelector::with_name("wlan0"))
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn interface_remove(
        &self,
        interface_selector: model::InterfaceSelector,
    ) -> Result<(), Error> {
        let iface_ifindex = self
            .interface_selector_to_ifindex(interface_selector)
            .await?;

        commands::set_interface(iface_ifindex, None).await
    }

    /// 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
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client.mesh_create("bat0", Some("BATMAN_V"), None).await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn mesh_create(
        &self,
        mesh_if: &str,
        routing_algo: Option<&str>,
        mac_addr: Option<macaddr::MacAddr6>,
    ) -> Result<(), Error> {
        commands::create_mesh(mesh_if, routing_algo, mac_addr).await
    }

    /// 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
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let meshes = client.mesh_list().await?;
    ///
    /// for mesh in meshes {
    ///     println!("mesh={}", mesh);
    /// }
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn mesh_list(&self) -> Result<Vec<String>, Error> {
        commands::list_meshes().await
    }

    /// Destroys a BATMAN-adv mesh interface selected by name or ifindex.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client.mesh_delete(MeshSelector::with_name("bat0")).await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn mesh_delete(&self, selector: model::MeshSelector) -> Result<(), Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::delete_mesh(ifindex).await
    }

    /// Counts the number of physical interfaces attached to the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let count = client.interfaces_count(MeshSelector::with_name("bat0")).await?;
    /// println!("{count}");
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn interfaces_count(&self, selector: model::MeshSelector) -> Result<u32, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::count_interfaces(ifindex).await
    }

    /// Gets whether packet aggregation is enabled on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let enabled = client.get_aggregation(MeshSelector::with_name("bat0")).await?;
    /// println!("{enabled}");
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_aggregation(&self, selector: model::MeshSelector) -> Result<bool, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_aggregation(ifindex).await
    }

    /// Enables or disables packet aggregation on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    /// * `val` - `true` to enable, `false` to disable.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .set_aggregation(MeshSelector::with_name("bat0"), true)
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn set_aggregation(
        &self,
        selector: model::MeshSelector,
        val: bool,
    ) -> Result<(), Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::set_aggregation(ifindex, val).await
    }

    /// Gets whether AP isolation is enabled on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let enabled = client
    ///     .get_ap_isolation(MeshSelector::with_name("bat0"))
    ///     .await?;
    /// println!("{enabled}");
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_ap_isolation(&self, selector: model::MeshSelector) -> Result<bool, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_ap_isolation(ifindex).await
    }

    /// Enables or disables AP isolation on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    /// * `val` - `true` to enable, `false` to disable.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .set_ap_isolation(MeshSelector::with_name("bat0"), true)
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn set_ap_isolation(
        &self,
        selector: model::MeshSelector,
        val: bool,
    ) -> Result<(), Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::set_ap_isolation(ifindex, val).await
    }

    /// Gets whether bridge loop avoidance is enabled on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let enabled = client
    ///     .get_bridge_loop_avoidance(MeshSelector::with_name("bat0"))
    ///     .await?;
    /// println!("{enabled}");
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_bridge_loop_avoidance(
        &self,
        selector: model::MeshSelector,
    ) -> Result<bool, Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::get_bridge_loop_avoidance(ifindex).await
    }

    /// Enables or disables bridge loop avoidance on the selected mesh interface.
    ///
    /// # Arguments
    /// * `selector` - Mesh selector.
    /// * `val` - `true` to enable, `false` to disable.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::{Client, MeshSelector};
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client
    ///     .set_bridge_loop_avoidance(MeshSelector::with_name("bat0"), true)
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn set_bridge_loop_avoidance(
        &self,
        selector: model::MeshSelector,
        val: bool,
    ) -> Result<(), Error> {
        let ifindex = self.selector_to_ifindex(selector).await?;
        commands::set_bridge_loop_avoidance(ifindex, val).await
    }

    /// Retrieves the system default routing algorithm for BATMAN-adv.
    ///
    /// # Errors
    /// Returns [`Error`] if the value cannot be retrieved from kernel state.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let algo = client.get_default_routing_algo().await?;
    /// println!("{algo}");
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_default_routing_algo(&self) -> Result<String, Error> {
        commands::get_default_routing_algo().await
    }

    /// Retrieves all active routing algorithms currently in use and their interfaces.
    ///
    /// Returns a vector of `(interface_name, algorithm_name)`.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let active = client.get_active_routing_algos().await?;
    /// for (iface, algo) in active {
    ///     println!("{iface}: {algo}");
    /// }
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_active_routing_algos(&self) -> Result<Vec<(String, String)>, Error> {
        commands::get_active_routing_algos().await
    }

    /// Retrieves all routing algorithms available on the system.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// let available = client.get_available_routing_algos().await?;
    /// println!("{} available algos", available.len());
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn get_available_routing_algos(&self) -> Result<Vec<String>, Error> {
        commands::get_available_routing_algos().await
    }

    /// Sets the system default routing algorithm.
    ///
    /// # Arguments
    /// * `algo` - Algorithm name to set as default.
    ///
    /// # Example
    ///
    /// ```no_run
    /// use batman_robin::Client;
    ///
    /// # async fn example() -> Result<(), batman_robin::Error> {
    /// let client = Client::new();
    /// client.set_default_routing_algo("BATMAN_V").await?;
    /// # Ok(())
    /// # }
    /// ```
    #[tracing::instrument(skip(self))]
    pub async fn set_default_routing_algo(&self, algo: &str) -> Result<(), Error> {
        commands::set_default_routing_algo(algo).await
    }
}