Skip to content

Commit

Permalink
support IFLA_VRF_PORT_TABLE attribute
Browse files Browse the repository at this point in the history
Links that belong to a VRF carry the VRF table ID in the link info. For
a VRF link we already had these attributes:

```
LinkInfo([Kind(Vrf), Data(Vrf([TableId(10)]))])
```

For ports attached to a VRF we now have:

```
LinkInfo([Kind(Veth), PortKind(Vrf), PortData(VrfPort([TableId(10)]))])
```

This tells us that this veth interface belong to the VRF with table ID
10.
  • Loading branch information
little-dude authored and cathay4t committed Apr 24, 2024
1 parent 4d6adfa commit abfadc1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/link/link_info/info_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ use netlink_packet_utils::{
DecodeError, Emitable, Parseable,
};

use super::super::{InfoBondPort, InfoBridgePort};
use super::{
super::{InfoBondPort, InfoBridgePort},
InfoVrf,
};

const BOND: &str = "bond";
const BRIDGE: &str = "bridge";
const VRF: &str = "vrf";

const IFLA_INFO_PORT_KIND: u16 = 4;
const IFLA_INFO_PORT_DATA: u16 = 5;
Expand All @@ -20,6 +24,7 @@ const IFLA_INFO_PORT_DATA: u16 = 5;
pub enum InfoPortKind {
Bond,
Bridge,
Vrf,
Other(String),
}

Expand All @@ -31,6 +36,7 @@ impl std::fmt::Display for InfoPortKind {
match self {
Self::Bond => BOND,
Self::Bridge => BRIDGE,
Self::Vrf => VRF,
Self::Other(s) => s.as_str(),
}
)
Expand All @@ -42,6 +48,7 @@ impl Nla for InfoPortKind {
let len = match self {
Self::Bond => BOND.len(),
Self::Bridge => BRIDGE.len(),
Self::Vrf => VRF.len(),
Self::Other(s) => s.len(),
};
len + 1
Expand All @@ -51,6 +58,7 @@ impl Nla for InfoPortKind {
let s = match self {
Self::Bond => BOND,
Self::Bridge => BRIDGE,
Self::Vrf => VRF,
Self::Other(s) => s.as_str(),
};
buffer[..s.len()].copy_from_slice(s.as_bytes());
Expand All @@ -76,16 +84,20 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoPortKind {
Ok(match s.as_str() {
BOND => Self::Bond,
BRIDGE => Self::Bridge,
VRF => Self::Vrf,
_ => Self::Other(s),
})
}
}

pub type InfoVrfPort = InfoVrf;

#[derive(Debug, PartialEq, Eq, Clone)]
#[non_exhaustive]
pub enum InfoPortData {
BondPort(Vec<InfoBondPort>),
BridgePort(Vec<InfoBridgePort>),
VrfPort(Vec<InfoVrfPort>),
Other(Vec<u8>),
}

Expand All @@ -94,6 +106,7 @@ impl Nla for InfoPortData {
match self {
Self::BondPort(nlas) => nlas.as_slice().buffer_len(),
Self::BridgePort(nlas) => nlas.as_slice().buffer_len(),
Self::VrfPort(nlas) => nlas.as_slice().buffer_len(),
Self::Other(bytes) => bytes.len(),
}
}
Expand All @@ -102,6 +115,7 @@ impl Nla for InfoPortData {
match self {
Self::BondPort(nlas) => nlas.as_slice().emit(buffer),
Self::BridgePort(nlas) => nlas.as_slice().emit(buffer),
Self::VrfPort(nlas) => nlas.as_slice().emit(buffer),
Self::Other(bytes) => buffer.copy_from_slice(bytes),
}
}
Expand All @@ -125,6 +139,10 @@ impl InfoPortData {
.map(|nla| nla.and_then(|nla| InfoBridgePort::parse(&nla)))
.collect::<Result<Vec<_>, _>>()
.map(InfoPortData::BridgePort),
InfoPortKind::Vrf => NlasIterator::new(payload)
.map(|nla| nla.and_then(|nla| InfoVrfPort::parse(&nla)))
.collect::<Result<Vec<_>, _>>()
.map(InfoPortData::VrfPort),
InfoPortKind::Other(_) => Ok(InfoPortData::Other(payload.to_vec())),
};

Expand Down

0 comments on commit abfadc1

Please sign in to comment.