Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support IFLA_VRF_PORT_TABLE attribute #98

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/link/af_spec/inet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ buffer!(InetDevConfBuffer(DEV_CONF_LEN) {
arp_evict_nocarrier: (i32, 128..132),
});

#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
#[non_exhaustive]
pub struct InetDevConf {
pub forwarding: i32,
Expand Down
2 changes: 1 addition & 1 deletion src/link/af_spec/inet6_devconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Emitable for Inet6DevConf {
}
}

#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
#[non_exhaustive]
pub struct Inet6DevConf {
pub forwarding: i32,
Expand Down
2 changes: 1 addition & 1 deletion src/link/af_spec/inet6_icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use netlink_packet_utils::{

pub(crate) const ICMP6_STATS_LEN: usize = 48;

#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
#[non_exhaustive]
pub struct Icmp6Stats {
pub num: i64,
Expand Down
2 changes: 1 addition & 1 deletion src/link/af_spec/inet6_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ buffer!(Inet6StatsBuffer(INET6_STATS_LEN) {
in_ce_pkts: (i64, 280..288),
});

#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
#[non_exhaustive]
pub struct Inet6Stats {
pub num: i64,
Expand Down
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
2 changes: 1 addition & 1 deletion src/link/link_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub use self::gre_tap6::InfoGreTap6;
pub use self::gtp::InfoGtp;
pub use self::hsr::{HsrProtocol, InfoHsr};
pub use self::info_data::InfoData;
pub use self::info_port::{InfoPortData, InfoPortKind};
pub use self::info_port::{InfoPortData, InfoPortKind, InfoVrfPort};
pub use self::infos::{InfoKind, LinkInfo};
pub use self::ipoib::InfoIpoib;
pub use self::ipvlan::{InfoIpVlan, InfoIpVtap, IpVlanMode, IpVtapMode};
Expand Down
2 changes: 1 addition & 1 deletion src/link/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buffer!(MapBuffer(LINK_MAP_LEN) {
port: (u8, 27),
});

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
#[non_exhaustive]
pub struct Map {
pub memory_start: u64,
Expand Down
6 changes: 3 additions & 3 deletions src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub use self::link_info::{
InfoGreTap, InfoGreTap6, InfoGreTun, InfoGreTun6, InfoGtp, InfoHsr,
InfoIpVlan, InfoIpVtap, InfoIpoib, InfoKind, InfoMacSec, InfoMacVlan,
InfoMacVtap, InfoPortData, InfoPortKind, InfoSitTun, InfoTun, InfoVeth,
InfoVlan, InfoVrf, InfoVti, InfoVxlan, InfoXfrm, IpVlanMode, IpVtapMode,
LinkInfo, LinkXstats, MacSecCipherId, MacSecOffload, MacSecValidate,
MacVlanMode, MacVtapMode, MiiStatus, VlanQosMapping,
InfoVlan, InfoVrf, InfoVrfPort, InfoVti, InfoVxlan, InfoXfrm, IpVlanMode,
IpVtapMode, LinkInfo, LinkXstats, MacSecCipherId, MacSecOffload,
MacSecValidate, MacVlanMode, MacVtapMode, MiiStatus, VlanQosMapping,
};
pub use self::link_layer_type::LinkLayerType;
pub use self::link_state::State;
Expand Down
2 changes: 1 addition & 1 deletion src/link/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use netlink_packet_utils::{

pub(crate) const LINK_STATS_LEN: usize = 96;

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
#[non_exhaustive]
pub struct Stats {
/// total packets received
Expand Down
2 changes: 1 addition & 1 deletion src/link/stats64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ buffer!(Stats64Buffer(LINK_STATS64_LEN) {
rx_otherhost_dropped: (u64, 192..200),
});

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
#[non_exhaustive]
pub struct Stats64 {
/// total packets received
Expand Down
Loading
Loading