aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2022-11-01 21:55:55 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2022-11-01 21:55:55 +0100
commit46f47b5e7f1f6653bcfcda7de12e74adfcd8d5ca (patch)
tree02a73097663db308f92d2569ba34009ae5ae54af
parent5e827e178ae7b9d7c71d34fa27870f05441f3fc0 (diff)
optimise push_net6 function
-rw-r--r--src/main.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 73c0d89..5661c2d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,6 +26,7 @@ enum Error {
PrefixLen(ipnet::PrefixLenError),
Io(std::io::Error),
SerdeJson(serde_json::Error),
+ MissingRecord(i32),
}
impl std::error::Error for Error {}
@@ -42,6 +43,7 @@ impl fmt::Display for Error {
Self::PrefixLen(e) => write!(fmt, "prefix length error: {}", e),
Self::Io(e) => write!(fmt, "io error: {}", e),
Self::SerdeJson(e) => write!(fmt, "serde_json library error: {}", e),
+ Self::MissingRecord(id) => write!(fmt, "missing ipv6 record (id: {})", id),
}
}
}
@@ -399,7 +401,6 @@ fn push_net6(config: Arc<Config>, rx: &mpsc::Receiver<Ipv6Net>) -> Result<()> {
let clt = Client::login(Endpoint::Sandbox, user, pass)?;
- let mut total_records = Vec::new();
for id in &config.records_net6 {
let info: RecordInfoResponse = clt
.call(RecordInfoCall {
@@ -414,17 +415,12 @@ fn push_net6(config: Arc<Config>, rx: &mpsc::Receiver<Ipv6Net>) -> Result<()> {
})?
.try_into()?;
- let mut records = info
- .records
- .expect("no AAAA records (this should never happen");
+ let records = info.records.ok_or(Error::MissingRecord(*id))?;
+ let record = records.first().ok_or(Error::MissingRecord(*id))?;
- total_records.append(&mut records);
- }
-
- for record in total_records {
let address = Ipv6Addr::from_str(&record.content)?;
- // Get the interface identifier.
+ // Get the interface identifier and append it to the new prefix.
let if_id = address.bitand(prefix.hostmask());
let new = prefix.addr().bitor(if_id);