pub struct LinkAddRequest { /* private fields */ }
Expand description

A request to create a new link. This is equivalent to the ip link add commands.

A few methods for common actions (creating a veth pair, creating a vlan interface, etc.) are provided, but custom requests can be made using the message_mut() accessor.

Implementations§

source§

impl LinkAddRequest

source

pub async fn execute(self) -> Result<(), Error>

Execute the request.

source

pub fn message_mut(&mut self) -> &mut LinkMessage

Return a mutable reference to the request message.

§Example

Let’s say we want to create a vlan interface on a link with id 6. By default, the vlan() method would create a request with the LinkFlag::Up link set, so that the interface is up after creation. If we want to create a interface that is down by default we could do:

use futures::Future;
use netlink_packet_route::link::LinkFlag;
use rtnetlink::{Handle, new_connection};

async fn run(handle: Handle) -> Result<(), String> {
    let vlan_id = 100;
    let link_id = 6;
    let mut request = handle.link().add().vlan("my-vlan-itf".into(),
        link_id, vlan_id);
    request.message_mut().header.flags.push(LinkFlag::Up);
    request.message_mut().header.change_mask.retain(
        |f| *f != LinkFlag::Up);
    // send the request
    request.execute().await.map_err(|e| format!("{}", e))
}
source

pub fn dummy(self, name: String) -> Self

Create a dummy link. This is equivalent to ip link add NAME type dummy.

source

pub fn veth(self, name: String, peer_name: String) -> Self

Create a veth pair. This is equivalent to ip link add NAME1 type veth peer name NAME2.

source

pub fn vlan(self, name: String, index: u32, vlan_id: u16) -> Self

Create VLAN on a link. This is equivalent to ip link add link LINK name NAME type vlan id VLAN_ID, but instead of specifying a link name (LINK), we specify a link index.

source

pub fn vlan_with_qos<I: IntoIterator<Item = QosMapping>, E: IntoIterator<Item = QosMapping>>( self, name: String, index: u32, vlan_id: u16, ingress_qos: I, egress_qos: E ) -> Self

Create VLAN on a link with ingress and egress qos mappings. This is equivalent to ip link add link LINK name NAME type vlan id VLAN_ID ingress-qos-mapping INGRESS_QOS egress-qos-mapping EGRESS_QOS, but instead of specifying a link name (LINK), we specify a link index.

source

pub fn macvlan(self, name: String, index: u32, mode: u32) -> Self

Create macvlan on a link. This is equivalent to ip link add name NAME link LINK type macvlan mode MACVLAN_MODE, but instead of specifying a link name (LINK), we specify a link index. The MACVLAN_MODE is an integer consisting of flags from MACVLAN_MODE (netlink-packet-route/src/rtnl/constants.rs) being: _PRIVATE, _VEPA, _BRIDGE, _PASSTHRU, _SOURCE, which can be combined.

source

pub fn macvtap(self, name: String, index: u32, mode: u32) -> Self

Create macvtap on a link. This is equivalent to ip link add name NAME link LINK type macvtap mode MACVTAP_MODE, but instead of specifying a link name (LINK), we specify a link index. The MACVTAP_MODE is an integer consisting of flags from MACVTAP_MODE (netlink-packet-route/src/rtnl/constants.rs) being: _PRIVATE, _VEPA, _BRIDGE, _PASSTHRU, _SOURCE, which can be combined.

source

pub fn vxlan(self, name: String, vni: u32) -> VxlanAddRequest

Create a VxLAN This is equivalent to ip link add name NAME type vxlan id VNI, it returns a VxlanAddRequest to further customize the vxlan interface creation.

source

pub fn xfrmtun(self, name: String, ifid: u32) -> Self

Create xfrm tunnel This is equivalent to ip link add name NAME type xfrm if_id NUMBER, The NUMBER is a XFRM if_id which may be connected to IPsec policy

source

pub fn bond(self, name: String) -> BondAddRequest

Create a new bond. This is equivalent to ip link add link NAME type bond.

source

pub fn bridge(self, name: String) -> Self

Create a new bridge. This is equivalent to ip link add link NAME type bridge.

source

pub fn wireguard(self, name: String) -> Self

Create a wireguard link. This is equivalent to ip link add NAME type wireguard.

source

pub fn replace(self) -> Self

Replace existing matching link.

source

pub fn name(self, name: String) -> Self

source

pub fn address(self, address: Vec<u8>) -> Self

Define the hardware address of the link when creating it (equivalent to ip link add NAME address ADDRESS)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.