diff --git a/src/network/constants.rs b/src/network/constants.rs index 30a7394be..67eb235c2 100644 --- a/src/network/constants.rs +++ b/src/network/constants.rs @@ -3,14 +3,6 @@ // default search domain pub static PODMAN_DEFAULT_SEARCH_DOMAIN: &str = "dns.podman"; -// Available macvlan modes -// TODO: remove constants from here after https://github.com/little-dude/netlink/pull/200 -pub const MACVLAN_MODE_PRIVATE: u32 = 1; -pub const MACVLAN_MODE_VEPA: u32 = 2; -pub const MACVLAN_MODE_BRIDGE: u32 = 4; -pub const MACVLAN_MODE_PASSTHRU: u32 = 8; -pub const MACVLAN_MODE_SOURCE: u32 = 16; - // IPAM drivers pub const IPAM_HOSTLOCAL: &str = "host-local"; pub const IPAM_DHCP: &str = "dhcp"; diff --git a/src/network/core_utils.rs b/src/network/core_utils.rs index 8ca39d3fb..2f0c45d6e 100644 --- a/src/network/core_utils.rs +++ b/src/network/core_utils.rs @@ -2,6 +2,10 @@ use crate::error::{ErrorWrap, NetavarkError, NetavarkResult}; use crate::network::{constants, internal_types, types}; use crate::wrap; use log::debug; +use netlink_packet_route::{ + MACVLAN_MODE_BRIDGE, MACVLAN_MODE_PASSTHRU, MACVLAN_MODE_PRIVATE, MACVLAN_MODE_SOURCE, + MACVLAN_MODE_VEPA, +}; use nix::sched; use sha2::{Digest, Sha512}; use std::collections::HashMap; @@ -195,20 +199,19 @@ impl CoreUtils { Ok(result) } - pub fn get_macvlan_mode_from_string(mode: &str) -> Result { - // Replace to constant from library once this gets merged. - // TODO: use actual constants after https://github.com/little-dude/netlink/pull/200 + pub fn get_macvlan_mode_from_string(mode: &str) -> NetavarkResult { match mode { - "" | "bridge" => Ok(constants::MACVLAN_MODE_BRIDGE), - "private" => Ok(constants::MACVLAN_MODE_PRIVATE), - "vepa" => Ok(constants::MACVLAN_MODE_VEPA), - "passthru" => Ok(constants::MACVLAN_MODE_PASSTHRU), - "source" => Ok(constants::MACVLAN_MODE_SOURCE), + // default to bridge when unset + "" | "bridge" => Ok(MACVLAN_MODE_BRIDGE), + "private" => Ok(MACVLAN_MODE_PRIVATE), + "vepa" => Ok(MACVLAN_MODE_VEPA), + "passthru" => Ok(MACVLAN_MODE_PASSTHRU), + "source" => Ok(MACVLAN_MODE_SOURCE), // default to bridge - _ => Err(std::io::Error::new( - std::io::ErrorKind::Other, - "invalid macvlan mode", - )), + name => Err(NetavarkError::msg(format!( + "invalid macvlan mode \"{}\"", + name + ))), } }