From 4ff62e68d31ab8ff8a78a6c7f71f4a604a50d43a Mon Sep 17 00:00:00 2001 From: Aditya Rajan Date: Wed, 12 Jan 2022 10:55:08 +0530 Subject: [PATCH] core, macvlan: add support setting for MTU from netavark config 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: https://github.com/containers/netavark/pull/111 Signed-off-by: Aditya Rajan --- src/network/core.rs | 21 +++++++++++++++++++++ src/network/core_utils.rs | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/network/core.rs b/src/network/core.rs index fdeb5ce7e..e8374edb3 100644 --- a/src/network/core.rs +++ b/src/network/core.rs @@ -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 => { @@ -402,6 +420,7 @@ impl Core { &master_ifname, &container_macvlan_name, macvlan_mode, + mtu_config, address_vector, netns, ) { @@ -428,6 +447,7 @@ impl Core { master_ifname: &str, container_macvlan: &str, macvlan_mode: u32, + mtu: u32, netns_ipaddr: Vec, netns: &str, ) -> Result { @@ -435,6 +455,7 @@ impl Core { master_ifname, container_macvlan, macvlan_mode, + mtu, netns, ) { Ok(_) => (), diff --git a/src/network/core_utils.rs b/src/network/core_utils.rs index ae7228510..68aab31a8 100644 --- a/src/network/core_utils.rs +++ b/src/network/core_utils.rs @@ -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() { @@ -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) => {