Skip to content

Commit

Permalink
core, macvlan: add support setting for MTU from netavark config
Browse files Browse the repository at this point in the history
Netavark config accepts `MTU` as network option so allow users to
configure the same for `macvlan` interface.

See https://github.com/containernetworking/plugins/blob/master/plugins/main/macvlan/macvlan.go#L181

Follow up PR to: containers#111

Signed-off-by: Aditya Rajan <[email protected]>
  • Loading branch information
flouthoc committed Jan 12, 2022
1 parent d847a7f commit 4ff62e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 4ff62e6

Please sign in to comment.