-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce mion dump-eeprom & dump-memory (#15)
* introduce mion dump-eeprom & dump-memory introduce two new subcommands we found while poking around in telnet memory dumps (telnet has the same username/password as the http interface). these cgi pages allow us to figure out the memory, and eeprom of the MION itself, which should be helpful for certain tasks. * retry dumping memory * fix clap breakage * allow retry on body read too * write as needed + resumption fixes #16 this writes the memory dump file which takes forever (4Gbs at 512 bytes per request, which can sometimes fail and need to be retried) as the requests come in rather than actually waiting for it to all be buffered in memory first. this also lowers the total amount of memory required to do so. also allow resuming a stopped/failed memory dump. * mention how long a mion memory dump takes * concurrently fetch pages
- Loading branch information
Showing
11 changed files
with
924 additions
and
3 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,76 @@ | ||
//! Dump the EEPROM for a running CAT-DEV. | ||
use crate::{ | ||
commands::argv_helpers::get_targeted_bridge_ip, | ||
exit_codes::{DUMP_EEPROM_FAILURE, FAILED_TO_WRITE_TO_DISK}, | ||
SHOULD_LOG_JSON, | ||
}; | ||
use cat_dev::mion::cgis::dump_eeprom; | ||
use miette::miette; | ||
use std::path::PathBuf; | ||
use tokio::fs::write; | ||
use tracing::{error, info}; | ||
|
||
/// Actual command handler for the `mion dump-eeprom` command. | ||
pub async fn handle_dump_eeprom(output_path: Option<PathBuf>) { | ||
let bridge_ip = get_targeted_bridge_ip().await; | ||
if SHOULD_LOG_JSON() { | ||
info!( | ||
id = "bridgectl::mion::dump_eeprom::start", | ||
%bridge_ip, | ||
"Dumping MION EEPROM...", | ||
); | ||
} else { | ||
info!( | ||
%bridge_ip, | ||
"Dumping MION EEPROM...", | ||
); | ||
} | ||
|
||
match dump_eeprom(bridge_ip).await { | ||
Ok(memory) => { | ||
let err = if let Some(path) = output_path.as_ref() { | ||
write(path, memory).await.err() | ||
} else { | ||
write("eeprom-memory.bin", memory).await.err() | ||
}; | ||
|
||
if let Some(cause) = err { | ||
if SHOULD_LOG_JSON() { | ||
error!( | ||
id = "bridgectl::mion::dump_eeprom::write_failure", | ||
%bridge_ip, | ||
?cause, | ||
path = output_path.map_or("eeprom-memory.bin".to_owned(), |p| p.to_string_lossy().to_string()), | ||
"Failed to write eeprom memory to disk!", | ||
); | ||
} else { | ||
error!( | ||
"\n{:?}", | ||
miette!("Could not write successfully dumped MION's EEPROM Memory") | ||
.wrap_err(cause), | ||
); | ||
} | ||
|
||
std::process::exit(FAILED_TO_WRITE_TO_DISK); | ||
} | ||
} | ||
Err(cause) => { | ||
if SHOULD_LOG_JSON() { | ||
error!( | ||
id = "bridgectl::mion::dump_eeprom::failure", | ||
%bridge_ip, | ||
?cause, | ||
"Failure to dump MION's EEPROM memory", | ||
); | ||
} else { | ||
error!( | ||
"\n{:?}", | ||
miette!("Could not dump MION's EEPROM Memory.").wrap_err(cause), | ||
); | ||
} | ||
|
||
std::process::exit(DUMP_EEPROM_FAILURE); | ||
} | ||
} | ||
} |
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,102 @@ | ||
//! Dump the memory for a running CAT-DEV. | ||
use crate::{ | ||
commands::argv_helpers::get_targeted_bridge_ip, | ||
exit_codes::{DUMP_MEMORY_FAILURE, FAILED_TO_WRITE_TO_DISK}, | ||
SHOULD_LOG_JSON, | ||
}; | ||
use cat_dev::mion::cgis::dump_memory_with_writer; | ||
use miette::miette; | ||
use std::{ | ||
fs::OpenOptions, | ||
io::{BufWriter, Write}, | ||
path::PathBuf, | ||
}; | ||
use tracing::{error, info}; | ||
|
||
/// Actual command handler for the `mion dump-memory` command. | ||
pub async fn handle_dump_memory(output_path: Option<PathBuf>, resume_at: Option<usize>) { | ||
let bridge_ip = get_targeted_bridge_ip().await; | ||
if SHOULD_LOG_JSON() { | ||
info!( | ||
id = "bridgectl::mion::dump_memory::start", | ||
%bridge_ip, | ||
"Dumping MION Memory, this will take a LONG time...", | ||
); | ||
} else { | ||
info!( | ||
%bridge_ip, | ||
"Dumping MION Memory, this will take a LONG time...", | ||
); | ||
} | ||
|
||
let path = output_path.unwrap_or(PathBuf::from("88F6281-memory.bin")); | ||
let file_writer = match OpenOptions::new() | ||
.write(true) | ||
.append(resume_at.is_some()) | ||
.create(true) | ||
.open(&path) | ||
{ | ||
Ok(val) => val, | ||
Err(cause) => { | ||
if SHOULD_LOG_JSON() { | ||
error!( | ||
id = "bridgectl::mion::dump_memory::write_failure", | ||
%bridge_ip, | ||
?cause, | ||
path = %path.to_string_lossy(), | ||
"Failed to write 88F6281 memory to disk!", | ||
); | ||
} else { | ||
error!( | ||
"\n{:?}", | ||
miette!("Could not write successfully dumped MION's 88F6281 Memory") | ||
.wrap_err(cause), | ||
); | ||
} | ||
|
||
std::process::exit(FAILED_TO_WRITE_TO_DISK); | ||
} | ||
}; | ||
let mut buff_writer = BufWriter::new(file_writer); | ||
|
||
if let Err(cause) = dump_memory_with_writer(bridge_ip, resume_at, |bytes: Vec<u8>| { | ||
if let Err(cause) = buff_writer.write(&bytes) { | ||
if SHOULD_LOG_JSON() { | ||
error!( | ||
id = "bridgectl::mion::dump_memory::write_failure", | ||
%bridge_ip, | ||
?cause, | ||
path = %path.to_string_lossy(), | ||
"Failed to write 88F6281 memory to disk!", | ||
); | ||
} else { | ||
error!( | ||
"\n{:?}", | ||
miette!("Could not write successfully dumped MION's 88F6281 Memory") | ||
.wrap_err(cause), | ||
); | ||
} | ||
|
||
std::process::exit(FAILED_TO_WRITE_TO_DISK); | ||
} | ||
}) | ||
.await | ||
{ | ||
if SHOULD_LOG_JSON() { | ||
error!( | ||
id = "bridgectl::mion::dump_memory::failure", | ||
%bridge_ip, | ||
?cause, | ||
"Failure to dump MION's memory", | ||
); | ||
} else { | ||
error!( | ||
"\n{:?}", | ||
miette!("Could not dump MION's Memory.").wrap_err(cause), | ||
); | ||
} | ||
|
||
std::process::exit(DUMP_MEMORY_FAILURE); | ||
} | ||
} |
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,7 @@ | ||
//! Subdirectory containing MION subcommands. | ||
mod dump_eeprom; | ||
mod dump_memory; | ||
|
||
pub use dump_eeprom::*; | ||
pub use dump_memory::*; |
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 |
---|---|---|
|
@@ -28,3 +28,5 @@ pub use remove::*; | |
pub use set_default::*; | ||
pub use set_parameters::*; | ||
pub use tail::*; | ||
|
||
pub mod mion; |
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
Oops, something went wrong.