pub async fn create_lif(
        &mut self,
        lif_type: LIFType,
        name: String,
        vlan: Option<u16>,
        ports: &[PortId],
    ) -> error::Result<lifmgr::LIF> {
        if ports.is_empty() {
            // At least one port is needed.
            return Err(error::NetworkManager::Lif(error::Lif::NotSupported));
        }
        let reserved: Vec<PortId> = ports
            .iter()
            .filter_map(|p| if self.port_manager.use_port(*p) { Some(*p) } else { None })
            .collect();
        if reserved.len() != ports.len() {
            self.release_ports(&reserved);
            return Err(error::NetworkManager::Lif(error::Lif::InvalidPort));
        }

        // TODO(cgibson): Once we can configure VLANs, we need to handle VLAN ID 0 vs None, since
        // VLAN ID 0x0000 is a reserved value in dot1q. fxbug.dev/41746.
        let vid = match vlan {
            Some(v) => v,
            None => 0,
        };

        let mut l = lifmgr::LIF::new(
            self.version,
            lif_type,
            &name,
            PortId::from(0),
            reserved.clone(),
            vid,
            Some(LIFProperties::default()),
        )
        .or_else(|e| {
            self.release_ports(&reserved);
            Err(e)
        })?;
        if reserved.len() > 1 {
            // Multiple ports, bridge them.
            let id = self.hal.create_bridge(reserved.clone()).await.or_else(|e| {
                self.release_ports(&reserved);
                Err(e)
            })?;
            // LIF ID is associated with the bridge.
            let () = l.set_pid(id);
        } else {
            let () = l.set_pid(reserved[0]);
        }
        let r = self.lif_manager.add_lif(&l);
        if let Err(e) = r {
            self.release_ports(&reserved);
            // nothing to do if delete_bridge fails, all state changes have been reverted
            // already, just return an error to let caller handle it as appropriate.
            self.hal.delete_bridge(l.pid()).await?;
            return Err(e);
        }
        // all went well, increase version.
        self.version += 1;
        Ok(l)
    }
/// Creates a LIF of the given type.
Creates a LIF of the given type.
Creates a LIF of the given type .
pub async fn create_lif(
        &mut self,
        lif_type: LIFType,
        name: String,
        vlan: Option<u16>,
        ports: &[PortId],
    ) -> error::Result<lifmgr::LIF> {
        if ports.is_empty() {
            // At least one port is needed.
            return Err(error::NetworkManager::Lif(error::Lif::NotSupported));
        }
        let reserved: Vec<PortId> = ports
            .iter()
            .filter_map(|p| if self.port_manager.use_port(*p) { Some(*p) } else { None })
            .collect();
        if reserved.len() != ports.len() {
            self.release_ports(&reserved);
            return Err(error::NetworkManager::Lif(error::Lif::InvalidPort));
        }
        // TODO(cgibson): Once we can configure VLANs, we need to handle VLAN ID 0 vs None, since
        // VLAN ID 0x0000 is a reserved value in dot1q. fxbug.dev/41746.
        let vid = match vlan {
            Some(v) => v,
            None => 0,
        };
        let mut l = lifmgr::LIF::new(
            self.version,
            lif_type,
            &name,
            PortId::from(0),
            reserved.clone(),
            vid,
            Some(LIFProperties::default()),
        )
        .or_else(|e| {
            self.release_ports(&reserved);
            Err(e)
        })?;
        if reserved.len() > 1 {
            // Multiple ports, bridge them.
            let id = self.hal.create_bridge(reserved.clone()).await.or_else(|e| {
                self.release_ports(&reserved);
                Err(e)
            })?;
            // LIF ID is associated with the bridge.
            let () = l.set_pid(id);
        } else {
            let () = l.set_pid(reserved[0]);
        }
        let r = self.lif_manager.add_lif(&l);
        if let Err(e) = r {
            self.release_ports(&reserved);
            // nothing to do if delete_bridge fails, all state changes have been reverted
            // already, just return an error to let caller handle it as appropriate.
            self.hal.delete_bridge(l.pid()).await?;
            return Err(e);
        }
        // all went well, increase version.
        self.version += 1;
        Ok(l)
    }
pub async fn create_lif ( & mut self , lif_type : LIFType , name : String , vlan : Option < u16 > , ports : & [ PortId ] , ) -> error :: Result < lifmgr :: LIF > { if ports . is_empty ( ) { // At least one port is needed. return Err ( error :: NetworkManager :: Lif ( error :: Lif :: NotSupported ) ) ; } let reserved : Vec < PortId > = ports . iter ( ) . filter_map ( | p | if self . port_manager . use_port ( * p ) { Some ( * p ) } else { None } ) . collect ( ) ; if reserved . len ( ) != ports . len ( ) { self . release_ports ( & reserved ) ; return Err ( error :: NetworkManager :: Lif ( error :: Lif :: InvalidPort ) ) ; } // TODO(cgibson): Once we can configure VLANs, we need to handle VLAN ID 0 vs None, since // VLAN ID 0x0000 is a reserved value in dot1q. fxbug.dev/41746. let vid = match vlan { Some ( v ) => v , None => 0 , } ; let mut l = lifmgr :: LIF :: new ( self . version , lif_type , & name , PortId :: from ( 0 ) , reserved . clone ( ) , vid , Some ( LIFProperties :: default ( ) ) , ) . or_else ( | e | { self . release_ports ( & reserved ) ; Err ( e ) } ) ? ; if reserved . len ( ) > 1 { // Multiple ports, bridge them. let id = self . hal . create_bridge ( reserved . clone ( ) ) . await . or_else ( | e | { self . release_ports ( & reserved ) ; Err ( e ) } ) ? ; // LIF ID is associated with the bridge. let ( ) = l . set_pid ( id ) ; } else { let ( ) = l . set_pid ( reserved [ 0 ] ) ; } let r = self . lif_manager . add_lif ( & l ) ; if let Err ( e ) = r { self . release_ports ( & reserved ) ; // nothing to do if delete_bridge fails, all state changes have been reverted // already, just return an error to let caller handle it as appropriate. self . hal . delete_bridge ( l . pid ( ) ) . await ? ; return Err ( e ) ; } // all went well, increase version. self . version += 1 ; Ok ( l ) }
Creates a LIF of the given type.
Creates a LIF of the given type .
&mut self
lif_type
LIFType
name
String
vlan
Option<u16>
ports
&[PortId]
&mut self
lif_type
LIFType
name
String
vlan
Option<u16>
ports
&[PortId]