netlink_tc/
lib.rs

1//! # netlink-tc
2//!
3//! `netlink-tc` provides a pure Rust API for interacting with the [netlink](https://www.kernel.org/doc/html/latest/userspace-api/netlink/intro.html) based Linux Traffic Control ([`tc`](http://man7.org/linux/man-pages/man8/tc.8.html)) subsystem of [`rtnetlink`](http://man7.org/linux/man-pages/man7/rtnetlink.7.html).
4//!
5//! This library is very much in progress. It only supports a small subset of `classless` and `classful` [qdiscs](https://tldp.org/HOWTO/Traffic-Control-HOWTO/components.html#c-qdisc). Also, the library only supports read at the moment.
6//!
7//! ## Example
8//!
9//! ```rust
10//! use netlink_tc as tc;
11//!
12//! // Get list of qdiscs
13//! let qdiscs = tc::qdiscs::<tc::Netlink>().unwrap();
14//!
15//! // Get list of classes
16//! let classes = tc::classes::<tc::Netlink>().unwrap();
17//!
18//! // Get class for given interface
19//! let class = tc::class::<tc::Netlink>("eth0").unwrap();
20//! ```
21
22pub mod errors;
23pub mod link;
24pub mod tc;
25pub mod types;
26
27mod class;
28mod constants;
29mod netlink;
30mod qdiscs;
31
32#[cfg(test)]
33mod test_data;
34#[cfg(test)]
35mod tests;
36
37pub use class::*;
38pub use netlink::*;
39pub use qdiscs::*;
40pub use types::*;
41
42/// Get list of all `tc` qdiscs and classes.
43pub fn tc_stats<T: netlink::NetlinkConnection>() -> Result<Vec<Tc>, errors::TcError> {
44    tc::tc_stats::<T>()
45}
46
47/// Get list of all `tc` qdiscs.
48pub fn qdiscs<T: netlink::NetlinkConnection>() -> Result<Vec<Tc>, errors::TcError> {
49    tc::qdiscs::<T>()
50}
51
52/// Get list of all `tc` classes.
53pub fn classes<T: netlink::NetlinkConnection>() -> Result<Vec<Tc>, errors::TcError> {
54    tc::classes::<T>()
55}
56
57/// Get list of all `tc` classes for a given interface.
58pub fn class<T: netlink::NetlinkConnection>(name: &str) -> Result<Vec<Tc>, errors::TcError> {
59    tc::class::<T>(name)
60}
61
62/// Get list of all `tc` classes for a given interface index.
63pub fn class_for_index<T: netlink::NetlinkConnection>(
64    index: u32,
65) -> Result<Vec<Tc>, errors::TcError> {
66    tc::class_for_index::<T>(index)
67}