Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add support setting for MTU on macvlan interface from netavark config #158

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/network/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ impl Core {
}
}

// mtu to configure, 0 means it was not set do nothing.
let mut mtu_config: u32 = 0;
if let Some(options_map) = network.options.as_ref() {
if let Some(mtu) = options_map.get("mtu") {
match mtu.parse() {
Ok(mtu) => {
mtu_config = mtu;
}
Err(err) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("unable to parse mtu: {}", err),
))
}
}
}
}

// get master interface name
let mut master_ifname: String = match network.network_interface.as_ref() {
None => {
Expand Down Expand Up @@ -402,6 +420,7 @@ impl Core {
&master_ifname,
&container_macvlan_name,
macvlan_mode,
mtu_config,
address_vector,
netns,
) {
Expand All @@ -428,13 +447,15 @@ impl Core {
master_ifname: &str,
container_macvlan: &str,
macvlan_mode: u32,
mtu: u32,
netns_ipaddr: Vec<ipnet::IpNet>,
netns: &str,
) -> Result<String, std::io::Error> {
let _ = match core_utils::CoreUtils::configure_macvlan_async(
master_ifname,
container_macvlan,
macvlan_mode,
mtu,
netns,
) {
Ok(_) => (),
Expand Down
12 changes: 12 additions & 0 deletions src/network/core_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ impl CoreUtils {
master_ifname: &str,
macvlan_ifname: &str,
macvlan_mode: u32,
mtu: u32,
netns_path: &str,
) -> Result<(), Error> {
let (_connection, handle, _) = match rtnetlink::new_connection() {
Expand Down Expand Up @@ -705,6 +706,17 @@ impl CoreUtils {
}
}

// configure mtu of macvlan interface
// before moving it to network namespace
// See: https://github.com/containernetworking/plugins/blob/master/plugins/main/macvlan/macvlan.go#L181
if mtu != 0 {
if let Err(err) =
CoreUtils::set_link_mtu(&handle, &macvlan_tmp_name.to_owned(), mtu).await
{
return Err(err);
}
}

// change network namespace of macvlan interface
match File::open(netns_path) {
Ok(netns_file) => {
Expand Down