MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / open_tap

Function open_tap

net_util/src/open_tap.rs:110–147  ·  view source on GitHub ↗

Create a new virtio network device with the given IP address and netmask.

(
    if_name: Option<&str>,
    ip_addr: Option<IpAddr>,
    netmask: Option<IpAddr>,
    host_mac: &mut Option<MacAddr>,
    mtu: Option<u16>,
    num_rx_q: usize,
    flags: Option<i32>,
)

Source from the content-addressed store, hash-verified

108/// Create a new virtio network device with the given IP address and
109/// netmask.
110pub fn open_tap(
111 if_name: Option<&str>,
112 ip_addr: Option<IpAddr>,
113 netmask: Option<IpAddr>,
114 host_mac: &mut Option<MacAddr>,
115 mtu: Option<u16>,
116 num_rx_q: usize,
117 flags: Option<i32>,
118) -> Result<Vec<Tap>> {
119 let mut taps: Vec<Tap> = Vec::new();
120 let mut ifname: String = String::new();
121
122 // In case the tap interface already exists, check if the number of
123 // queues is appropriate. The tap might not support multiqueue while
124 // the number of queues indicates the user expects multiple queues, or
125 // on the contrary, the tap might support multiqueue while the number
126 // of queues indicates the user doesn't expect multiple queues.
127 check_mq_support(&if_name, num_rx_q)?;
128
129 for i in 0..num_rx_q {
130 let tap: Tap;
131 if i == 0 {
132 // Special handling is required for the first RX queue, such as
133 // configuring the device. Subsequent iterations will then use the
134 // same device.
135 tap = open_tap_rx_q_0(if_name, ip_addr, netmask, host_mac, mtu, num_rx_q, flags)?;
136 // Set the name of the tap device we open in subsequent iterations.
137 ifname = tap.if_name_as_str().to_string();
138 } else {
139 tap = Tap::open_named(ifname.as_str(), num_rx_q, flags).map_err(Error::TapOpen)?;
140
141 tap.set_vnet_hdr_size(vnet_hdr_len() as i32)
142 .map_err(Error::TapSetVnetHdrSize)?;
143 }
144 taps.push(tap);
145 }
146 Ok(taps)
147}

Callers 4

_test_tap_from_fdFunction · 0.85
newMethod · 0.85
newMethod · 0.85

Calls 7

newFunction · 0.85
check_mq_supportFunction · 0.85
open_tap_rx_q_0Function · 0.85
vnet_hdr_lenFunction · 0.85
if_name_as_strMethod · 0.80
set_vnet_hdr_sizeMethod · 0.80
pushMethod · 0.45

Tested by 2

_test_tap_from_fdFunction · 0.68