This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! dist/tools/vaina: add VAINA client
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::ffi::OsString; | ||
use std::net::Ipv6Addr; | ||
|
||
use clap::{value_t, ArgMatches}; | ||
|
||
use crate::client::VainaClient; | ||
use crate::msg::Message; | ||
use crate::Error; | ||
|
||
/// Router Client Set sub command | ||
pub fn handle_matches(matches: &ArgMatches) -> Result<(), Error> { | ||
match matches.subcommand() { | ||
("add", Some(add_matches)) => add(add_matches)?, | ||
("del", Some(del_matches)) => del(del_matches)?, | ||
_ => println!("{}", matches.usage()), | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn add(matches: &ArgMatches) -> Result<(), Error> { | ||
let prefix = value_t!(matches, "prefix", u8).unwrap_or_else(|e| e.exit()); | ||
let ip = value_t!(matches, "IP", Ipv6Addr).unwrap_or_else(|e| e.exit()); | ||
let interface = value_t!(matches, "interface", String).unwrap_or_else(|e| e.exit()); | ||
let interface = OsString::from(interface); | ||
|
||
let mut client = VainaClient::new(&interface)?; | ||
|
||
let msg = Message::NibAdd { | ||
seqno: client.craft_seqno(), | ||
prefix, | ||
ip, | ||
}; | ||
client.send_message(&msg)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn del(matches: &ArgMatches) -> Result<(), Error> { | ||
let prefix = value_t!(matches, "prefix", u8).unwrap_or_else(|e| e.exit()); | ||
let ip = value_t!(matches, "IP", Ipv6Addr).unwrap_or_else(|e| e.exit()); | ||
let interface = value_t!(matches, "interface", String).unwrap_or_else(|e| e.exit()); | ||
let interface = OsString::from(interface); | ||
|
||
let mut client = VainaClient::new(&interface)?; | ||
|
||
let msg = Message::NibDel { | ||
seqno: client.craft_seqno(), | ||
prefix, | ||
ip, | ||
}; | ||
client.send_message(&msg)?; | ||
|
||
Ok(()) | ||
} |