diff --git a/Cargo.lock b/Cargo.lock index d0bc6dfb..d4adb24d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,7 +1389,7 @@ dependencies = [ "log", "mozim", "netlink-packet-core", - "netlink-packet-route", + "netlink-packet-route 0.20.0", "netlink-packet-utils", "netlink-sys", "nftables", @@ -1450,6 +1450,21 @@ dependencies = [ "netlink-packet-utils", ] +[[package]] +name = "netlink-packet-route" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37142a3d25dff78c49e99c27244827409717366287ff229b16e36cfeee17cf1" +dependencies = [ + "anyhow", + "bitflags 2.5.0", + "byteorder", + "libc", + "log", + "netlink-packet-core", + "netlink-packet-utils", +] + [[package]] name = "netlink-packet-utils" version = "0.5.2" @@ -1515,7 +1530,7 @@ dependencies = [ "libc", "log", "mptcp-pm", - "netlink-packet-route", + "netlink-packet-route 0.19.0", "netlink-packet-utils", "netlink-sys", "rtnetlink", @@ -1879,7 +1894,7 @@ dependencies = [ "futures", "log", "netlink-packet-core", - "netlink-packet-route", + "netlink-packet-route 0.19.0", "netlink-packet-utils", "netlink-proto", "netlink-sys", diff --git a/Cargo.toml b/Cargo.toml index 493c4b9f..440c876c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ nix = { version = "0.29.0", features = ["sched", "signal", "user"] } rand = "0.8.5" sha2 = "0.10.8" netlink-packet-utils = "0.5.2" -netlink-packet-route = "0.19.0" +netlink-packet-route = "0.20.0" netlink-packet-core = "0.7.0" nftables = "0.4" fs2 = "0.4.3" diff --git a/src/network/core_utils.rs b/src/network/core_utils.rs index 8638f98f..34f0caf3 100644 --- a/src/network/core_utils.rs +++ b/src/network/core_utils.rs @@ -3,6 +3,7 @@ use crate::network::{constants, internal_types, types}; use crate::wrap; use ipnet::IpNet; use log::debug; +use netlink_packet_route::link::{IpVlanMode, MacVlanMode}; use nix::sched; use sha2::{Digest, Sha512}; use std::collections::HashMap; @@ -19,18 +20,6 @@ use sysctl::{Sysctl, SysctlError}; use super::netlink; -pub const IPVLAN_MODE_L2: u16 = 0; -pub const IPVLAN_MODE_L3: u16 = 1; -pub const IPVLAN_MODE_L3S: u16 = 2; - -// const were removed upstream: -// https://github.com/rust-netlink/netlink-packet-route/issues/88 -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; - pub struct CoreUtils { pub networkns: String, } @@ -229,14 +218,14 @@ impl CoreUtils { Ok(result) } - pub fn get_macvlan_mode_from_string(mode: Option<&str>) -> NetavarkResult { + pub fn get_macvlan_mode_from_string(mode: Option<&str>) -> NetavarkResult { match mode { // default to bridge when unset - None | Some("") | Some("bridge") => Ok(MACVLAN_MODE_BRIDGE), - Some("private") => Ok(MACVLAN_MODE_PRIVATE), - Some("vepa") => Ok(MACVLAN_MODE_VEPA), - Some("passthru") => Ok(MACVLAN_MODE_PASSTHRU), - Some("source") => Ok(MACVLAN_MODE_SOURCE), + None | Some("") | Some("bridge") => Ok(MacVlanMode::Bridge), + Some("private") => Ok(MacVlanMode::Private), + Some("vepa") => Ok(MacVlanMode::Vepa), + Some("passthru") => Ok(MacVlanMode::Passthrough), + Some("source") => Ok(MacVlanMode::Source), // default to bridge Some(name) => Err(NetavarkError::msg(format!( "invalid macvlan mode \"{name}\"" @@ -244,12 +233,12 @@ impl CoreUtils { } } - pub fn get_ipvlan_mode_from_string(mode: Option<&str>) -> NetavarkResult { + pub fn get_ipvlan_mode_from_string(mode: Option<&str>) -> NetavarkResult { match mode { // default to l2 when unset - None | Some("") | Some("l2") => Ok(IPVLAN_MODE_L2), - Some("l3") => Ok(IPVLAN_MODE_L3), - Some("l3s") => Ok(IPVLAN_MODE_L3S), + None | Some("") | Some("l2") => Ok(IpVlanMode::L2), + Some("l3") => Ok(IpVlanMode::L3), + Some("l3s") => Ok(IpVlanMode::L3S), Some(name) => Err(NetavarkError::msg(format!( "invalid ipvlan mode \"{name}\"" ))), diff --git a/src/network/netlink.rs b/src/network/netlink.rs index c95a67b4..0c0d6d08 100644 --- a/src/network/netlink.rs +++ b/src/network/netlink.rs @@ -15,8 +15,7 @@ use netlink_packet_core::{ }; use netlink_packet_route::{ address::AddressMessage, - link::{InfoData, InfoKind, LinkAttribute, LinkInfo}, - link::{LinkFlag, LinkMessage}, + link::{InfoData, InfoKind, LinkAttribute, LinkFlags, LinkInfo, LinkMessage}, route::{RouteAddress, RouteMessage, RouteProtocol, RouteScope, RouteType}, AddressFamily, RouteNetlinkMessage, }; @@ -395,8 +394,8 @@ impl Socket { LinkID::Name(name) => msg.attributes.push(LinkAttribute::IfName(name)), } - msg.header.flags = vec![LinkFlag::Up]; - msg.header.change_mask = vec![LinkFlag::Up]; + msg.header.flags = LinkFlags::Up; + msg.header.change_mask = LinkFlags::Up; let result = self.make_netlink_request( RouteNetlinkMessage::SetLink(msg), diff --git a/src/network/vlan.rs b/src/network/vlan.rs index 6434d942..f5b6b522 100644 --- a/src/network/vlan.rs +++ b/src/network/vlan.rs @@ -2,7 +2,9 @@ use log::{debug, error}; use std::os::fd::BorrowedFd; use std::{collections::HashMap, net::IpAddr}; -use netlink_packet_route::link::{InfoData, InfoIpVlan, InfoKind, InfoMacVlan, LinkAttribute}; +use netlink_packet_route::link::{ + InfoData, InfoIpVlan, InfoKind, InfoMacVlan, IpVlanMode, LinkAttribute, MacVlanMode, +}; use rand::distributions::{Alphanumeric, DistString}; use crate::network::macvlan_dhcp::{get_dhcp_lease, release_dhcp_lease}; @@ -30,14 +32,14 @@ enum KindData { /// static mac address mac_address: Option>, /// macvlan mode - mode: u32, + mode: MacVlanMode, // IFLA_MACVLAN_BC_CUTOFF option if set bclim: Option, }, IpVlan { /// ipvlan mode - mode: u16, + mode: IpVlanMode, }, }