Struct rtnetlink::LinkAddRequest
source · 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
impl LinkAddRequest
sourcepub fn message_mut(&mut self) -> &mut LinkMessage
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 IFF_UP
link set, so that the
interface is up after creation. If we want to create a interface tha tis down by default we
could do:
use futures::Future;
use rtnetlink::{Handle, new_connection, packet::IFF_UP};
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);
// unset the IFF_UP flag before sending the request
request.message_mut().header.flags &= !IFF_UP;
request.message_mut().header.change_mask &= !IFF_UP;
// send the request
request.execute().await.map_err(|e| format!("{}", e))
}
sourcepub fn dummy(self, name: String) -> Self
pub fn dummy(self, name: String) -> Self
Create a dummy link.
This is equivalent to ip link add NAME type dummy
.
sourcepub fn veth(self, name: String, peer_name: String) -> Self
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
.
sourcepub fn vlan(self, name: String, index: u32, vlan_id: u16) -> Self
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.
sourcepub fn macvlan(self, name: String, index: u32, mode: u32) -> Self
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.
sourcepub fn vxlan(self, name: String, vni: u32) -> VxlanAddRequest
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.