diff --git a/src/main.rs b/src/main.rs index 5bf4868..2ed638c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,8 +113,7 @@ async fn main() -> Result<(), Box> { }; let dest_addr = if let Some(IpHeader::Version6(header, _)) = packet.ip { - let dest_addr = Ipv6Addr::from(header.destination); - dest_addr + Ipv6Addr::from(header.destination) } else { continue; }; @@ -123,7 +122,7 @@ async fn main() -> Result<(), Box> { // Check if destination address is in 200::/7 range let first_byte = dest_addr.segments()[0] >> 8; // get the first byte - if first_byte < 0x02 || first_byte > 0x3F { + if !(0x02..=0x3F).contains(&first_byte) { continue; } diff --git a/src/metric.rs b/src/metric.rs index 2d4ac4d..0500720 100644 --- a/src/metric.rs +++ b/src/metric.rs @@ -1,6 +1,8 @@ //! Dedicated logic for //! [metrics](https://datatracker.ietf.org/doc/html/rfc8966#metric-computation). +#![allow(clippy::suspicious_arithmetic_impl)] + use core::fmt; use std::ops::Add; diff --git a/src/router.rs b/src/router.rs index b8e2b49..7827fab 100644 --- a/src/router.rs +++ b/src/router.rs @@ -7,7 +7,7 @@ use crate::{ source_table::{FeasibilityDistance, SourceKey, SourceTable}, x25519::{self, shared_secret_from_keypair}, }; -use log::{debug, error, info, trace, warn}; +use log::{error, info, trace, warn}; use std::{ collections::HashMap, error::Error, @@ -228,7 +228,7 @@ impl Router { // create retraction update for each dead peer let retraction_update = ControlPacket::new_update( 32, - UPDATE_INTERVAL as u16, + UPDATE_INTERVAL, inner.router_seqno, Metric::infinite(), dead_peer.overlay_ip(), // todo: fix to use actual prefix, not IP @@ -338,7 +338,6 @@ impl Router { // if no entry exists (based on prefix, plen AND neighbor field) if !route_entry_exists { if metric.is_infinite() || !inner.source_table.is_update_feasible(&update) { - return; } else { // this means that the update is feasible and the metric is not infinite // create a new route entry and add it to the routing table (which requires a new source entry to be created as well) @@ -643,7 +642,7 @@ impl Router { return true; } } - return false; + false } async fn handle_incoming_data_packet(self, mut router_data_rx: UnboundedReceiver) { @@ -717,7 +716,7 @@ impl Router { // println!("\n\n best route towards {}: {:?}", dest_ip, best_route); - return best_route; + best_route } pub async fn propagate_static_route(self) { @@ -785,13 +784,13 @@ impl RouterInner { peer_interfaces: Vec::new(), router_control_tx, router_data_tx, - node_tun: node_tun, + node_tun, selected_routing_table: RoutingTable::new(), fallback_routing_table: RoutingTable::new(), source_table: SourceTable::new(), router_seqno: SeqNo::default(), - static_routes: static_routes, - node_keypair: node_keypair, + static_routes, + node_keypair, node_tun_addr, dest_pubkey_map: HashMap::new(), }; @@ -861,7 +860,7 @@ impl RouterInner { for peer in self.peer_interfaces.iter() { let update = ControlPacket::new_update( sr.plen, // static routes have plen 32 - UPDATE_INTERVAL as u16, + UPDATE_INTERVAL, self.router_seqno, // updates receive the seqno of the router peer.link_cost().into(), // direct connection to other peer, so the only cost is the cost towards the peer sr.prefix, // the prefix of a static route corresponds to the TUN addr of the node @@ -892,7 +891,7 @@ impl RouterInner { let update = ControlPacket::new_update( sr.0.plen(), - UPDATE_INTERVAL as u16, + UPDATE_INTERVAL, self.router_seqno, // updates receive the seqno of the router sr.1.metric() + Metric::from(peer_link_cost), // the cost of the route is the cost of the route + the cost of the link to the peer diff --git a/src/sequence_number.rs b/src/sequence_number.rs index ac39b09..04f22b5 100644 --- a/src/sequence_number.rs +++ b/src/sequence_number.rs @@ -9,7 +9,7 @@ use core::ops::{Add, AddAssign}; const SEQNO_COMPARE_TRESHOLD: u16 = 32_768; /// A sequence number on a route. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] pub struct SeqNo(u16); impl SeqNo { @@ -40,12 +40,6 @@ impl fmt::Display for SeqNo { } } -impl Default for SeqNo { - fn default() -> Self { - SeqNo(0) - } -} - impl From for SeqNo { fn from(value: u16) -> Self { SeqNo(value) diff --git a/src/source_table.rs b/src/source_table.rs index 250291e..0e7eb4f 100644 --- a/src/source_table.rs +++ b/src/source_table.rs @@ -111,16 +111,16 @@ impl SourceTable { let source_key = SourceKey::new(prefix, plen, router_id); match self.get(&source_key) { Some(&entry) => { - return (!seqno.lt(&entry.seqno())) + (!seqno.lt(&entry.seqno())) || (seqno == entry.seqno() && metric < entry.metric()) - || metric.is_infinite(); + || metric.is_infinite() } - None => return true, + None => true, } } _ => { error!("Error accepting update, control struct did not match update packet"); - return false; + false } } } diff --git a/src/x25519.rs b/src/x25519.rs index 3faa55b..15de080 100644 --- a/src/x25519.rs +++ b/src/x25519.rs @@ -19,9 +19,9 @@ pub fn get_keypair() -> Result<(StaticSecret, PublicKey), Box Result<(StaticSecret, PublicKey), Box