Skip to content

Commit

Permalink
macvlan: add IFLA_MACVLAN_BC_ options
Browse files Browse the repository at this point in the history
Add new IFLA_MACVLAN_BC_QUEUE_LEN, IFLA_MACVLAN_BC_QUEUE_LEN_USED and
IFLA_MACVLAN_BC_CUTOFF kernel options for macvlan and macvtap.

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=d4bff72c8401
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=954d1fa1ac93

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 24, 2023
1 parent 0d1bb1f commit 03f7d08
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/rtnl/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ pub const IFLA_MACVLAN_MACADDR_MODE: u16 = 3;
pub const IFLA_MACVLAN_MACADDR: u16 = 4;
pub const IFLA_MACVLAN_MACADDR_DATA: u16 = 5;
pub const IFLA_MACVLAN_MACADDR_COUNT: u16 = 6;
pub const IFLA_MACVLAN_BC_QUEUE_LEN: u16 = 7;
pub const IFLA_MACVLAN_BC_QUEUE_LEN_USED: u16 = 8;
pub const IFLA_MACVLAN_BC_CUTOFF: u16 = 9;
pub const IFLA_VLAN_UNSPEC: u16 = 0;
pub const IFLA_VLAN_ID: u16 = 1;
pub const IFLA_VLAN_FLAGS: u16 = 2;
Expand Down
50 changes: 49 additions & 1 deletion src/rtnl/link/nlas/link_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use byteorder::{ByteOrder, NativeEndian};
use netlink_packet_utils::{
nla::{DefaultNla, Nla, NlaBuffer, NlasIterator},
parsers::{
parse_mac, parse_string, parse_u16, parse_u16_be, parse_u32, parse_u8,
parse_mac, parse_string, parse_u16, parse_u16_be, parse_u32, parse_u8, parse_i32,
},
traits::{Emitable, Parseable},
DecodeError,
Expand Down Expand Up @@ -1222,6 +1222,9 @@ pub enum InfoMacVlan {
MacAddr([u8; 6]),
MacAddrData(Vec<InfoMacVlan>),
MacAddrCount(u32),
BcQueueLen(u32),
BcQueueLenUsed(u32),
BcCutoff(i32),
Other(DefaultNla),
}

Expand All @@ -1236,6 +1239,9 @@ impl Nla for InfoMacVlan {
MacAddr(_) => 6,
MacAddrData(ref nlas) => nlas.as_slice().buffer_len(),
MacAddrCount(_) => 4,
BcQueueLen(_) => 4,
BcQueueLenUsed(_) => 4,
BcCutoff(_) => 4,
Other(nla) => nla.value_len(),
}
}
Expand All @@ -1250,6 +1256,9 @@ impl Nla for InfoMacVlan {
MacAddr(bytes) => buffer.copy_from_slice(bytes),
MacAddrData(ref nlas) => nlas.as_slice().emit(buffer),
MacAddrCount(value) => NativeEndian::write_u32(buffer, *value),
BcQueueLen(value) => NativeEndian::write_u32(buffer, *value),
BcQueueLenUsed(value) => NativeEndian::write_u32(buffer, *value),
BcCutoff(value) => NativeEndian::write_i32(buffer, *value),
Other(nla) => nla.emit_value(buffer),
}
}
Expand All @@ -1264,6 +1273,9 @@ impl Nla for InfoMacVlan {
MacAddr(_) => IFLA_MACVLAN_MACADDR,
MacAddrData(_) => IFLA_MACVLAN_MACADDR_DATA,
MacAddrCount(_) => IFLA_MACVLAN_MACADDR_COUNT,
BcQueueLen(_) => IFLA_MACVLAN_BC_QUEUE_LEN,
BcQueueLenUsed(_) => IFLA_MACVLAN_BC_QUEUE_LEN_USED,
BcCutoff(_) => IFLA_MACVLAN_BC_CUTOFF,
Other(nla) => nla.kind(),
}
}
Expand Down Expand Up @@ -1305,6 +1317,18 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoMacVlan {
parse_u32(payload)
.context("invalid IFLA_MACVLAN_MACADDR_COUNT value")?,
),
IFLA_MACVLAN_BC_QUEUE_LEN => BcQueueLen(
parse_u32(payload)
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN value")?,
),
IFLA_MACVLAN_BC_QUEUE_LEN_USED => BcQueueLenUsed(
parse_u32(payload)
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN_USED value")?,
),
IFLA_MACVLAN_BC_CUTOFF => BcCutoff(
parse_i32(payload)
.context("invalid IFLA_MACVLAN_BC_CUTOFF value")?,
),
kind => Other(
DefaultNla::parse(buf)
.context(format!("unknown NLA type {kind}"))?,
Expand All @@ -1323,6 +1347,9 @@ pub enum InfoMacVtap {
MacAddr([u8; 6]),
MacAddrData(Vec<InfoMacVtap>),
MacAddrCount(u32),
BcQueueLen(u32),
BcQueueLenUsed(u32),
BcCutoff(i32),
Other(DefaultNla),
}

Expand All @@ -1337,6 +1364,9 @@ impl Nla for InfoMacVtap {
MacAddr(_) => 6,
MacAddrData(ref nlas) => nlas.as_slice().buffer_len(),
MacAddrCount(_) => 4,
BcQueueLen(_) => 4,
BcQueueLenUsed(_) => 4,
BcCutoff(_) => 4,
Other(nla) => nla.value_len(),
}
}
Expand All @@ -1351,6 +1381,9 @@ impl Nla for InfoMacVtap {
MacAddr(bytes) => buffer.copy_from_slice(bytes),
MacAddrData(ref nlas) => nlas.as_slice().emit(buffer),
MacAddrCount(value) => NativeEndian::write_u32(buffer, *value),
BcQueueLen(value) => NativeEndian::write_u32(buffer, *value),
BcQueueLenUsed(value) => NativeEndian::write_u32(buffer, *value),
BcCutoff(value) => NativeEndian::write_i32(buffer, *value),
Other(nla) => nla.emit_value(buffer),
}
}
Expand All @@ -1365,6 +1398,9 @@ impl Nla for InfoMacVtap {
MacAddr(_) => IFLA_MACVLAN_MACADDR,
MacAddrData(_) => IFLA_MACVLAN_MACADDR_DATA,
MacAddrCount(_) => IFLA_MACVLAN_MACADDR_COUNT,
BcQueueLen(_) => IFLA_MACVLAN_BC_QUEUE_LEN,
BcQueueLenUsed(_) => IFLA_MACVLAN_BC_QUEUE_LEN_USED,
BcCutoff(_) => IFLA_MACVLAN_BC_CUTOFF,
Other(nla) => nla.kind(),
}
}
Expand Down Expand Up @@ -1406,6 +1442,18 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoMacVtap {
parse_u32(payload)
.context("invalid IFLA_MACVLAN_MACADDR_COUNT value")?,
),
IFLA_MACVLAN_BC_QUEUE_LEN => BcQueueLen(
parse_u32(payload)
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN value")?,
),
IFLA_MACVLAN_BC_QUEUE_LEN_USED => BcQueueLenUsed(
parse_u32(payload)
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN_USED value")?,
),
IFLA_MACVLAN_BC_CUTOFF => BcCutoff(
parse_i32(payload)
.context("invalid IFLA_MACVLAN_BC_CUTOFF value")?,
),
kind => Other(
DefaultNla::parse(buf)
.context(format!("unknown NLA type {kind}"))?,
Expand Down

0 comments on commit 03f7d08

Please sign in to comment.