Skip to content

Commit

Permalink
fix new clippy warnings
Browse files Browse the repository at this point in the history
Remove some unused ipva code fromt he dhcp proxy, I don't see us needing
this anythime soon and we can always add it back later.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 7, 2024
1 parent ed7cfd8 commit 87fe59f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 88 deletions.
41 changes: 2 additions & 39 deletions src/dhcp_proxy/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,9 @@ use crate::network::netlink;
use crate::network::netlink::Socket;
use ipnet::IpNet;
use log::debug;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;

trait IpConv {
fn to_v4(&self) -> Result<&Ipv4Addr, ProxyError>;
fn to_v6(&self) -> Result<&Ipv6Addr, ProxyError>;
}

// Simple implementation for converting from IPAddr to
// specific IP type
impl IpConv for IpAddr {
fn to_v4(&self) -> Result<&Ipv4Addr, ProxyError> {
match self {
IpAddr::V4(ip) => Ok(ip),
IpAddr::V6(_) => Err(ProxyError::new(
"invalid value for ipv4 conversion".to_string(),
)),
}
}

fn to_v6(&self) -> Result<&Ipv6Addr, ProxyError> {
match self {
IpAddr::V4(_) => Err(ProxyError::new(
"invalid value for ipv6 conversion".to_string(),
)),
IpAddr::V6(ip) => Ok(ip),
}
}
}

/*
Information that came back in the DHCP lease like name_servers,
domain and host names, etc. will be implemented in podman; not here.
Expand All @@ -63,7 +36,6 @@ trait Address<T> {
Self: Sized;
fn add_ip(&self, nls: &mut Socket) -> Result<(), ProxyError>;
fn add_gws(&self, nls: &mut Socket) -> Result<(), ProxyError>;
fn remove(self) -> Result<(), ProxyError>;
}

fn handle_gws(g: Vec<String>, netmask: &str) -> Result<Vec<IpNet>, ProxyError> {
Expand Down Expand Up @@ -122,7 +94,7 @@ impl Address<Ipv4Addr> for MacVLAN {
let gateways = match handle_gws(l.gateways.clone(), &l.subnet_mask) {
Ok(g) => g,
Err(e) => {
return Err(ProxyError::new(format!("bad gateways: {}", e.to_string())));
return Err(ProxyError::new(format!("bad gateways: {}", e)));
}
};
let prefix_length = match get_prefix_length_v4(&l.subnet_mask) {
Expand Down Expand Up @@ -158,15 +130,6 @@ impl Address<Ipv4Addr> for MacVLAN {
Err(e) => Err(ProxyError::new(e.to_string())),
}
}

/*
For now, nv will remove the interface; this causes all IP stuff
to fold.
*/
fn remove(self) -> Result<(), ProxyError> {
debug!("removing interface {}", self.interface);
todo!()
}
}

// setup takes the DHCP lease and some additional information and
Expand Down
17 changes: 1 addition & 16 deletions src/dhcp_proxy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use g_rpc::netavark_proxy_client::NetavarkProxyClient;
use log::debug;
use std::fs::File;
use std::net::AddrParseError;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::net::Ipv4Addr;
use std::str::FromStr;
use tokio::net::UnixStream;
use tonic::transport::{Channel, Endpoint, Uri};
Expand Down Expand Up @@ -271,7 +271,6 @@ impl NetworkConfig {

trait VectorConv {
fn to_v4_addrs(&self) -> Result<Option<Vec<Ipv4Addr>>, AddrParseError>;
fn to_v6_addrs(&self) -> Result<Option<Vec<Ipv6Addr>>, AddrParseError>;
}

impl VectorConv for Vec<String> {
Expand All @@ -288,18 +287,4 @@ impl VectorConv for Vec<String> {
}
Ok(Some(out_addrs))
}

fn to_v6_addrs(&self) -> Result<Option<Vec<Ipv6Addr>>, AddrParseError> {
if self.is_empty() {
return Ok(None);
}
let mut out_addrs = Vec::new();
for ip in self {
match Ipv6Addr::from_str(ip) {
Ok(i) => out_addrs.push(i),
Err(e) => return Err(e),
};
}
Ok(Some(out_addrs))
}
}
6 changes: 3 additions & 3 deletions src/dhcp_proxy/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl CustomErr for ProxyError {
}
}

impl ToString for ProxyError {
fn to_string(&self) -> String {
self.0.to_string()
impl std::fmt::Display for ProxyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/dns/aardvark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl Aardvark {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&lockfile_path)
{
Ok(file) => file,
Expand Down Expand Up @@ -355,7 +356,7 @@ impl Aardvark {
pub fn modify_network_dns_servers(
&self,
network_name: &str,
network_dns_servers: &Vec<String>,
network_dns_servers: &[String],
) -> NetavarkResult<()> {
let mut dns_servers_modified = false;
let path = Path::new(&self.config).join(network_name);
Expand Down
52 changes: 24 additions & 28 deletions src/network/macvlan_dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ pub fn get_dhcp_lease(
container_iface: container_network_interface.to_string(),
container_mac_addr: container_macvlan_mac.to_string(),
};
let lease = match {
tokio::task::LocalSet::new().block_on(
match &tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
{
Ok(r) => r,
Err(e) => {
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
}
},
nvp_config.get_lease(DEFAULT_UDS_PATH),
)
} {
let lease = match tokio::task::LocalSet::new().block_on(
match &tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
{
Ok(r) => r,
Err(e) => {
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
}
},
nvp_config.get_lease(DEFAULT_UDS_PATH),
) {
Ok(l) => l,
Err(e) => {
return Err(NetavarkError::msg(format!("unable to obtain lease: {e}")));
Expand Down Expand Up @@ -114,20 +112,18 @@ pub fn release_dhcp_lease(
container_iface: container_network_interface.to_string(),
container_mac_addr: container_macvlan_mac.to_string(),
};
match {
tokio::task::LocalSet::new().block_on(
match &tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
{
Ok(r) => r,
Err(e) => {
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
}
},
nvp_config.drop_lease(DEFAULT_UDS_PATH),
)
} {
match tokio::task::LocalSet::new().block_on(
match &tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
{
Ok(r) => r,
Err(e) => {
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
}
},
nvp_config.drop_lease(DEFAULT_UDS_PATH),
) {
Ok(_) => {}
Err(e) => {
return Err(NetavarkError::Message(e.to_string()));
Expand Down
2 changes: 1 addition & 1 deletion src/network/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn setup(
let random = Alphanumeric.sample_string(&mut rand::thread_rng(), 10);
let tmp_name = "mv-".to_string() + &random;
let mut opts = opts.clone();
opts.name = tmp_name.clone();
opts.name.clone_from(&tmp_name);
result = host.create_link(opts);
if let Err(ref e) = result {
// if last element return directly
Expand Down

0 comments on commit 87fe59f

Please sign in to comment.