Skip to content

Commit

Permalink
macvlan add bclim option
Browse files Browse the repository at this point in the history
Expose the netlink IFLA_MACVLAN_BC_CUTOFF option as bclim like the ip
command does. We still need c/common and podman patches to allow this
option for podman network create.

Also I created a PR[1] upstream in the netlink lib to allow setting
these options directly instead of using the DefaultNla work around as I
do here.

[1] rust-netlink/netlink-packet-route#32

This is needed for https://bugzilla.redhat.com/show_bug.cgi?id=2183896

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 24, 2023
1 parent 0bf54e1 commit cd9f2f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ zbus = { version = "3.12.0" }
nix = "0.26.2"
rand = "0.8.5"
sha2 = "0.10.6"
netlink-packet-utils = "0.5"
netlink-packet-route = "0.15"
netlink-packet-core = "0.5"
fs2 = "0.4.3"
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dhcp_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl<W: Write + Clear + Send + 'static> NetavarkProxy for NetavarkProxyService<W
&self,
request: Request<NetworkConfig>,
) -> Result<Response<NetavarkLease>, Status> {
//let info = request.extensions().get::<tonic::transport::server::UdsConnectInfo>().unwrap();
debug!("Request from client {:?}", request.remote_addr());
// notify server of activity
self.reset_inactivity_timeout();
Expand All @@ -97,24 +98,30 @@ impl<W: Write + Clear + Send + 'static> NetavarkProxy for NetavarkProxyService<W
let lease = tokio::task::spawn(async move {
// Check if the connection has been dropped before attempting to get a lease
if rx.try_recv() == Err(TryRecvError::Closed) {
log::debug!("Request dropped, aborting DORA");
log::error!("Request dropped, aborting DORA");
return Err(Status::new(Code::Aborted, "client disconnected"));
}


let get_lease = process_setup(network_config, &timeout, cache);
// watch the client and the lease, which ever finishes first return
let get_lease: NetavarkLease = tokio::select! {
_ = &mut rx => {
// we never send to tx, so this completing means that the other end, tx, was dropped!
log::debug!("Request dropped, aborting DORA");
log::error!("Request dropped, aborting DORA1");
return Err(Status::new(Code::Aborted, "client disconnected"))
}
lease = get_lease => {
Ok::<NetavarkLease, Status>(lease?)
}
_ = tokio::time::sleep(Duration::from_millis(10000)) => {
log::error!("after sleep");
return Err(Status::new(Code::Aborted, "timout"))
}
}?;
// check after lease was found that the client is still there
if rx.try_recv() == Err(TryRecvError::Closed) {
log::debug!("Request dropped, aborting DORA");
log::error!("Request dropped, aborting DORA2");
return Err(Status::new(Code::Aborted, "client disconnected"));
}

Expand Down
40 changes: 31 additions & 9 deletions src/network/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use log::{debug, error};
use std::{collections::HashMap, net::IpAddr, os::unix::prelude::RawFd};

use netlink_packet_route::nlas::link::{InfoData, InfoIpVlan, InfoKind, InfoMacVlan, Nla};
use netlink_packet_utils::nla::DefaultNla;
use rand::distributions::{Alphanumeric, DistString};

use crate::network::macvlan_dhcp::{get_dhcp_lease, release_dhcp_lease};
Expand Down Expand Up @@ -30,6 +31,9 @@ enum KindData {
mac_address: Option<Vec<u8>>,
/// macvlan mode
mode: u32,

// IFLA_MACVLAN_BC_CUTOFF option if set
bclim: Option<i32>,
},
IpVlan {
/// ipvlan mode
Expand Down Expand Up @@ -117,13 +121,17 @@ impl driver::NetworkDriver for Vlan<'_> {
super::constants::DRIVER_IPVLAN => KindData::IpVlan {
mode: CoreUtils::get_ipvlan_mode_from_string(mode.as_deref())?,
},
super::constants::DRIVER_MACVLAN => KindData::MacVlan {
mode: CoreUtils::get_macvlan_mode_from_string(mode.as_deref())?,
mac_address: match &self.info.per_network_opts.static_mac {
Some(mac) => Some(CoreUtils::decode_address_from_hex(mac)?),
None => None,
},
},
super::constants::DRIVER_MACVLAN => {
let bclim = parse_option(&self.info.network.options, "bclim")?;
KindData::MacVlan {
mode: CoreUtils::get_macvlan_mode_from_string(mode.as_deref())?,
mac_address: match &self.info.per_network_opts.static_mac {
Some(mac) => Some(CoreUtils::decode_address_from_hex(mac)?),
None => None,
},
bclim: bclim,
}
}
other => {
return Err(NetavarkError::msg(format!(
"unsupported VLAN type {}",
Expand Down Expand Up @@ -268,13 +276,27 @@ fn setup(
opts.info_data = Some(InfoData::IpVlan(vec![InfoIpVlan::Mode(*mode)]));
opts
}
KindData::MacVlan { mode, mac_address } => {
KindData::MacVlan {
mode,
mac_address,
bclim,
} => {
let mut opts = CreateLinkOptions::new(if_name.to_string(), InfoKind::MacVlan);
opts.mac = mac_address.clone().unwrap_or_default();
opts.mtu = data.mtu;
opts.netns = netns_fd;
opts.link = link.header.index;
opts.info_data = Some(InfoData::MacVlan(vec![InfoMacVlan::Mode(*mode)]));

let mut mv_opts = vec![InfoMacVlan::Mode(*mode)];
if let Some(bclim) = bclim {
debug!("setting macvlan bclim to {bclim}");
// TODO: change this to use the upstream const when available
// https://github.com/rust-netlink/netlink-packet-route/pull/32
// IFLA_MACVLAN_BC_CUTOFF const in the kernel is 9
mv_opts.push(InfoMacVlan::Other(DefaultNla::new(9, bclim.to_ne_bytes().to_vec())))
}

opts.info_data = Some(InfoData::MacVlan(mv_opts));
opts
}
};
Expand Down

0 comments on commit cd9f2f1

Please sign in to comment.