net_util: Support supplying flags to open_tap() helper

This helper can open a TAP device and configure the interface on it. If
the device needs to be opened multiple times for MQ then it also handles
that correctly.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-01-27 17:52:22 +00:00
parent c4fb0f36bd
commit 5db9b0ec99
3 changed files with 5 additions and 3 deletions

View File

@ -65,6 +65,7 @@ pub fn open_tap(
netmask: Option<Ipv4Addr>, netmask: Option<Ipv4Addr>,
host_mac: &mut Option<MacAddr>, host_mac: &mut Option<MacAddr>,
num_rx_q: usize, num_rx_q: usize,
flags: Option<i32>,
) -> Result<Vec<Tap>> { ) -> Result<Vec<Tap>> {
let mut taps: Vec<Tap> = Vec::new(); let mut taps: Vec<Tap> = Vec::new();
let mut ifname: String = String::new(); let mut ifname: String = String::new();
@ -82,7 +83,7 @@ pub fn open_tap(
let tap: Tap; let tap: Tap;
if i == 0 { if i == 0 {
tap = match if_name { tap = match if_name {
Some(name) => Tap::open_named(name, num_rx_q, None).map_err(Error::TapOpen)?, Some(name) => Tap::open_named(name, num_rx_q, flags).map_err(Error::TapOpen)?,
None => Tap::new(num_rx_q).map_err(Error::TapOpen)?, None => Tap::new(num_rx_q).map_err(Error::TapOpen)?,
}; };
if let Some(ip) = ip_addr { if let Some(ip) = ip_addr {
@ -104,7 +105,7 @@ pub fn open_tap(
ifname = String::from_utf8(tap.get_if_name()).unwrap(); ifname = String::from_utf8(tap.get_if_name()).unwrap();
} else { } else {
tap = Tap::open_named(ifname.as_str(), num_rx_q, None).map_err(Error::TapOpen)?; tap = Tap::open_named(ifname.as_str(), num_rx_q, flags).map_err(Error::TapOpen)?;
tap.set_offload(flag).map_err(Error::TapSetOffload)?; tap.set_offload(flag).map_err(Error::TapSetOffload)?;
tap.set_vnet_hdr_size(vnet_hdr_size) tap.set_vnet_hdr_size(vnet_hdr_size)

View File

@ -143,6 +143,7 @@ impl VhostUserNetBackend {
Some(netmask), Some(netmask),
&mut Some(host_mac), &mut Some(host_mac),
num_queues / 2, num_queues / 2,
None,
) )
.map_err(Error::OpenTap)?; .map_err(Error::OpenTap)?;

View File

@ -283,7 +283,7 @@ impl Net {
queue_size: u16, queue_size: u16,
seccomp_action: SeccompAction, seccomp_action: SeccompAction,
) -> Result<Self> { ) -> Result<Self> {
let taps = open_tap(if_name, ip_addr, netmask, host_mac, num_queues / 2) let taps = open_tap(if_name, ip_addr, netmask, host_mac, num_queues / 2, None)
.map_err(Error::OpenTap)?; .map_err(Error::OpenTap)?;
Self::new_with_tap( Self::new_with_tap(