Skip to content

Commit 640be35

Browse files
Luap99cathay4t
authored andcommitted
macvlan: add IFLA_MACVLAN_BC_ options
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]>
1 parent 2d33edb commit 640be35

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/rtnl/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ pub const IFLA_MACVLAN_MACADDR_MODE: u16 = 3;
470470
pub const IFLA_MACVLAN_MACADDR: u16 = 4;
471471
pub const IFLA_MACVLAN_MACADDR_DATA: u16 = 5;
472472
pub const IFLA_MACVLAN_MACADDR_COUNT: u16 = 6;
473+
pub const IFLA_MACVLAN_BC_QUEUE_LEN: u16 = 7;
474+
pub const IFLA_MACVLAN_BC_QUEUE_LEN_USED: u16 = 8;
475+
pub const IFLA_MACVLAN_BC_CUTOFF: u16 = 9;
473476
pub const IFLA_VLAN_UNSPEC: u16 = 0;
474477
pub const IFLA_VLAN_ID: u16 = 1;
475478
pub const IFLA_VLAN_FLAGS: u16 = 2;

src/rtnl/link/nlas/link_infos.rs

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use byteorder::{ByteOrder, NativeEndian};
55
use netlink_packet_utils::{
66
nla::{DefaultNla, Nla, NlaBuffer, NlasIterator},
77
parsers::{
8-
parse_mac, parse_string, parse_u16, parse_u16_be, parse_u32, parse_u8,
8+
parse_i32, parse_mac, parse_string, parse_u16, parse_u16_be, parse_u32,
9+
parse_u8,
910
},
1011
traits::{Emitable, Parseable},
1112
DecodeError,
@@ -1345,6 +1346,9 @@ pub enum InfoMacVlan {
13451346
MacAddr([u8; 6]),
13461347
MacAddrData(Vec<InfoMacVlan>),
13471348
MacAddrCount(u32),
1349+
BcQueueLen(u32),
1350+
BcQueueLenUsed(u32),
1351+
BcCutoff(i32),
13481352
Other(DefaultNla),
13491353
}
13501354

@@ -1359,6 +1363,9 @@ impl Nla for InfoMacVlan {
13591363
MacAddr(_) => 6,
13601364
MacAddrData(ref nlas) => nlas.as_slice().buffer_len(),
13611365
MacAddrCount(_) => 4,
1366+
BcQueueLen(_) => 4,
1367+
BcQueueLenUsed(_) => 4,
1368+
BcCutoff(_) => 4,
13621369
Other(nla) => nla.value_len(),
13631370
}
13641371
}
@@ -1373,6 +1380,9 @@ impl Nla for InfoMacVlan {
13731380
MacAddr(bytes) => buffer.copy_from_slice(bytes),
13741381
MacAddrData(ref nlas) => nlas.as_slice().emit(buffer),
13751382
MacAddrCount(value) => NativeEndian::write_u32(buffer, *value),
1383+
BcQueueLen(value) => NativeEndian::write_u32(buffer, *value),
1384+
BcQueueLenUsed(value) => NativeEndian::write_u32(buffer, *value),
1385+
BcCutoff(value) => NativeEndian::write_i32(buffer, *value),
13761386
Other(nla) => nla.emit_value(buffer),
13771387
}
13781388
}
@@ -1387,6 +1397,9 @@ impl Nla for InfoMacVlan {
13871397
MacAddr(_) => IFLA_MACVLAN_MACADDR,
13881398
MacAddrData(_) => IFLA_MACVLAN_MACADDR_DATA,
13891399
MacAddrCount(_) => IFLA_MACVLAN_MACADDR_COUNT,
1400+
BcQueueLen(_) => IFLA_MACVLAN_BC_QUEUE_LEN,
1401+
BcQueueLenUsed(_) => IFLA_MACVLAN_BC_QUEUE_LEN_USED,
1402+
BcCutoff(_) => IFLA_MACVLAN_BC_CUTOFF,
13901403
Other(nla) => nla.kind(),
13911404
}
13921405
}
@@ -1428,6 +1441,18 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoMacVlan {
14281441
parse_u32(payload)
14291442
.context("invalid IFLA_MACVLAN_MACADDR_COUNT value")?,
14301443
),
1444+
IFLA_MACVLAN_BC_QUEUE_LEN => BcQueueLen(
1445+
parse_u32(payload)
1446+
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN value")?,
1447+
),
1448+
IFLA_MACVLAN_BC_QUEUE_LEN_USED => BcQueueLenUsed(
1449+
parse_u32(payload)
1450+
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN_USED value")?,
1451+
),
1452+
IFLA_MACVLAN_BC_CUTOFF => BcCutoff(
1453+
parse_i32(payload)
1454+
.context("invalid IFLA_MACVLAN_BC_CUTOFF value")?,
1455+
),
14311456
kind => Other(
14321457
DefaultNla::parse(buf)
14331458
.context(format!("unknown NLA type {kind}"))?,
@@ -1446,6 +1471,9 @@ pub enum InfoMacVtap {
14461471
MacAddr([u8; 6]),
14471472
MacAddrData(Vec<InfoMacVtap>),
14481473
MacAddrCount(u32),
1474+
BcQueueLen(u32),
1475+
BcQueueLenUsed(u32),
1476+
BcCutoff(i32),
14491477
Other(DefaultNla),
14501478
}
14511479

@@ -1460,6 +1488,9 @@ impl Nla for InfoMacVtap {
14601488
MacAddr(_) => 6,
14611489
MacAddrData(ref nlas) => nlas.as_slice().buffer_len(),
14621490
MacAddrCount(_) => 4,
1491+
BcQueueLen(_) => 4,
1492+
BcQueueLenUsed(_) => 4,
1493+
BcCutoff(_) => 4,
14631494
Other(nla) => nla.value_len(),
14641495
}
14651496
}
@@ -1474,6 +1505,9 @@ impl Nla for InfoMacVtap {
14741505
MacAddr(bytes) => buffer.copy_from_slice(bytes),
14751506
MacAddrData(ref nlas) => nlas.as_slice().emit(buffer),
14761507
MacAddrCount(value) => NativeEndian::write_u32(buffer, *value),
1508+
BcQueueLen(value) => NativeEndian::write_u32(buffer, *value),
1509+
BcQueueLenUsed(value) => NativeEndian::write_u32(buffer, *value),
1510+
BcCutoff(value) => NativeEndian::write_i32(buffer, *value),
14771511
Other(nla) => nla.emit_value(buffer),
14781512
}
14791513
}
@@ -1488,6 +1522,9 @@ impl Nla for InfoMacVtap {
14881522
MacAddr(_) => IFLA_MACVLAN_MACADDR,
14891523
MacAddrData(_) => IFLA_MACVLAN_MACADDR_DATA,
14901524
MacAddrCount(_) => IFLA_MACVLAN_MACADDR_COUNT,
1525+
BcQueueLen(_) => IFLA_MACVLAN_BC_QUEUE_LEN,
1526+
BcQueueLenUsed(_) => IFLA_MACVLAN_BC_QUEUE_LEN_USED,
1527+
BcCutoff(_) => IFLA_MACVLAN_BC_CUTOFF,
14911528
Other(nla) => nla.kind(),
14921529
}
14931530
}
@@ -1529,6 +1566,18 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoMacVtap {
15291566
parse_u32(payload)
15301567
.context("invalid IFLA_MACVLAN_MACADDR_COUNT value")?,
15311568
),
1569+
IFLA_MACVLAN_BC_QUEUE_LEN => BcQueueLen(
1570+
parse_u32(payload)
1571+
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN value")?,
1572+
),
1573+
IFLA_MACVLAN_BC_QUEUE_LEN_USED => BcQueueLenUsed(
1574+
parse_u32(payload)
1575+
.context("invalid IFLA_MACVLAN_BC_QUEUE_LEN_USED value")?,
1576+
),
1577+
IFLA_MACVLAN_BC_CUTOFF => BcCutoff(
1578+
parse_i32(payload)
1579+
.context("invalid IFLA_MACVLAN_BC_CUTOFF value")?,
1580+
),
15321581
kind => Other(
15331582
DefaultNla::parse(buf)
15341583
.context(format!("unknown NLA type {kind}"))?,
@@ -2142,6 +2191,64 @@ mod tests {
21422191
assert_eq!(&vec[..], &MACVLAN[..]);
21432192
}
21442193

2194+
#[rustfmt::skip]
2195+
static MACVLAN_BC: [u8; 48] = [
2196+
0x0c, 0x00, // length = 12
2197+
0x01, 0x00, // type = 1 = IFLA_INFO_KIND
2198+
0x6d, 0x61, 0x63, 0x76, 0x6c, 0x61, 0x6e, 0x00, // V = "macvlan\0"
2199+
0x24, 0x00, // length = 36
2200+
0x02, 0x00, // type = 2 = IFLA_INFO_DATA
2201+
0x08, 0x00, // length = 8
2202+
0x01, 0x00, // type = IFLA_MACVLAN_MODE
2203+
0x02, 0x00, 0x00, 0x00, // V = 2 = vepa
2204+
2205+
0x08, 0x00, // length = 8
2206+
0x07, 0x00, // type = IFLA_MACVLAN_BC_QUEUE_LEN
2207+
0xe8, 0x03, 0x00, 0x00, // value 1000
2208+
2209+
0x08, 0x00, // length = 8
2210+
0x08, 0x00, // type = IFLA_MACVLAN_BC_QUEUE_LEN_USED
2211+
0xe8, 0x03, 0x00, 0x00, // value 1000
2212+
2213+
0x08, 0x00, // length = 8
2214+
0x09, 0x00, // type = IFLA_MACVLAN_BC_CUTOFF
2215+
0xff, 0xff, 0xff, 0xff, // value = -1 (signed two's complement)
2216+
];
2217+
2218+
lazy_static! {
2219+
static ref MACVLAN_INFO_BC: Vec<InfoMacVlan> = vec![
2220+
InfoMacVlan::Mode(2), // vepa
2221+
InfoMacVlan::BcQueueLen(1000),
2222+
InfoMacVlan::BcQueueLenUsed(1000),
2223+
InfoMacVlan::BcCutoff(-1),
2224+
];
2225+
}
2226+
2227+
#[test]
2228+
fn parse_info_macvlan_bc() {
2229+
let nla = NlaBuffer::new_checked(&MACVLAN_BC[..]).unwrap();
2230+
let parsed = VecInfo::parse(&nla).unwrap().0;
2231+
let expected = vec![
2232+
Info::Kind(InfoKind::MacVlan),
2233+
Info::Data(InfoData::MacVlan(MACVLAN_INFO_BC.clone())),
2234+
];
2235+
assert_eq!(expected, parsed);
2236+
}
2237+
2238+
#[test]
2239+
fn emit_info_macvlan_bc() {
2240+
let nlas = vec![
2241+
Info::Kind(InfoKind::MacVlan),
2242+
Info::Data(InfoData::MacVlan(MACVLAN_INFO_BC.clone())),
2243+
];
2244+
2245+
assert_eq!(nlas.as_slice().buffer_len(), 48);
2246+
2247+
let mut vec = vec![0xff; 48];
2248+
nlas.as_slice().emit(&mut vec);
2249+
assert_eq!(&vec[..], &MACVLAN_BC[..]);
2250+
}
2251+
21452252
lazy_static! {
21462253
static ref XFRMTUN_INFO: Vec<InfoXfrmTun> = vec![
21472254
InfoXfrmTun::IfId(4), // ifid

0 commit comments

Comments
 (0)