-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**API BREAK** To remove the duplicate error of `LinkAddRequest` and `LinkSetRequest`, this patch introduce `LinkMessageBuilder` to generate `LinkMessage` for link handlers to use. The `impl LinkMessageBuilder<T>` holds the common functions available for all interface types. The `impl LinkMessageBuilder<LinkVlan>` holds VLAN specific functions. The LinkMessageBuilder is designed for advanced user, wrapper functions are created for common use cases. For example, to create a VLAN interface: ```rus let (connection, handle, _) = new_connection().unwrap(); tokio::spawn(connection); handle .link() .add( LinkVlan::new("vlan100", 10, 100) .up() .build() ) .execute() .await .map_err(|e| format!("{e}")) ``` These patches included these new structures to generate matching LinkMessageBuilder: * `LinkUnspec` (for matching existing interface) * `LinkDummy` * `LinkVeth` * `LinkVlan` * `LinkVxlan` * `LinkMacVlan` * `LinkMacVtap` * `LinkWireguard` * `LinkBondPort` Special note: * Due to confliction, the previous VxLAN `link()` function changed to `dev()`. The `link()` is the share function for all interface types. The API is matching with `ip link` command line option for vxlan. Please check `examples/create_vxlan.rs` for usage. * The `LinkHandler::set_bond_port()` changed to `LinkHandler::set_port()`, please check `examples/set_bond_port.rs` for usage. * The `message_mut()` function is removed from `LinkSetRequest` and `LinkAddRequest`, user should modify the LinkMessage before sent to handler. Signed-off-by: Gris Ge <[email protected]>
- Loading branch information
Showing
37 changed files
with
1,782 additions
and
1,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use rtnetlink::{new_connection, LinkDummy}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), String> { | ||
let (connection, handle, _) = new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
handle | ||
.link() | ||
.add(LinkDummy::new("dummy0").build()) | ||
.execute() | ||
.await | ||
.map_err(|e| format!("{e}")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use rtnetlink::{new_connection, LinkVrf}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), String> { | ||
let (connection, handle, _) = new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
handle | ||
.link() | ||
.add(LinkVrf::new("my-vrf", 101).build()) | ||
.execute() | ||
.await | ||
.map_err(|e| format!("{e}")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use rtnetlink::{new_connection, LinkWireguard}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), String> { | ||
let (connection, handle, _) = new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
handle | ||
.link() | ||
.add(LinkWireguard::new("my-wg").build()) | ||
.execute() | ||
.await | ||
.map_err(|e| format!("{e}")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use futures::stream::TryStreamExt; | ||
use rtnetlink::{new_connection, Error, Handle, LinkXfrm}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), String> { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() != 2 { | ||
usage(); | ||
return Ok(()); | ||
} | ||
let link_name = &args[1]; | ||
|
||
let (connection, handle, _) = new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
create_xfrm(handle, link_name.to_string()) | ||
.await | ||
.map_err(|e| format!("{e}")) | ||
} | ||
|
||
async fn create_xfrm(handle: Handle, link_name: String) -> Result<(), Error> { | ||
let mut parent_links = | ||
handle.link().get().match_name(link_name.clone()).execute(); | ||
if let Some(parent) = parent_links.try_next().await? { | ||
let request = handle | ||
.link() | ||
.add(LinkXfrm::new("my-xfrm", parent.header.index, 0x08).build()); | ||
|
||
request.execute().await? | ||
} else { | ||
println!("no link {link_name} found"); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn usage() { | ||
eprintln!( | ||
"usage: | ||
cargo run --example create_xfrm -- <link name> | ||
Note that you need to run this program as root. Instead of running cargo as | ||
root, build the example normally: | ||
cargo build --example create_xfrm | ||
Then find the binary in the target directory: | ||
cd target/debug/examples ; sudo ./create_xfrm <link_name>" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.