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
//! This crate provides methods to manipulate networking resources (links, addresses, arp tables,
//! route tables) via the netlink protocol.
//!
//! It can be used on its own for simple needs, but it is possible to tweak any netlink request.
//! See this [link creation snippet](struct.LinkAddRequest.html#example) for example.
//!
//! # Example: listing links
//!
//! ```rust,no_run
//! extern crate futures;
//! extern crate iproute2;
//! extern crate tokio_core;
//!
//! use futures::Future;
//! use iproute2::new_connection;
//! use tokio_core::reactor::Core;
//!
//! fn main() {
//!     // Create a netlink connection, and a handle to send requests via this connection
//!     let (connection, handle) = new_connection().unwrap();
//!
//!     // The connection will run in an event loop
//!     let mut core = Core::new().unwrap();
//!     core.handle().spawn(connection.map_err(|_| ()));
//!
//!     /// Create a netlink request
//!     let request = handle.link().get().execute().and_then(|links| {
//!         println!("{:#?}", links);
//!         Ok(())
//!     });
//!
//!     /// Run the request on the event loop
//!     core.run(request).unwrap();
//! }
//! ```
//!
//! # Example: creating a veth pair
//!
//! ```rust,no_run
//! extern crate futures;
//! extern crate iproute2;
//! extern crate tokio_core;
//!
//! use std::thread::spawn;
//!
//! use futures::Future;
//! use tokio_core::reactor::Core;
//!
//! use iproute2::new_connection;
//!
//! fn main() {
//!     // Create a netlink connection, and a handle to send requests via this connection
//!     let (connection, handle) = new_connection().unwrap();
//!
//!     // The connection we run in its own thread
//!     spawn(move || Core::new().unwrap().run(connection));
//!
//!     // Create a request to create the veth pair
//!     handle
//!         .link()
//!         .add()
//!         .veth("veth-rs-1".into(), "veth-rs-2".into())
//!         // Execute the request, and wait for it to finish
//!         .execute()
//!         .wait()
//!         .unwrap();
//! }
//! ```
//!
//! # Example: deleting a link by name
//!
//! ```rust,no_run
//! extern crate futures;
//! extern crate iproute2;
//! extern crate tokio_core;
//!
//! use std::env;
//! use std::thread::spawn;
//!
//! use futures::Future;
//! use tokio_core::reactor::Core;
//!
//! use iproute2::new_connection;
//!
//! fn main() {
//!     let args: Vec<String> = env::args().collect();
//!     if args.len() != 2 { panic!("expected one link name as argument"); }
//!     let link_name = &args[1];
//!
//!     let (connection, handle) = new_connection().unwrap();
//!     spawn(move || Core::new().unwrap().run(connection));
//!
//!     // Get the list of links
//!     let links = handle.link().get().execute().wait().unwrap();
//!
//!     // Find the link with the name provided as argument, and delete it
//!     for link in links {
//!         if link.name().unwrap() == link_name {
//!             handle.link().del(link.index()).execute().wait().unwrap();
//!         }
//!     }
//! }
//! ```

#![cfg_attr(feature = "cargo-clippy", allow(module_inception))]

#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;
extern crate bytes;
extern crate eui48;
extern crate futures;
extern crate tokio_core;

extern crate netlink_socket;
extern crate rtnetlink;

extern crate failure;
#[macro_use]
extern crate failure_derive;

mod connection;
mod errors;
mod link;

pub use connection::*;
pub use errors::*;
pub use link::*;